[Mapbender-commits] r9030 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Aug 6 07:07:40 PDT 2014
Author: armin11
Date: 2014-08-06 07:07:40 -0700 (Wed, 06 Aug 2014)
New Revision: 9030
Modified:
trunk/mapbender/http/classes/class_iso19139.php
Log:
Possibility to handle simple gml3 exterior rings to use them as bounding geometries of metadata sets.
Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php 2014-08-05 14:13:04 UTC (rev 9029)
+++ trunk/mapbender/http/classes/class_iso19139.php 2014-08-06 14:07:40 UTC (rev 9030)
@@ -27,6 +27,8 @@
var $abstract;
var $metadata;
var $wgs84Bbox = array(); //minx, miny, maxx, maxy in EPSG:4326
+ var $polygonalExtentExterior; //Prototype: Two dimensional array of coordinates $polygonalExtentExterior[i]['x'], $polygonalExtentExterior[i]['y']
+ //var $polygonalExtentExterior = boolean; //TODO maybe implemented somewhen, now only exterior (GML3) is supported, maybe we can use the GML classes themself?
var $datasetId;
var $datasetIdCodeSpace;
var $keywords = array();
@@ -73,6 +75,7 @@
$this->changeDate = "1900-01-01";
$this->metadata = "";
$this->wgs84Bbox = array(-180.0,-90.0,180.0,90.0); //minx, miny, maxx, maxy in EPSG:4326
+ $this->polygonalExtentExterior = array(); //initialize empty array
$this->datasetId = "";
$this->datasetIdCodeSpace = "";
$this->keywords = array();
@@ -294,6 +297,34 @@
$maxy = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal');
$maxy = $maxy[0];
$this->wgs84Bbox = array($minx,$miny,$maxx,$maxy);
+ //more info: https://geo-ide.noaa.gov/wiki/index.php?title=ISO_Extents
+ //look for GML3 polygon as exterior ring in two alternative encodings (see: http://www.galdosinc.com/archives/191 - all coords are interpreted as given in EPSG:4326 for the moment!!!):
+ if ($iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_BoundingPolygon/gmd:polygon/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList')) {
+ //read posList
+ $exteriorRingPoints = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_BoundingPolygon/gmd:polygon/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList');
+ if (count($exteriorRingPoints) > 0) {
+ //poslist is only space separated
+ $exteriorRingPointsArray = explode(' ',$exteriorRingPoints[0]);
+ for ($i = 0; $i <= count($exteriorRingPointsArray)/2-1; $i++) {
+ $this->polygonalExtentExterior[$i]['x'] = $exteriorRingPointsArray[2*$i];
+ $this->polygonalExtentExterior[$i]['y'] = $exteriorRingPointsArray[(2*$i)+1];
+ }
+ }
+ } else {
+ //try to read coordinates
+ $exteriorRingPoints = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_BoundingPolygon/gmd:polygon/gml:Polygon/gml:exterior/gml:LinearRing/gml:coordinates');
+ if (count($exteriorRingPoints) > 0) {
+ //two coordinates of one point are comma separated
+ //problematic= ", " or " ," have to be deleted before
+ $exteriorRingPoints[0] = str_replace(', ',',',str_replace(' ,',',',$exteriorRingPoints[0]));
+ $exteriorRingPointsArray = explode(' ',$exteriorRingPoints[0]);
+ for ($i = 0; $i <= count($exteriorRingPointsArray)-1;$i++) {
+ $coords = explode(",",$exteriorRingPointsArray[$i]);
+ $this->polygonalExtentExterior[$i]['x'] = $coords[0];
+ $this->polygonalExtentExterior[$i]['y'] = $coords[1];
+ }
+ }
+ }
$this->hierachyLevel = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
$this->hierachyLevel = $this->hierachyLevel[0];
$this->tmpExtentBegin = $iso19139Xml->xpath('//gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
@@ -729,8 +760,55 @@
}
}
+ private function parseExteriorPolygon($gml3Polygon) {
+ //cause postgis gives back polygons without namspace, we have to add a namespace before parsing the xml again :-(
+ $gml3Polygon = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".$gml3Polygon;
+ libxml_use_internal_errors(true);
+ try {
+ $iso19139Xml = simplexml_load_string($gml3Polygon);
+ if ($iso19139Xml === false) {
+ foreach(libxml_get_errors() as $error) {
+ $err = new mb_exception("class_Iso19139:".$error->message);
+ }
+ throw new Exception("class_Iso19139:".'Cannot parse Metadata XML!');
+ return false;
+ }
+ }
+ catch (Exception $e) {
+ $err = new mb_exception("class_Iso19139:".$e->getMessage());
+ return false;
+ }
+ //if parsing was successful
+ if ($iso19139Xml !== false) {
+ //add ns as attribute
+ $iso19139Xml->addAttribute('xmlns:xmlns:gml', 'http://www.opengis.net/gml');
+ //reloadXML
+ $iso19139Xml = simplexml_load_string($iso19139Xml->asXML());
+ $iso19139Xml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+ $e = new mb_exception("class_iso19139.php: parsing successfull!");
+ //<gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList srsDimension="2">
+ $posListArray = $iso19139Xml->xpath('/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList');
+ if (count($posListArray) > 0) {
+ $e = new mb_exception("class_iso19139.php: found pos list!");
+ //read posList
+ $exteriorRingPoints = $posListArray;
+ if (count($exteriorRingPoints) > 0) {
+ //poslist is only space separated
+ $exteriorRingPointsArray = explode(' ',$exteriorRingPoints[0]);
+ for ($i = 0; $i <= count($exteriorRingPointsArray)/2-1; $i++) {
+ $polygonalExtentExterior[$i]['x'] = $exteriorRingPointsArray[2*$i];
+ $polygonalExtentExterior[$i]['y'] = $exteriorRingPointsArray[(2*$i)+1];
+ }
+ $e = new mb_exception("class_iso19139.php: ". count($polygonalExtentExterior) . " point objects!");
+ return $polygonalExtentExterior;
+ }
+ }
+ }
+ return array();
+ }
+
public function createFromDBInternalId($metadataId){
- $sql = "SELECT * , box2d(the_geom) as bbox2d from mb_metadata WHERE metadata_id = $1";
+ $sql = "SELECT * , box2d(the_geom) as bbox2d, st_asgml(3,bounding_geom) as bounding_polygon from mb_metadata WHERE metadata_id = $1";
$v = array($metadataId);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -752,6 +830,14 @@
//$e = new mb_exception("class_iso19139.php: got bbox for metadata: ".$bbox);
$this->wgs84Bbox = explode(',',$bbox);
}
+ if (isset($row['bounding_polygon']) && $row['bounding_polygon'] != '') {
+ //extract coordinates from gml
+ //push them into array
+ //store them in object
+ //$bbox = str_replace(' ',',',str_replace(')','',str_replace('BOX(','',$row['bbox2d'])));
+ //$e = new mb_exception("class_iso19139.php: got bbox for metadata: ".$bbox);
+ $this->polygonalExtentExterior = $this->parseExteriorPolygon($row['bounding_polygon']);
+ }
//fill keywords and categories later cause they are stored in relations!
/*$this->keywords = array();
$this->keywordsThesaurusName = array();
@@ -1089,6 +1175,23 @@
return $postGisBbox;
}
+ private function createWktPolygonFromPointArray($pointArray) { //-180 -90 180 90
+ $postGisPolygon = "";
+ //"SRID=4326;POLYGON((-140 -80,-140 80,170 80,170 -80,-140 -80))"
+ $postGisPolygon = "SRID=4326;POLYGON((";
+ if (count($pointArray) == 0) {
+ return null;
+ } else {
+ foreach ($pointArray as $point) {
+ $postGisPolygon .= trim($point['x'])." ".trim($point['y']).",";
+ }
+ $postGisPolygon = rtrim($postGisPolygon,',');
+ $postGisPolygon .= "))";
+ $e = new mb_exception("class_iso19139.php: polygon: ".$postGisPolygon);
+ return $postGisPolygon;
+ }
+ }
+
public function insertKeywordsAndCategoriesIntoDB($metadataId,$resourceType,$resourceId){
//first delete old classifications - after that create new ones
$this->deleteKeywordsAndCategoriesFromDB($metadataId,$resourceType,$resourceId);
@@ -1378,7 +1481,7 @@
public function insertMetadataIntoDB() {
//insert an instance for iso19139 into mapbenders database
$sql = <<<SQL
-INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset, ref_system, the_geom, datalinks, inspire_whole_area, inspire_actual_coverage, inspire_download) VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)
+INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset, ref_system, the_geom, datalinks, inspire_whole_area, inspire_actual_coverage, inspire_download, bounding_geom) VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35)
SQL;
$v = array(
$this->href,
@@ -1414,9 +1517,10 @@
$this->jsonEncodeDownloadLinks($this->downloadLinks),
$this->inspireWholeArea,
$this->inspireActualCoverage,
- $this->inspireDownload
+ $this->inspireDownload,
+ $this->createWktPolygonFromPointArray($this->polygonalExtentExterior)
);
- $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i');
+ $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON');
$res = db_prep_query($sql,$v,$t);
return $res;
}
@@ -1440,7 +1544,7 @@
$sql .= "linktype = $4, uuid = $5, title = $6, createdate = $7, changedate = $8, lastchanged = now(), ";
$sql .= "abstract = $9, searchtext = $10, type = $11, tmp_reference_1 = $12, tmp_reference_2 = $13, export2csw = $14, datasetid = $15, ";
$sql .= "datasetid_codespace = $16, randomid = $17, harvestresult = $20, harvestexception = $21, lineage = $22, inspire_top_consistence = $23, ";
- $sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29, the_geom = $30, datalinks = $31, inspire_whole_area = $32, inspire_actual_coverage = $33, inspire_download = $34 WHERE metadata_id = $19";
+ $sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29, the_geom = $30, datalinks = $31, inspire_whole_area = $32, inspire_actual_coverage = $33, inspire_download = $34, bounding_geom = $35 WHERE metadata_id = $19";
$v = array(
$this->href,
@@ -1477,9 +1581,10 @@
$this->jsonEncodeDownloadLinks($this->downloadLinks),
$this->inspireWholeArea,
$this->inspireActualCoverage,
- $this->inspireDownload
+ $this->inspireDownload,
+ $this->createWktPolygonFromPointArray($this->polygonalExtentExterior)
);
- $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i');
+ $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s','POLYGON','s','s','s','i','POLYGON');
$res = db_prep_query($sql,$v,$t);
return $res;
}
@@ -1576,7 +1681,7 @@
return true;
}
- private function getExtentGraphic($layer_4326_box) {
+ public function getExtentGraphic($layer_4326_box) {
$area_4326_box = explode(',',EXTENTSERVICEBBOX);
if ($layer_4326_box[0] <= $area_4326_box[0] || $layer_4326_box[2] >= $area_4326_box[2] || $layer_4326_box[1] <= $area_4326_box[1] || $layer_4326_box[3] >= $area_4326_box[3]) {
if ($layer_4326_box[0] < $area_4326_box[0]) {
@@ -1605,47 +1710,10 @@
if ($new_miny < -90) $area_4326_box[1] = -90; else $area_4326_box[1] = $new_miny;
if ($new_maxy > 90) $area_4326_box[3] = 90; else $area_4326_box[3] = $new_maxy;
}
- $getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$area_4326_box[0].",".$area_4326_box[1].",".$area_4326_box[2].",".$area_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3];
+ $getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$area_4326_box[0].",".$area_4326_box[1].",".$area_4326_box[2].",".$area_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3]."&metadata_uuid=".$this->fileIdentifier;
return $getMapUrl;
}
-
-
-
-/* private function getExtentGraphic($layer_4326_box) {
- $rlp_4326_box = array(6.05,48.9,8.6,50.96);
- if ($layer_4326_box[0] <= $rlp_4326_box[0] || $layer_4326_box[2] >= $rlp_4326_box[2] || $layer_4326_box[1] <= $rlp_4326_box[1] || $layer_4326_box[3] >= $rlp_4326_box[3]) {
- if ($layer_4326_box[0] < $rlp_4326_box[0]) {
- $rlp_4326_box[0] = $layer_4326_box[0];
- }
- if ($layer_4326_box[2] > $rlp_4326_box[2]) {
- $rlp_4326_box[2] = $layer_4326_box[2];
- }
- if ($layer_4326_box[1] < $rlp_4326_box[1]) {
- $rlp_4326_box[1] = $layer_4326_box[1];
- }
- if ($layer_4326_box[3] > $rlp_4326_box[3]) {
- $rlp_4326_box[3] = $layer_4326_box[3];
- }
-
- $d_x = $rlp_4326_box[2] - $rlp_4326_box[0];
- $d_y = $rlp_4326_box[3] - $rlp_4326_box[1];
-
- $new_minx = $rlp_4326_box[0] - 0.05*($d_x);
- $new_maxx = $rlp_4326_box[2] + 0.05*($d_x);
- $new_miny = $rlp_4326_box[1] - 0.05*($d_y);
- $new_maxy = $rlp_4326_box[3] + 0.05*($d_y);
-
- if ($new_minx < -180) $rlp_4326_box[0] = -180; else $rlp_4326_box[0] = $new_minx;
- if ($new_maxx > 180) $rlp_4326_box[2] = 180; else $rlp_4326_box[2] = $new_maxx;
- if ($new_miny < -90) $rlp_4326_box[1] = -90; else $rlp_4326_box[1] = $new_miny;
- if ($new_maxy > 90) $rlp_4326_box[3] = 90; else $rlp_4326_box[3] = $new_maxy;
- }
- $getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$rlp_4326_box[0].",".$rlp_4326_box[1].",".$rlp_4326_box[2].",".$rlp_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3];
- return $getMapUrl;
- }*/
-
-
public function insertToDB($resourceType, $resourceId){
$result = array(); //value/message
switch ($this->origin) {
More information about the Mapbender_commits
mailing list