[Mapbender-commits] r9998 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Nov 14 12:40:13 PST 2018


Author: armin11
Date: 2018-11-14 12:40:13 -0800 (Wed, 14 Nov 2018)
New Revision: 9998

Modified:
   trunk/mapbender/http/php/mod_dataISOMetadata.php
Log:
Enhancement when exporting dataset iso metadata from metador - also publish polygonal extent as gml3 if given in bounding_geom column of mb_metadata. gml:id attributes are generated on the fly from hashing gml elements!

Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php	2018-11-13 18:20:11 UTC (rev 9997)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php	2018-11-14 20:40:13 UTC (rev 9998)
@@ -99,7 +99,7 @@
 	//get record from mb_metadata and prohibit duplicates:
 	$sql = <<<SQL
 
-SELECT *, st_xmin(the_geom) || ',' || st_ymin(the_geom) || ',' || st_xmax(the_geom) || ',' || st_ymax(the_geom)  as bbox2d FROM mb_metadata WHERE uuid = $1 ORDER BY lastchanged DESC LIMIT 1
+SELECT *, st_xmin(the_geom) || ',' || st_ymin(the_geom) || ',' || st_xmax(the_geom) || ',' || st_ymax(the_geom)  as bbox2d, st_asgml(3, bounding_geom) as bounding_polygon FROM mb_metadata WHERE uuid = $1 ORDER BY lastchanged DESC LIMIT 1
 
 SQL;
 	$v = array($uuid);
@@ -111,6 +111,71 @@
 	}
 	$row = db_fetch_assoc($res);
 	$mb_metadata = $row;
