From fbb336751cc3d91893b0eb630534bb02bcc29da3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 15 Mar 2018 21:47:25 +0100 Subject: [PATCH] --- arcgis-to-geojson.php | 142 ++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 75 deletions(-) diff --git a/arcgis-to-geojson.php b/arcgis-to-geojson.php index 073c26a..071a946 100644 --- a/arcgis-to-geojson.php +++ b/arcgis-to-geojson.php @@ -1,75 +1,67 @@ - - */ -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"; -*/ -?> + + */ +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"; +?> -- 2.30.2