[Mapbender-commits] r10188 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jul 29 06:41:27 PDT 2019


Author: armin11
Date: 2019-07-29 06:41:26 -0700 (Mon, 29 Jul 2019)
New Revision: 10188

Modified:
   trunk/mapbender/http/classes/class_gml_2_factory.php
   trunk/mapbender/http/classes/class_gml_3_factory.php
   trunk/mapbender/http/classes/class_gml_factory.php
   trunk/mapbender/http/classes/class_gml_feature.php
   trunk/mapbender/http/classes/class_gml_geometry.php
   trunk/mapbender/http/classes/class_wfs.php
Log:
New options for wfs linked opendata proxy

Modified: trunk/mapbender/http/classes/class_gml_2_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2_factory.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_gml_2_factory.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -241,9 +241,13 @@
 	 * @param $domNode DOMNodeObject the feature tag of the GML 
 	 * 								(<gml:featureMember> in the above example)
 	 */
-	protected function parseFeature($domNode, $feature, $wfsConf, $gmlBoundedBySrs) {
-		$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
-
+	protected function parseFeature($domNode, $feature, $wfsConf, $gmlBoundedBySrs, $geometryColumnName=false) {
+		if ($geometryColumnName == false) {
+			//get name by information from wfs_conf
+			$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
+		} else {
+			$geomFeaturetypeElement = $geometryColumnName;
+		}
 		$currentSibling = $domNode;
 		
 		$feature->fid = $currentSibling->getAttribute("fid");
@@ -321,9 +325,9 @@
 	 * @return Gml_2
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml, $wfsConf) {
+	public function createFromXml ($xml, $wfsConf, $myWfs=false, $myFeatureType=false, $geomColumnName=false) {
 		$gml2 = new Gml_2();
-		return parent::createFromXml($xml, $wfsConf, $gml2);
+		return parent::createFromXml($xml, $wfsConf, $gml2, $myWfs, $myFeatureType, $geomColumnName);
 	}	
 }
 ?>

Modified: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -48,9 +48,9 @@
 	 * @return Gml_3
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml, $wfsConf) {
+	public function createFromXml ($xml, $wfsConf, $myWfs=false, $myFeatureType=false, $geomColumnName=false) {
 		$gml3 = new Gml_3();
-		return parent::createFromXml($xml, $wfsConf, $gml3);
+		return parent::createFromXml($xml, $wfsConf, $gml3, $myWfs, $myFeatureType, $geomColumnName);
 	}	
 
 	public static function getDimensionFromNode ($domNode) {
@@ -342,9 +342,13 @@
 	 * @param $domNode DOMNodeObject the feature tag of the GML 
 	 * 								(<gml:featureMember> in the above example)
 	 */
-	protected function parseFeature($domNode, $feature, $wfsConf, $gmlBoundedBySrs) {
-		$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
-
+	protected function parseFeature($domNode, $feature, $wfsConf, $gmlBoundedBySrs, $geometryColumnName=false) {
+		if ($geometryColumnName == false) {
+			//get name by information from wfs_conf
+			$geomFeaturetypeElement = $wfsConf->getGeometryColumnName();
+		} else {
+			$geomFeaturetypeElement = $geometryColumnName;
+		}
 		$feature->fid = $domNode->getAttribute("gml:id");
 		
 		$currentSibling = $domNode->firstChild;
@@ -358,7 +362,7 @@
 			$ns = $namespace['ns'];
 			$columnName = $namespace['value'];
 			$isGeomColumn = ($geomFeaturetypeElement == null || $columnName == $geomFeaturetypeElement);
-			
+			//$e = new mb_exception("classes/class_gml3_factory.php: current column name: ".$columnName." - compare to geomname: ". $geomFeaturetypeElement);			
 			// check if this node is a geometry node.
 			// however, even if it is a property node, 
 			// it has a child node, the text node!

Modified: trunk/mapbender/http/classes/class_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_factory.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_gml_factory.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -214,21 +214,24 @@
 	 * @return Gml
 	 * @param $xml String
 	 */
-	public function createFromXml ($xml, $wfsConf, $gml) {
+	public function createFromXml ($xml, $wfsConf, $gml, $myWfs=false, $myFeatureType=false, $geomColumnName=false) {
 		try {
 			$xml = $this->removeWhiteSpace($xml);
 			$gmlDoc = new SimpleXMLElement($xml);
-			
-			// we need to find the name and namespaces of the featuretype 
-			// used in this WFS configuration
-			$wfsFactory = new UniversalWfsFactory();
-			$myWfs = $wfsFactory->createFromDb($wfsConf->wfsId);
-			if (is_null($myWfs)) {
-				new mb_exception("class_gml_factory.php: createFromXml: WFS not found! ID: " . $wfsConf->wfsId);
-				return null;
+			//$e = new mb_exception("wfs: ".gettype($myWfs)." ft: ".gettype($myFeatureType)." geomname: ".$geomColumnName);
+			if ($myWfs != false && $myFeatureType != false && $geomColumnName != false) {
+				$featureType = $myFeatureType;
+			} else {
+				// we need to find the name and namespaces of the featuretype 
+				// used in this WFS configuration
+				$wfsFactory = new UniversalWfsFactory();
+				$myWfs = $wfsFactory->createFromDb($wfsConf->wfsId);
+				if (is_null($myWfs)) {
+					new mb_exception("class_gml_factory.php: createFromXml: WFS not found or given! ID: " . $wfsConf->wfsId);
+					return null;
+				}
+				$featureType = $myWfs->findFeatureTypeById($wfsConf->featureTypeId);
 			}
-			$featureType = $myWfs->findFeatureTypeById($wfsConf->featureTypeId);
-			
 			// register namespace of feature type
 			$pos = strpos($featureType->name, ":");
 			if ($pos !== false) {
@@ -256,7 +259,7 @@
 				foreach ($gmlFeatureMembers as $gmlFeatureMember) {
 					$gmlfeatureMember_dom = dom_import_simplexml($gmlFeatureMember);
 					$feature = new Feature();
-					$this->parseFeature($gmlfeatureMember_dom->firstChild, $feature, $wfsConf, $gmlBoundedBySrs);
+					$this->parseFeature($gmlfeatureMember_dom->firstChild, $feature, $wfsConf, $gmlBoundedBySrs, $geomColumnName);
 					if (isset($feature->geometry)) {
 						$gml->featureCollection->addFeature($feature);
 					}
@@ -271,7 +274,7 @@
 					foreach ($gmlFeatureMembers as $gmlFeatureMember) {
 						$gmlfeatureMember_dom = dom_import_simplexml($gmlFeatureMember);
 						$feature = new Feature();
-						$this->parseFeature($gmlfeatureMember_dom, $feature, $wfsConf, $gmlBoundedBySrs);
+						$this->parseFeature($gmlfeatureMember_dom, $feature, $wfsConf, $gmlBoundedBySrs, $geomColumnName);
 						if (isset($feature->geometry)) {
 							$gml->featureCollection->addFeature($feature);
 						}

Modified: trunk/mapbender/http/classes/class_gml_feature.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_feature.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_gml_feature.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -82,4 +82,4 @@
 	}
 }
 
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/http/classes/class_gml_geometry.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_geometry.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_gml_geometry.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -21,6 +21,7 @@
 require_once(dirname(__FILE__)."/../classes/class_connector.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_gml_feature_collection.php");
+require_once(dirname(__FILE__)."/../classes/class_crs.php");
 
 abstract class GmlGeometry {
 
@@ -45,10 +46,13 @@
 	
 	public function isLatLonSrs ($geomSrs) {
 		//use user defined $latLonSrsArray from file epsg.php for check 
-		require_once(dirname(__FILE__)."/../../core/epsg.php");
-		
-		$pattern = '/urn/';
-		if(preg_match($pattern, $geomSrs)) {
+		//require_once(dirname(__FILE__)."/../../core/epsg.php");
+		//new 2019-07-29
+		$crs = new Crs($geomSrs);
+		//$crs->axisOrder > different types:'east,north' - ('lon,lat') or 'north,east' - ('lat,lon')
+		//TODO: alter geometry classes to handle crs in a right way!
+		//$pattern = '/urn/';
+		/*if(preg_match($pattern, $geomSrs)) {
 			if(in_array($geomSrs, $latLonSrsArray)) {
 				return true;
 			}
@@ -55,8 +59,13 @@
 			else {
 				return false;
 			}	
+		}*/
+//$e = new mb_exception("classes/class_gml_geometry.php: axis order found: ".$crs->axisOrder);
+		if($crs->axisOrder == 'north,east') {
+			return true;
+		} else {
+			return false;
 		}
-		return false;
 	}
 }
 ?>

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2019-07-29 11:32:16 UTC (rev 10187)
+++ trunk/mapbender/http/classes/class_wfs.php	2019-07-29 13:41:26 UTC (rev 10188)
@@ -24,6 +24,7 @@
 require_once(dirname(__FILE__)."/class_ows.php");
 require_once(dirname(__FILE__)."/class_wfsToDb.php");
 require_once(dirname(__FILE__)."/class_wfs_configuration.php");
+require_once(dirname(__FILE__)."/class_crs.php");
 
 /**
  * An abstract Web Feature Service (WFS) class, modelling for example
@@ -53,7 +54,7 @@
 		array_push($this->featureTypeArray, $aFeatureType);
 	}
 	
-	protected function findFeatureTypeByName ($name) {
+	public function findFeatureTypeByName ($name) {
 		foreach ($this->featureTypeArray as $ft) {
 			if ($ft->name == $name) {
 				return $ft;
@@ -92,6 +93,19 @@
 		}
 		return null;
 	}
+
+	public static function findGeomColumnNameByFeaturetypeId($ftId) {
+		$geomTypesArray = array('GeometryPropertyType','PointPropertyType','LineStringPropertyType','PolygonPropertyType','MultiPointPropertyType','MultiLineStringPropertyType','MultiPolygonPropertyType');
+		$sql = "SELECT element_name, element_type FROM wfs_element WHERE fkey_featuretype_id = $1";
+		$res = db_prep_query($sql, array($ftId), array("i"));
+		//simple uses first supported geom type!
+		while($row = db_fetch_array($res)){
+			if (in_array($row['element_type'], $geomTypesArray)) {
+				return $row['element_name'];
+			}
+		}
+		return null;
+	}
 	
 	protected function getFeatureGet ($featureTypeName, $filter, $maxFeatures=null) {
 		switch ($this->getVersion()) {
@@ -248,7 +262,7 @@
 //		return $this->getFeatureGet($featureTypeName, $filter);
 	}
 
-	protected function getFeaturePostPaging ($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex, $version=false) {
+	protected function getFeaturePostPaging ($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex, $version=false, $outputFormat=false) {
 		if ($version == false) {
 			$version = $this->getVersion();
 		} else {
@@ -342,6 +356,33 @@
 		//TODO test if post is ok! mapserver in trier don't allow it?
 		//test get request
 		$getRequest = $this->getFeature.""."SERVICE=wfs&VERSION=".$version."&REQUEST=GetFeature"."&".$typeNameParameterName."=".$featureTypeName."&".$maxFeaturesParameterName."=".$maxFeatures."&STARTINDEX=".$startIndex."&".$maxFeaturesParameterName."=".$maxFeatures;
+		if ($outputFormat != false) {
+			$getRequest .= "&outputFormat=".$outputFormat;
+		}
+		if ($destSrs != false) {
+			//check crs representation
+			$crs = new Crs($destSrs);
+			$alterAxisOrder = $crs->alterAxisOrder("wfs_".$version);
+			$srsId = $crs->identifierCode;
+			//add srs to request
+			switch ($version) {
+				case "2.0.2":
+					$getRequest .= "&SRSNAME="."http://www.opengis.net/def/crs/EPSG/0/".$srsId;
+					break;
+				case "2.0.0":
+					$getRequest .= "&SRSNAME="."urn:ogc:def:crs:EPSG::".$srsId;	
+					break;
+				case "1.1.0":
+					$getRequest .= "&SRSNAME="."urn:ogc:def:crs:EPSG::".$srsId;
+					break;
+				case "1.0.0":
+					$getRequest .= "&SRSNAME="."EPSG:".$srsId;
+					break;
+			}
+		}	
+$e = new mb_exception($getRequest);
+		//convert gml 3 to geojson!
+		
 		return $this->get($getRequest);
 		//other variants
 		//return $this->post($this->getFeature.$maxFeaturesParameterName."=".$maxFeatures."&STARTINDEX=".$startIndex, $postData); //from class_ows!
@@ -551,7 +592,12 @@
 				"</wfs:Update>";
 	}
 	
-	public function getFeatureById ($featureTypeName, $outputFormat=false, $id) {
+	public function getFeatureById ($featureTypeName, $outputFormat=false, $id, $version=false, $srsName=false) {
+		if ($version == false) {
+			$version = $this->getVersion();
+		} else {
+			$e = new mb_exception("classes/class_wfs.php: wfs version forced too ".$version."!");
+		}
 		switch ($this->getVersion()) {
 			case "2.0.2":
 				$typeNameParameterName = "typeNames";
@@ -569,12 +615,36 @@
 				$featureIdParameterName = "featureID";
 				break;
 		}
-		$url = $this->getFeature .
+		$getRequest = $this->getFeature .
 			$this->getConjunctionCharacter($this->getFeature) . 
 			"service=WFS&request=GetFeature&version=" . 
 			$this->getVersion() . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&".$featureIdParameterName."=".$id;
-$e = new mb_exception($url);
-		return $this->get($url); //from class_ows!
+
+		if ($outputFormat != false) {
+			$getRequest .= "&outputFormat=".$outputFormat;
+		}
+		if ($srsName != false) {
+		//check crs representation
+			$crs = new Crs($srsName);
+			$alterAxisOrder = $crs->alterAxisOrder("wfs_".$version);
+			$srsId = $crs->identifierCode;
+			//add srs to request
+			switch ($version) {
+				case "2.0.2":
+					$getRequest .= "&SRSNAME="."http://www.opengis.net/def/crs/EPSG/0/".$srsId;
+					break;
+				case "2.0.0":
+					$getRequest .= "&SRSNAME="."urn:ogc:def:crs:EPSG::".$srsId;	
+					break;
+				case "1.1.0":
+					$getRequest .= "&SRSNAME="."urn:ogc:def:crs:EPSG::".$srsId;
+					break;
+				case "1.0.0":
+					$getRequest .= "&SRSNAME="."EPSG:".$srsId;
+					break;
+			}
+		}
+		return $this->get($getRequest); //from class_ows!
 	}
 	
 	protected function transactionDelete ($feature, $featureType, $authWfsConfElement) {
@@ -589,9 +659,7 @@
 				$featureNS . ":" . $authWfsConfElement->name . 
 				"</ogc:PropertyName><ogc:Literal>" . 
 				$user . "</ogc:Literal></ogc:PropertyIsEqualTo>";
-
 		}
-
 		// filter
 		if (!isset($feature->fid)) {
 			$e = new mb_exception("Feature ID not set.");



More information about the Mapbender_commits mailing list