Skip to content

Instantly share code, notes, and snippets.

@Samshal
Created March 14, 2021 06:38
Show Gist options
  • Save Samshal/1d17d4f4b653d100f0ec1b134ebdc338 to your computer and use it in GitHub Desktop.
Save Samshal/1d17d4f4b653d100f0ec1b134ebdc338 to your computer and use it in GitHub Desktop.
Transform coordinates in a geojson from (long,lat) to (lat,long)
<?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