示例#1
0
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);
}
示例#2
0
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);
}
示例#3
0
function outputToGeoJSON($theData, $nbOfResults)
{
    // Load the GetFeature result document
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $nbOfResults, 'features' => array());
    // Check root element
    if ($doc->getElementsByTagname('FeatureCollection')->item(0) === null) {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => "Invalid response from server"));
        return json_encode($geojson);
    }
    // Get the DataStrip root element
    $dataObjects = $doc->getElementsByTagname('DataStrip');
    // Roll over each feature
    foreach ($dataObjects as $dataObject) {
        // Initialize empty properties array
        $properties = array();
        $properties["identifier"] = $dataObject->getElementsByTagName('identifier')->item(0)->nodeValue;
        $properties["startDate"] = $dataObject->getElementsByTagName('startDate')->item(0)->nodeValue;
        $properties["completionDate"] = $dataObject->getElementsByTagName('completionDate')->item(0)->nodeValue;
        $properties["acquisitionSubType"] = $dataObject->getElementsByTagName('acquisitionSubType')->item(0)->nodeValue;
        $properties["serialIdentifier"] = $dataObject->getElementsByTagName('serialIdentifier')->item(0)->nodeValue;
        $properties["orbitNumber"] = $dataObject->getElementsByTagName('orbitNumber')->item(0)->nodeValue;
        $properties["cloudCoverPercentage"] = $dataObject->getElementsByTagName('cloudCoverPercentage')->item(0)->nodeValue;
        $properties["archivingCenter"] = $dataObject->getElementsByTagName('archivingCenter')->item(0)->nodeValue;
        $posList = $dataObject->getElementsByTagName('posList')->item(0)->nodeValue;
        // Album, quicklook and thumbnails
        $browses = $dataObject->getElementsByTagName('BrowseInformation');
        foreach ($browses as $browse) {
            $type = $browse->getElementsByTagName('type')->item(0)->nodeValue;
            $properties[strtolower($type)] = $browse->getElementsByTagName('fileName')->item(0)->nodeValue;
        }
        // Masks
        $masks = $dataObject->getElementsByTagName('MaskInformation');
        foreach ($masks as $mask) {
            $type = $mask->getElementsByTagName('type')->item(0)->nodeValue;
            if ($mask->getElementsByTagName('referenceSystemIdentifier')->item(0)->nodeValue === "4326") {
                $properties[strtolower($type)] = $mask->getElementsByTagName('fileName')->item(0)->nodeValue;
            }
        }
        /*
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($posList, LATLON), 'properties' => $properties);
        /*
         * Add feature array to feature collection array
         */
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
示例#4
0
function outputToGeoJSON($theData, $slotprefix, $objprefix)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Number of objects returned
     */
    $searchResults = $doc->getElementsByTagname('SearchResults');
    $totalResults = 0;
    $returnedResults = 0;
    if ($searchResults->item(0) != null) {
        $totalResults = $searchResults->item(0)->getAttribute('numberOfRecordsMatched');
        $returnedResults = $searchResults->item(0)->getAttribute('numberOfRecordsMatched');
    } else {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => urldecode($theData)));
        return json_encode($geojson);
    }
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $totalResults, 'features' => array());
    /*
     * EOProduct properties
     */
    $eopmapping = array($slotprefix . "acquisitionType" => "acquisitionType", $slotprefix . "acquisitionSubType" => "acquisitionSubType", $slotprefix . "status" => "status", $slotprefix . "beginPosition" => "beginPosition", $slotprefix . "endPosition" => "endPosition", $slotprefix . "productType" => "productType", $slotprefix . "pitch" => "pitch", $slotprefix . "parentIdentifier" => "parentIdentifier", $slotprefix . "incidenceAngle" => "incidenceAngle", $slotprefix . "sensorType" => "sensorType", $slotprefix . "instrumentShortName" => "instrumentShortName", $slotprefix . "sensorOperationalMode" => "sensorOperationalMode", $slotprefix . "platformOrbitType" => "platformOrbitType");
    /*
     * Process all RegistryPackages
     */
    $registryPackages = $searchResults->item(0)->getElementsByTagname('RegistryPackage');
    foreach ($registryPackages as $registryPackage) {
        /*
         * Process all ExtrinsicObject within the RegistryPackage
         */
        $properties = array();
        $extrinsicObjects = $registryPackage->getElementsByTagname('ExtrinsicObject');
        /*
         * Map EOProduct slots
         */
        foreach ($extrinsicObjects as $extrinsicObject) {
            /*
             * EOProduct
             */
            if ($extrinsicObject->getAttribute('objectType') == $objprefix . "EOProduct") {
                /*
                 * Get EOProduct identifier
                 */
                $properties['identifier'] = $extrinsicObject->getAttribute('id');
            } elseif ($extrinsicObject->getAttribute('objectType') == $objprefix . "EOAcquisitionPlatform") {
                /*
                 * Get Platform name
                 */
                $name = $extrinsicObject->getElementsByTagname('Name');
                if ($name->item(0) != null) {
                    $properties['platformName'] = $name->item(0)->getElementsByTagname('LocalizedString')->item(0)->getAttribute('value');
                }
            } elseif ($extrinsicObject->getAttribute('objectType') == $objprefix . "EOBrowseInformation") {
                /*
                 * Get Browseinformation
                 */
                $name = $extrinsicObject->getElementsByTagname('Name');
                if ($name->item(0) != null) {
                    $browsetype = strtolower($name->item(0)->getElementsByTagname('LocalizedString')->item(0)->getAttribute('value'));
                    $slots = $extrinsicObject->getElementsByTagname('Slot');
                    foreach ($slots as $slot) {
                        if ($slot->getAttribute('name') == $slotprefix . "fileName") {
                            $properties[$browsetype] = $slot->getElementsByTagname('Value')->item(0)->nodeValue;
                        }
                    }
                }
            } elseif ($extrinsicObject->getAttribute('objectType') == $objprefix . "EOProductInformation") {
                /*
                 * Get Productinformation
                 */
                $slots = $extrinsicObject->getElementsByTagname('Slot');
                if ($slots->item(0) != null) {
                    foreach ($slots as $slot) {
                        if ($slot->getAttribute('name') == $slotprefix . "fileName") {
                            $properties["productUrl"] = $slot->getElementsByTagname('Value')->item(0)->nodeValue;
                        }
                    }
                }
            } else {
                continue;
            }
            /*
             * Roll over each Slot
             */
            $slots = $extrinsicObject->getElementsByTagname('Slot');
            foreach ($slots as $slot) {
                /*
                 * Parse the eopmapping array and compare it
                 * to the Slot 'name' attribute
                 */
                $keys = array_keys($eopmapping);
                for ($i = 0; $i < count($keys); $i++) {
                    $name = $keys[$i];
                    if ($slot->getAttribute('name') == $name) {
                        $properties[$eopmapping[$name]] = $slot->getElementsByTagname('Value')->item(0)->nodeValue;
                        break;
                    }
                }
                /*
                 * Special case for multiExtentOf
                 */
                if ($slot->getAttribute('name') == $slotprefix . "multiExtentOf") {
                    $linearRing = $slot->getElementsByTagname('LinearRing')->item(0);
                    /*
                     * Compute posList from linearRing content
                     * A <gml:LinearRing> could contain either :
                     *  - one <gml:posList>
                     *  - several <gml:pos>
                     */
                    if ($linearRing->getElementsByTagname('posList')->length != 0) {
                        $posList = $linearRing->getElementsByTagname('posList')->item(0)->nodeValue;
                    } else {
                        $poss = $linearRing->getElementsByTagname('pos');
                        $posList = "";
                        foreach ($poss as $pos) {
                            $posList .= $pos->nodeValue . " ";
                        }
                    }
                }
            }
        }
        /*
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($posList, LATLON), 'properties' => $properties);
        /*
         * Add feature array to feature collection array
         */
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}