Created
March 14, 2021 06:38
-
-
Save Samshal/1d17d4f4b653d100f0ec1b134ebdc338 to your computer and use it in GitHub Desktop.
Transform coordinates in a geojson from (long,lat) to (lat,long)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Transform coordinates in a geojson from (long,lat) to (lat,long) | |
* | |
* TOOLS: geojsonlint.com to validate geojson | |
*/ | |
$file = file_get_contents("pipeline (1).geojson"); | |
$file = json_decode($file); | |
for ($i = 0; $i < count($file->features); $i++){ | |
$coords = $file->features[$i]->geometry->coordinates; | |
foreach($coords as $key=>$value){ | |
$coords[$key] = [$value[1], $value[0]]; | |
} | |
$file->features[$i]->geometry->coordinates = $coords; | |
} | |
$f = json_encode($file); | |
file_put_contents("pipeline_transform_1.geojson", $f); | |
echo "done"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment