From: Christian Weiske Date: Thu, 15 Mar 2018 20:45:30 +0000 (+0100) Subject: (no commit message) X-Git-Url: https://git.cweiske.de/paste/555.git/commitdiff_plain/656fcfbc93bc2ef93183a199c98b805d14001b0f --- 656fcfbc93bc2ef93183a199c98b805d14001b0f diff --git a/arcgis-to-geojson.php b/arcgis-to-geojson.php new file mode 100644 index 0000000..073c26a --- /dev/null +++ b/arcgis-to-geojson.php @@ -0,0 +1,75 @@ + + */ +require_once __DIR__ . '/vendor/autoload.php'; + +function err($msg) +{ + echo $msg . "\n"; + exit(1); +} + +if ($argc < 2) { + err("convert.php "); +} + +$file = $argv[1]; +$data = json_decode(file_get_contents($file)); + +if (!isset($data->RecordSet->geometryType) + || $data->RecordSet->geometryType != 'esriGeometryPolygon' +) { + err('No esriGeometryPolygon'); +} + +$sRefs = [ + 25833 => ['N', 33] +]; +$sRef = $data->RecordSet->spatialReference->wkid; +if (!isset($sRefs[$sRef])) { + err('Unknown spatial reference EPSG ' . $sRef); +} +list($latZone, $lngZone) = $sRefs[$sRef]; + +$geoJson = [ + 'type' => 'Feature', + 'title' => basename($file, '.json'), + 'properties' => null, + 'geometry' => [ + 'type' => 'Polygon', + 'coordinates' => [], + ], +]; +foreach ($data->RecordSet->features as $feature) { + foreach ($feature->geometry->rings as $ring) { + $coords = []; + foreach ($ring as $point) { + $utm = new \PHPCoord\UTMRef( + $point[0], $point[1], 0, $latZone, $lngZone + ); + $ll = $utm->toLatLng(); + $coords[] = [$ll->getLng(), $ll->getLat()]; + } + + $geoJson['geometry']['coordinates'][] = $coords; + } +} + +echo json_encode($geoJson, JSON_PRETTY_PRINT) . "\n"; + +/* +$UTMRef = new \PHPCoord\UTMRef(350531.8, 5689109.2, 0, 'N', 33); +$LatLng = $UTMRef->toLatLng(); + +echo (string) $UTMRef . "\n"; +echo (string) $LatLng . "\n"; +*/ +?> diff --git a/combine-geojson.php b/combine-geojson.php new file mode 100644 index 0000000..2df9115 --- /dev/null +++ b/combine-geojson.php @@ -0,0 +1,30 @@ + + */ +function err($msg) +{ + echo $msg . "\n"; + exit(1); +} + +if ($argc < 2) { + err("combine-geojson.php "); +} + +$files = $argv; +array_shift($files); + +$combined = [ + 'type' => 'FeatureCollection', + 'features' => [], +]; + +foreach ($files as $file) { + $combined['features'][] = json_decode(file_get_contents($file)); +} + +echo json_encode($combined, JSON_PRETTY_PRINT) . "\n"; +?>