[Mapbender-commits] r9077 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Sep 18 08:41:14 PDT 2014


Author: armin11
Date: 2014-09-18 08:41:14 -0700 (Thu, 18 Sep 2014)
New Revision: 9077

Modified:
   trunk/mapbender/http/plugins/mb_metadata_server.php
Log:
Allow handling of multipolygons as metadata extent (gml3 multisurface element)

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2014-09-18 15:40:32 UTC (rev 9076)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2014-09-18 15:41:14 UTC (rev 9077)
@@ -49,6 +49,39 @@
 	return;
 }
 
+function extractPolygonArray($domXpath, $path) {
+	$polygonalExtentExterior = array();
+	if ($domXpath->query($path.'/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList')) {
+		//read posList
+		$exteriorRingPoints = $domXpath->query($path.'/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList');
+		$exteriorRingPoints = DOMNodeListObjectValuesToArray($exteriorRingPoints);
+		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];
+			}
+		}
+	} else {
+		//try to read coordinates
+		$exteriorRingPoints = $domXpath->query($path.'/gml:Polygon/gml:exterior/gml:LinearRing/gml:coordinates');
+		$exteriorRingPoints = DOMNodeListObjectValuesToArray($exteriorRingPoints);
+		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]);
+				$polygonalExtentExterior[$i]['x'] = $coords[0];
+				$polygonalExtentExterior[$i]['y'] = $coords[1];
+			}
+		}
+	}
+	return $polygonalExtentExterior;
+}
+
 function gml2wkt($gml) {
 	//function to create wkt from given gml multipolygon
 	//DOM
@@ -56,7 +89,6 @@
 	$gmlObject = new DOMDocument();
 	libxml_use_internal_errors(true);
 	try {
-		//$feedXML = simplexml_load_string($feedFile);
 		$gmlObject->loadXML($gml);
 		if ($gmlObject === false) {
 			foreach(libxml_get_errors() as $error) {
@@ -70,57 +102,33 @@
     		$err = new mb_exception("mb_metadata_server.php:".$e->getMessage());
 		return false;
 	}
-
 	//if parsing was successful
 	if ($gmlObject !== false) {
 		//read crs from gml
 		$xpath = new DOMXPath($gmlObject);
 		$xpath->registerNamespace('gml','http://www.opengis.net/gml');
+		$MultiSurface = $xpath->query('/gml:MultiSurface');
+		if ($MultiSurface->length == 1) { //test for DOM!
+			$crs = $xpath->query('/gml:MultiSurface/@srsName');
+			$crsArray = DOMNodeListObjectValuesToArray($crs);
+			$crsId = end(explode(":",$crsArray[0]));
+			//count surfaceMembers
+			$numberOfSurfaces = count(DOMNodeListObjectValuesToArray($xpath->query('/gml:MultiSurface/gml:surfaceMember')));
+			for ($k = 0; $k < $numberOfSurfaces; $k++) {
+				$polygonalExtentExterior[] = extractPolygonArray($xpath, '/gml:MultiSurface/gml:surfaceMember');
+			}
+		} else { 
+			$polygonalExtentExterior[0] = extractPolygonArray($xpath, '/');
+		}
 		$crs = $xpath->query('/gml:Polygon/@srsName');
 		$crsArray = DOMNodeListObjectValuesToArray($crs);
 		$crsId = end(explode(":",$crsArray[0]));
-		//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 ($xpath->query('/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList')) {
-			//read posList
-			$exteriorRingPoints = $xpath->query('/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList');
-			$exteriorRingPoints = DOMNodeListObjectValuesToArray($exteriorRingPoints);
-			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];
-				}
-			}
-		} else {
-			//try to read coordinates
-			$exteriorRingPoints = $xpath->query('/gml:Polygon/gml:exterior/gml:LinearRing/gml:coordinates');
-			$exteriorRingPoints = DOMNodeListObjectValuesToArray($exteriorRingPoints);
-			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]);
-					$polygonalExtentExterior[$i]['x'] = $coords[0];
-					$polygonalExtentExterior[$i]['y'] = $coords[1];
-				}
-			}
-		}
-		//build wkt
 		if (!isset($crsId) || $crsId =="" || $crsId == NULL) {
 			//set default to lonlat wgs84
 			$crsId = "4326";
 		}
-		$wkt = "SRID=".$crsId.";POLYGON((";
-		//Example: "SRID=4326;POLYGON((-140 -80,-140 80,170 80,170 -80,-140 -80))"
-		foreach ($polygonalExtentExterior as $point) {
-			$wkt .= trim($point['x'])." ".trim($point['y']).",";
-		}
-		$wkt = rtrim($wkt,',');
-		$wkt .= "))";
-		$e = new mb_exception("plugins/mb_metadata_server.php: polygon: ".$wkt);
+		$mbMetadata = new Iso19139();
+		$wkt = $mbMetadata->createWktPolygonFromPointArray($polygonalExtentExterior);
 		return $wkt;
 	}
 }
@@ -920,6 +928,7 @@
 			$mbMetadata->inspireCharset = $data->inspire_charset;
 			$mbMetadata->updateFrequency = $data->update_frequency;
 			$mbMetadata->downloadLinks = array($data->downloadlink);
+			$mbMetadata->polygonalExtentExterior = null;
 			if (isset($data->inspire_whole_area) && $data->inspire_whole_area != "") {
 				$mbMetadata->inspireWholeArea = $data->inspire_whole_area;
 			} else {



More information about the Mapbender_commits mailing list