function toGeoJSON($resultFileURI) { $doc = new DOMDocument(); $doc->load($resultFileURI); $type = getSentinelType($doc); /* * Initialize GeoJSON */ $geojson = array('type' => 'FeatureCollection', 'features' => array()); if ($type == "gs2_dimap_document") { /* * Two cases : * - Global_Footprint is defined => S2_DIMAP final product * - Global_Footprint is not defined => intermediate product use Granule */ $footprints = $doc->getElementsByTagname('Global_Footprint'); /* * Global footprint */ $ds = $doc->getElementsByTagName('Data_Strip_Identification')->item(0); $properties = array('identifier' => $doc->getElementsByTagName('DATASET_NAME')->item(0)->nodeValue, 'DATA_STRIP_ID' => $ds->getElementsByTagName('DATA_STRIP_ID')->item(0)->nodeValue, 'DATA_STRIP_TYPE' => $ds->getElementsByTagName('DATA_STRIP_TYPE')->item(0)->nodeValue, 'RECEPTION_STATION' => $ds->getElementsByTagName('RECEPTION_STATION')->item(0)->nodeValue, 'ARCHIVING_STATION' => $ds->getElementsByTagName('ARCHIVING_STATION')->item(0)->nodeValue, 'ARCHIVING_DATE' => $ds->getElementsByTagName('ARCHIVING_DATE')->item(0)->nodeValue, 'DOWNLINK_ORBIT_NUMBER' => $ds->getElementsByTagName('DOWNLINK_ORBIT_NUMBER')->item(0)->nodeValue, 'ORBIT_NUMBER' => $ds->getElementsByTagName('ORBIT_NUMBER')->item(0)->nodeValue, 'ACQUISITION_PLATFORM' => $ds->getElementsByTagName('ACQUISITION_PLATFORM')->item(0)->nodeValue, 'ACQUISITION_DATE' => $ds->getElementsByTagName('ACQUISITION_DATE')->item(0)->nodeValue, 'ACQUISITION_ORBIT_DIRECTION' => $ds->getElementsByTagName('ACQUISITION_ORBIT_DIRECTION')->item(0)->nodeValue, 'DOWNLINK_PRIORITY_FLAG' => $ds->getElementsByTagName('DOWNLINK_PRIORITY_FLAG')->item(0)->nodeValue); if ($footprints->item(0)->getElementsByTagName('EXT_POS_LIST')->item(0)->nodeValue != "0 0 0 0") { foreach ($footprints as $footprint) { $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($footprint->getElementsByTagName('EXT_POS_LIST')->item(0)->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => $properties); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } else { /* * Quicklook_Descriptor */ $qs = $doc->getElementsByTagName('Quicklook_Descriptor'); /* * Roll over detectors */ foreach ($qs as $q) { $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($q->getElementsByTagName('EXT_POS_LIST')->item(0)->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => $properties); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } } return json_encode($geojson); }
/** * Get mapshup layer type from an XML file */ function getLayerType($doc) { $rootName = MSP_UNKNOWN; /* * Get root name element */ if ($doc && $doc->documentElement->nodeName != null) { $rootName = strtolower(removeNamespace($doc->documentElement->nodeName)); } /* * RSS */ if ($rootName === "rss" || $rootName === "rdf") { return "GeoRSS"; } else { if ($rootName === "gpx") { return "GPX"; } else { if ($rootName == "opensearchdescription") { return "OpenSearch"; } else { if ($rootName === "wfs_capabilities") { return "WFS"; } else { if ($rootName === "wms_capabilities" || $rootName === "wmt_ms_capabilities") { return "WMS"; } else { if ($rootName === "capabilities") { $serviceIdentification = $doc->getElementsByTagName('ServiceIdentification')->item(0); if ($serviceIdentification != null) { $serviceType = $serviceIdentification->getElementsByTagName('ServiceType')->item(0)->nodeValue; if (strpos($serviceType, "WMTS") !== false) { return "WMTS"; } else { if (strpos($serviceType, "WPS") !== false) { return "WPS"; } } } return MSP_UNKNOWN; } else { if (getPHRType($doc) !== null) { return "Pleiades"; } else { if (getSentinelType($doc) !== null) { return "Sentinel"; } else { $rootName = MSP_UNKNOWN; } } } } } } } } return $rootName; }