/** * 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; }
function toGeoJSON($resultFileURI) { $doc = new DOMDocument(); $doc->load($resultFileURI); /* * Get the PHR type from XML file root name element */ $type = getPHRType($doc); /* * Initialize GeoJSON */ $geojson = array('type' => 'FeatureCollection', 'features' => array()); /* * * Pleiades Inventory Plan * * Displayed geometry : * * STATION/PASS/DATASTRIP/CORNER/LATITUDE * STATION/PASS/DATASTRIP/CORNER/LONGITUDE * * Displayed properties : * * STATION/PASS/DATASTRIP/OBMM_FILE_NUMBER * */ if ($type == "phr_inventory_plan") { $stations = $doc->getElementsByTagname('STATION'); foreach ($stations as $station) { $passes = $station->getElementsByTagname('PASS'); foreach ($passes as $pass) { $orbit = $pass->getElementsByTagname('ORBIT_NUMBER')->item(0)->nodeValue; $Features = $pass->getElementsByTagname('DATASTRIP'); foreach ($Features as $datastrip) { $dsids = $datastrip->getElementsByTagName('OBMM_FILE_NUMBER'); $urgence = $datastrip->getElementsByTagName('INV_URGENCE')->item(0)->nodeValue; $dstype = $datastrip->getElementsByTagName('DATASTRIP_TYPE')->item(0)->nodeValue; $corners = $datastrip->getElementsByTagName('CORNER'); $poslist = ''; $isFirst = 1; foreach ($corners as $corner) { $LAT = $corner->getElementsByTagName('LATITUDE')->item(0)->nodeValue; $LON = $corner->getElementsByTagName('LONGITUDE')->item(0)->nodeValue; $longitude = $LON; $latitude = $LAT; $poslist .= $latitude . ' ' . $longitude . ' '; if ($isFirst == 1) { $latitude1 = $latitude; $longitude1 = $longitude; $isFirst = 0; } } $poslist .= $latitude1 . ' ' . $longitude1; /** * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($poslist, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => $dsids->item(0)->nodeValue . " (orbit " . $orbit . " : " . $dstype . ")", 'DOWNLINK_ORBIT_NUMBER' => $orbit, 'INV_URGENCE' => $urgence, 'DATASTRIP_TYPE' => $dstype, 'DOWNLINK_START' => $pass->getElementsByTagName('DATES')->item(0)->getElementsByTagName('START')->item(0)->nodeValue)); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } } } else { if ($type == "phr_dimap_document") { // Metadata info $pl = $doc->getElementsByTagname('PROCESSING_LEVEL')->item(0); $sp = $doc->getElementsByTagname('SPECTRAL_PROCESSING')->item(0); // Metadata profile $profile = $doc->getElementsByTagname('METADATA_PROFILE')->item(0)->nodeValue; // Default is full product (no swaths) $swaths = null; // Footprint from Album_Footprint if ($profile == "PHR_INVENTORY_INIT_LOC_DATA" || $profile == "PHR_INVENTORY_ALBUM_NCN_DATA" || $profile == "PHR_IMAGE_ARCHIVE_PRODUCT") { $footprint = $doc->getElementsByTagname('Album_Footprint')->item(0); $path = "Data_Strip_Frame/Album_Footprint/Vertex"; } else { $footprint = $doc->getElementsByTagname('Dataset_Frame')->item(0); $path = "Product_Frame/Dataset_Frame/Vertex"; $swaths = $footprint->getElementsByTagname('Array_Frame'); // Multiple swath defined ? if ($swaths->item(0)) { $path = "Product_Frame/Dataset_Frame/Array_Frame/Vertex"; } } if ($swaths && $swaths->item(0)) { foreach ($swaths as $swath) { $vertices = $swath->getElementsByTagname('Vertex'); $poslist = ''; $isFirst = 1; foreach ($vertices as $vertex) { $latitude = $vertex->getElementsByTagName('LAT')->item(0)->nodeValue; $longitude = $vertex->getElementsByTagName('LON')->item(0)->nodeValue; $poslist .= $latitude . " " . $longitude . " "; if ($isFirst == 1) { $latitude1 = $latitude; $longitude1 = $longitude; $isFirst = 0; } } $poslist .= $latitude1 . ' ' . $longitude1; /** * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($poslist, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => $doc->getElementsByTagname('DATASET_NAME')->item(0)->nodeValue, 'METADATA_PROFILE' => $profile, 'PROCESSING_LEVEL' => $pl ? $pl->nodeValue : 'N/A', 'SPECTRAL_PROCESSING' => $sp ? $sp->nodeValue : 'N/A', 'GEOMETRY_PATH' => $path, 'BAND_ID' => $footprint->getElementsByTagname('BAND_ID')->item(0)->nodeValue, 'SUBSWATH_NUMBER' => $swath->getElementsByTagname('SUBSWATH_NUMBER')->item(0)->nodeValue, 'ARRAY_ID' => $swath->getElementsByTagname('ARRAY_ID')->item(0)->nodeValue)); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } else { $vertices = $footprint->getElementsByTagname('Vertex'); $poslist = ''; $isFirst = 1; foreach ($vertices as $vertex) { $latitude = $vertex->getElementsByTagName('LAT')->item(0)->nodeValue; $longitude = $vertex->getElementsByTagName('LON')->item(0)->nodeValue; $poslist .= $latitude . " " . $longitude . " "; if ($isFirst == 1) { $latitude1 = $latitude; $longitude1 = $longitude; $isFirst = 0; } } $poslist .= $latitude1 . ' ' . $longitude1; /** * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($poslist, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => $doc->getElementsByTagname('DATASET_NAME')->item(0)->nodeValue, 'METADATA_PROFILE' => $profile, 'PROCESSING_LEVEL' => $pl ? $pl->nodeValue : 'N/A', 'SPECTRAL_PROCESSING' => $sp ? $sp->nodeValue : 'N/A', 'GEOMETRY_PATH' => $path)); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } else { if ($type == "phr_ip_request") { // Check geometry availability $roi = $doc->getElementsByTagname('PRODUCT_ROI')->item(0); if ($roi) { /* * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($roi->getElementsByTagname('POLYGON')->item(0)->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => strtoupper($type))); } else { $geojson = array('error' => array('message' => 'Error: no ROI defined')); } // Add feature array to feature collection array array_push($geojson['features'], $feature); return json_encode($geojson); } else { if ($type === "geo_phr_command_file" || $type === "init_loc_prod_command_file") { // Check geometry availability $roi = $doc->getElementsByTagname('POLYGON')->item(0); if ($roi) { /* * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($roi->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => strtoupper($type))); } else { $geojson = array('error' => array('message' => 'Error: no ROI defined')); } // Add feature array to feature collection array array_push($geojson['features'], $feature); return json_encode($geojson); } else { if ($type == "mask" || $type == "overilluminationmask") { // First check if input file is a Mask or an OverIlluminationMask $masks = $doc->getElementsByTagname('MaskFeature'); // No MaskFeature, try OverIllumination if ($masks->item(0) === null) { $masks = $doc->getElementsByTagname('OverIllumination'); // No OverIllumination - do nothing if ($masks->item(0) === null) { return ""; } } foreach ($masks as $mask) { $id = $mask->getAttribute('gml:id'); $exterior = $mask->getElementsByTagName('exterior')->item(0); /** * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($exterior->getElementsByTagName('posList')->item(0)->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => $id)); // Add feature array to feature collection array array_push($geojson['features'], $feature); $holes = $mask->getElementsByTagName('interior'); $count = 0; foreach ($holes as $hole) { /** * Add feature */ $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($hole->getElementsByTagName('posList')->item(0)->nodeValue, LATLON), 'crs' => array('type' => 'EPSG', 'properties' => array('code' => '4326')), 'properties' => array('identifier' => $id . " -> HOLE " . $count++)); // Add feature array to feature collection array array_push($geojson['features'], $feature); } } } } } } } return json_encode($geojson); }