+
+	//parse polygon to add needed gml:id attributes for metadata validation
+	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);
+				
+		$gml3FromPostgis = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".$row['bounding_polygon'];
+		libxml_use_internal_errors(true);
+		try {
+			$gml3 = simplexml_load_string($gml3FromPostgis);
+			if ($gml3 === 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 ($gml3 !== false) {
+			$gml3->addAttribute('xmlns:xmlns:gml', 'http://www.opengis.net/gml');
+			$gml3->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+			$gml3 = simplexml_load_string($gml3->asXML());
+			if ($gml3->xpath('//gml:MultiSurface')) {
+				$e = new mb_notice("php/mod_dataISOMetadata.php: MultiSurface found!");
+				$gml3->addAttribute('gml:gml:id', md5($gml3->asXML()));
+				//count surfaceMembers
+				$numberOfSurfaces = count($gml3->xpath('//gml:MultiSurface/gml:surfaceMember'));
+				$e = new mb_notice("php/mod_dataISOMetadata.php: number of polygons: ".$numberOfSurfaces);
+				for ($k = 0; $k < $numberOfSurfaces; $k++) {
+					$polygon = $gml3->xpath('//gml:MultiSurface/gml:surfaceMember/gml:Polygon');
+					//$e = new mb_exception($polygon[0]->asXML());
+					$polygon = $polygon[0];
+					$polygon->addAttribute('gml:gml:id', md5($polygon->asXML()));
+				}
+			} else { 
+				$e = new mb_notice("php/mod_dataISOMetadata.php: no MultiSurface found!");
+				if($gml3->xpath('//gml:Polygon')) {
+					$e = new mb_notice("php/mod_dataISOMetadata.php: number of polygons: 1");
+					$polygon = $gml3->xpath('//gml:Polygon');
+					$polygon = $polygon[0];
+					$polygon->addAttribute('gml:gml:id', md5($polygon->asXML()));
+				}
+			}
+		}
+		//remove gml namespace to be secure! - maybe TODO 
+		/*$namespaces = $gml3->xpath('//gml:MultiSurface/@srsName');
+		foreach ($namespaces as $namespace) {
+    			unset($namespace[0]);
+		}*/
+		$mb_metadata['boundingPolygonGml'] = str_replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>","",$gml3->asXML());
+	} else {
+		$mb_metadata['boundingPolygonGml'] = false;
+	}
+	//$e = new mb_exception('gml: '.$boundingPolygonGml);
+	//if ($mb_metadata['boundinggeom'] == '') {
+	//	$e = new mb_exception("no bounding geometry available!");
+	//}
 	//convert dates to timestamps
 	$mb_metadata['createdate'] = strtotime($mb_metadata['createdate']);
 	$mb_metadata['changedate'] = strtotime($mb_metadata['changedate']);
@@ -1296,9 +1361,6 @@
 	if ($mb_metadata['spatial_res_value'] == '') {
 		$mb_metadata['spatial_res_value'] = 0;
 	}
-
-
-
 	if ($mb_metadata['spatial_res_type'] == 'groundDistance') {
 		$distance = $iso19139->createElement("gmd:distance");
 		$Distance = $iso19139->createElement("gco:Distance");
@@ -1382,12 +1444,6 @@
 	$t = array('i','i','i');
 	$res = db_prep_query($sql,$v,$t);
 	$e = new mb_notice("look for topic: ");
-
-
-
-
-
-
 	$countTopic = 0;
 	while ($row = db_fetch_array($res)) {
 		$e = new mb_notice("topic cat found: ".$row['md_topic_category_code_en']);
@@ -1409,6 +1465,31 @@
 		$topicCategory->appendChild($MD_TopicCategoryCode);
 		$MD_DataIdentification->appendChild($topicCategory);
 	}
+
+//example for multipolygonal extent with wrong gml ids
+/*<gmd:extent><gmd:EX_Extent><gmd:geographicElement><gmd:EX_BoundingPolygon><gmd:polygon><gml:MultiSurface srsName="EPSG:4326" gml:id="xs:4132378"><gml:surfaceMember><gml:Polygon gml:id="xs:4132378"><gml:exterior><gml:LinearRing><gml:posList srsDimension="2">7.632389 50.393998 7.63219 50.394527 7.632518 50.394749 7.633134 50.394392 7.633755 50.39442 7.633864 50.39435 7.633868 50.394318 7.633928 50.394335 7.634223 50.394456 7.635028 50.393798 7.634869 50.393729 7.635206 50.393539 7.634863 50.39329 7.634811 50.393318 7.634069 50.39278 7.633948 50.392693 7.633702 50.392844 7.633353 50.392603 7.632831 50.392248 7.632601 50.392093 7.632761 50.391968 7.632839 50.391786 7.632804 50.391773 7.632724 50.39195 7.632228 50.392331 7.631741 50.392702 7.632047 50.393318 7.632363 50.393947 7.632389 50.393998</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon gml:id="xs:4132378"><gml:exterior><gml:LinearRing><gml:posList srsDimension="2">7.
 638676 50.390807 7.63969 50.392005 7.639833 50.391981 7.640094 50.391948 7.640364 50.39185 7.640583 50.391703 7.640039 50.390515 7.639995 50.390339 7.638676 50.390807</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface></gmd:polygon></gmd:EX_BoundingPolygon></gmd:geographicElement></gmd:EX_Extent></gmd:extent>*/
+
+	//generate polygonal extent if given:
+	if ($mb_metadata['boundingPolygonGml'] !== false) {
+		$extent=$iso19139->createElement("gmd:extent");
+		$EX_Extent=$iso19139->createElement("gmd:EX_Extent");
+		$geographicElement=$iso19139->createElement("gmd:geographicElement");
+		$EX_BoundingPolygon=$iso19139->createElement("gmd:EX_BoundingPolygon");
+		$polygon=$iso19139->createElement("gmd:polygon");
+		//inject polygons
+		$gmlDoc = new DOMDocument();
+		$gmlDoc->loadXML($mb_metadata['boundingPolygonGml']);
+		$xpathGml = new DOMXpath($gmlDoc);
+		$gmlNodeList = $xpathGml->query('/gml:MultiSurface');
+		for ($i = ($gmlNodeList->length)-1; $i >= 0; $i--) {
+			$polygon->appendChild($iso19139->importNode($gmlNodeList->item($i), true));
+		}
+		$EX_BoundingPolygon->appendChild($polygon);
+		$geographicElement->appendChild($EX_BoundingPolygon);
+		$EX_Extent->appendChild($geographicElement);
+		$extent->appendChild($EX_Extent);
+		$MD_DataIdentification->appendChild($extent);
+	}
 	#Geographical Extent
 	$bbox = array();
 	//initialize if no extent is defined in the database
@@ -1416,7 +1497,6 @@
 	$bbox[1] = -90;
 	$bbox[2] = 180;
 	$bbox[3] = 90;
-
 	if (isset($mb_metadata['bbox2d']) & ($mb_metadata['bbox2d'] != '')) {
 		$bbox = explode(',',$mb_metadata['bbox2d']);
 	}
@@ -1463,6 +1543,10 @@
 	$extent->appendChild($EX_Extent);
 
 	$MD_DataIdentification->appendChild($extent);
+
+
+
+
 	//generate temporal extent from begin and end positions
 	/*
 <gmd:extent>



More information about the Mapbender_commits mailing list