I am trying to use the following GeoJson file
On my server and via php I would like to be able to call a url, perhaps:
http://example.com/point.php?country=Argentina
and then 1 random point would ouput.
I understand that the geojson file marks the boundaries of each country. What is the best way to do this?
I have googled and also looked for examples or ideas via stackoverflow without much luck which is why I am posting. I have been able to do this with just the USA by state but I would really like to use this geojson file as it would be more accurate and enable me to generate a random point from any specified country. The included code works for the states. I'd like to modify it to work with this geojson file.
"AK": {
"name": "Alaska",
"min_lat": 52.5964,
"max_lat": 71.5232,
"min_lng": -169.9146,
"max_lng": -129.993
}
<?php
function float_rand($Min, $Max){
if ($Min > $Max) {
$min = $Max;
$max = $Min;
} else {
$min = $Min;
$max = $Max;
}
$randomfloat = $min + mt_rand() / mt_getrandmax() * ($max - $min);
$randomfloat = round($randomfloat, 14);
return $randomfloat;
}
$boundaries_json = file_get_contents("state_boundaries.json");
$boundaries = json_decode($boundaries_json, true);
$b = array();
foreach ($boundaries as $state => $bounds) {
$b[] = $bounds;
}
$state = $b[rand(0, sizeof($b) - 1)];
//print_r($state);
// generate coords
$lat = float_rand($state["min_lat"], $state["max_lat"]);
$lon = float_rand($state["min_lng"], $state["max_lng"]);
The included code works for the states. I'd like to modify it to work with this geojson file.