--- /dev/null
+<?php
+/**
+ * Convert a ArcGis web recordset polygon to a geojson polygon feature.
+ *
+ * Validate the generated JSON with http://geojsonlint.com/
+ *
+ * Dependency installation:
+ * $ composer require php-coord/php-coord
+ *
+ * @author Christan Weiske <cweiske@cweiske.de>
+ */
+require_once __DIR__ . '/vendor/autoload.php';
+
+function err($msg)
+{
+ echo $msg . "\n";
+ exit(1);
+}
+
+if ($argc < 2) {
+ err("convert.php <esriGeoMetryFile.json>");
+}
+
+$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";
+*/
+?>
--- /dev/null
+<?php
+/**
+ * Takes several geojson files and combines them into a single one.
+ *
+ * @author Christian Weiske <cweiske@cweiske.de>
+ */
+function err($msg)
+{
+ echo $msg . "\n";
+ exit(1);
+}
+
+if ($argc < 2) {
+ err("combine-geojson.php <files>");
+}
+
+$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";
+?>