[Mapbender-commits] r10212 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Aug 15 08:13:03 PDT 2019


Author: armin11
Date: 2019-08-15 08:13:03 -0700 (Thu, 15 Aug 2019)
New Revision: 10212

Modified:
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/php/mod_linkedDataProxy.php
Log:
New options to handle post/get and set more filters to wfs 3.0 proxy prototype

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2019-08-14 16:42:51 UTC (rev 10211)
+++ trunk/mapbender/http/classes/class_wfs.php	2019-08-15 15:13:03 UTC (rev 10212)
@@ -107,7 +107,7 @@
 		return null;
 	}
 	
-	protected function getFeatureGet ($featureTypeName, $filter, $maxFeatures=null) {
+	protected function getFeatureGet ($featureTypeName, $filter, $maxFeatures=null, $version="2.0.0") {
 		switch ($this->getVersion()) {
 			case "2.0.2":
 				$typeNameParameterName = "typeNames";
@@ -249,19 +249,6 @@
 //		return $this->getFeatureGet($featureTypeName, $filter);
 	}
 
-	public function getFeaturePaging ($featureTypeName, $filter, $destSrs=null, $storedQueryId=null, $storedQueryParams=null,  $maxFeatures=null, $startIndex=null, $version=false, $outputFormat=false) {
-
-// FOR NOW, WE ONLY DO POST REQUESTS!
-// THE FILTERS ARE CONSTRUCTED ON THE CLIENT SIDE,
-// SO CHANGING THEM HERE ACCORDING TO GET/POST
-// WOULD BE TOO MUCH FOR NOW
-//
-//		if (strpos($this->getFeature, "?") === false) {
-			return $this->getFeaturePostPaging($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex, $version, $outputFormat);
-//		}
-//		return $this->getFeatureGet($featureTypeName, $filter);
-	}
-
 	public function bbox2spatialFilter($bbox, $geometryColumn, $srs="EPSG:4326", $version=false){
 		//define spatial filter from GET (https://github.com/opengeospatial/WFS_FES) bbox=160.6,-55.95,-170,-25.89 - geojson long/lat - east/north!	
 		/*
@@ -390,8 +377,7 @@
 		return $spatialFilter;
 	}
 
-	protected function getFeaturePostPaging ($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex, $version=false, $outputFormat=false) {
-//$e = new mb_exception("classes/class_wfs.php: filter: ".$filter);
+	public function getFeaturePaging ($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex, $version=false, $outputFormat=false, $method="POST") {
 		if ($version == false) {
 			$version = $this->getVersion();
 		} else {
@@ -428,27 +414,30 @@
 				$srsName = "EPSG:".$srsId;
 				break;
 		}
+$e = new mb_exception($filter);
 		if($storedQueryId && $storedQueryId != "") {
-			$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
-					"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
-					"xmlns:wfs=\"http://www.opengis.net/wfs/2.0\" " .
-					//"xmlns:xlink=\"http://www.w3.org/1999/xlink\" " .
-					//"xmlns:ogc=\"http://www.opengis.net/ogc\" ".
-					//"xmlns:ows=\"http://www.opengis.net/ows/1.1\" " .
-					"xmlns:gml=\"http://www.opengis.net/gml/3.2\" " .
-					"xmlns:fes=\"http://www.opengis.net/fes/2.0\" " .
-					"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
-					"xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd\" ";
-			if (isset($outputFormat) && $outputFormat != '') {
-				$postData .= "outputFormat=\"".$outputFormat."\">";
-			} else {
-				$postData .= ">";
-			}
-			$postData .= "<wfs:StoredQuery id=\"" . $storedQueryId . "\">";
-			$postData .= $storedQueryParams;
-			$postData .= "</wfs:StoredQuery>";
+		    $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+				"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
+				"xmlns:wfs=\"http://www.opengis.net/wfs/2.0\" " .
+				//"xmlns:xlink=\"http://www.w3.org/1999/xlink\" " .
+				//"xmlns:ogc=\"http://www.opengis.net/ogc\" ".
+				//"xmlns:ows=\"http://www.opengis.net/ows/1.1\" " .
+				"xmlns:gml=\"http://www.opengis.net/gml/3.2\" " .
+				"xmlns:fes=\"http://www.opengis.net/fes/2.0\" " .
+				"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
+				"xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd\" ";
+		    if (isset($outputFormat) && $outputFormat != '') {
+			$postData .= "outputFormat=\"".$outputFormat."\">";
+		    } else {
+			$postData .= ">";
+		    }
+		    $postData .= "<wfs:StoredQuery id=\"" . $storedQueryId . "\">";
+		    $postData .= $storedQueryParams;
+		    $postData .= "</wfs:StoredQuery>";
 		} else {
-			if($version == "2.0.0" || $version == "2.0.2") {
+		    switch ($method) {
+			case "POST":
+			    if($version == "2.0.0" || $version == "2.0.2") {
 				$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
 					"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
 					"xmlns:wfs=\"http://www.opengis.net/wfs/2.0\" ".
@@ -459,12 +448,12 @@
 					"xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd\" ".
 					"startIndex=\"".$startIndex."\" count=\"".$maxFeatures."\" ";
 				if (isset($outputFormat) && $outputFormat != '') {
-					$postData .= "outputFormat=\"".$outputFormat."\">";
+				    $postData .= "outputFormat=\"".$outputFormat."\">";
 				} else {
-					$postData .= ">";
+				    $postData .= ">";
 				}
-			}//TODO: not already implemented - maybe usefull for older geoserver/mapserver implementations
-			else if($version == "1.1.0") {
+				//TODO: not already implemented - maybe usefull for older geoserver/mapserver implementations
+			    } else if($version == "1.1.0") {
 				$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
 						"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
 						"xmlns:wfs=\"http://www.opengis.net/wfs\" " .
@@ -473,12 +462,11 @@
 						"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
 						"xsi:schemaLocation=\"http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd\" ";
 				if (isset($outputFormat) && $outputFormat != '') {
-					$postData .= "outputFormat=\"".$outputFormat."\">";
+				    $postData .= "outputFormat=\"".$outputFormat."\">";
 				} else {
-					$postData .= ">";
+				    $postData .= ">";
 				}
-			}
-			else {
+			    } else {
 				$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
 						"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
 						"xmlns:wfs=\"http://www.opengis.net/wfs\" " .
@@ -487,56 +475,46 @@
 						"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
 						"xsi:schemaLocation=\"http://www.opengis.net/wfs ../wfs/1.0.0/WFS-basic.xsd\" ";
 				if (isset($outputFormat) && $outputFormat != '') {
-					$postData .= "outputFormat=\"".$outputFormat."\">";
+				    $postData .= "outputFormat=\"".$outputFormat."\">";
 				} else {
-					$postData .= ">";
+				    $postData .= ">";
 				}
-			}
-			$postData .="<wfs:Query ";
-			if($destSrs) {
+			    }
+			    $postData .="<wfs:Query ";
+			    if($destSrs) {
 				$postData .= "srsName=\"" . $srsName . "\" ";
-			}
-			// add namespace
-			if (strpos($featureTypeName, ":") !== false) {
+			    }
+			    //add namespace
+			    if (strpos($featureTypeName, ":") !== false) {
 				$ft = $this->findFeatureTypeByName($featureTypeName);
 				$ns = $this->getNamespace($featureTypeName);
 				$url = $ft->getNamespace($ns);
 				$postData .= "xmlns:" . $ns . "=\"" . $url . "\" ";	
-			}
-			if($version == "2.0.0" || $version == "2.0.2") {
-				//change filter to fes syntax
-				/*$filter = str_replace("<ogc", "<fes", $filter);
-				$filter = str_replace("/ogc", "/fes", $filter);
-			        $filter = str_replace("PropertyName", "ValueReference", $filter);*/
-			}
-			$postData .= $typeNameParameterName."=\"" . $featureTypeName . "\"  >";
-
-			$postData .= $filter .
-					"</wfs:Query>";
+			    }
+			    $postData .= $typeNameParameterName."=\"".$featureTypeName."\">";
+			    $postData .= $filter."</wfs:Query>";
+ 			    $postData .= "</wfs:GetFeature>";
+			    return $this->post($this->getFeature, $postData);
+			    break;
+		        case "GET":
+		            $getRequest = $this->getFeature.$this->getConjunctionCharacter($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) {
+			        $getRequest .= "&SRSNAME=".$srsName;
+		            }
+			    if ($filter != null) {
+				$getRequest .= "&FILTER=".urlencode($filter);
+			    }
+//$e = new mb_exception("classes/class_wfs.php: getfeature-GET-url: ".$getRequest);
+                            return $this->get($getRequest);
+			    break;
+		    }
 		}
-		$postData .= "</wfs:GetFeature>";	
-                //$e = new mb_exception("class_wfs.php: getFeaturePost: ".$postData);
-		//$e = new mb_exception("class_wfs.php: getFeaturePost url: ".$this->getFeature."&".$maxFeaturesParameterName."=".$maxFeatures."&STARTINDEX=".$startIndex);
-		//TODO test if post is ok! mapserver in trier don't allow it?
-		//test HTTP 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) {
-			$getRequest .= "&SRSNAME=".$srsName;
-		}	
-		//$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!
-//$e = new mb_exception("classes/class_wfs.php: getFeaturePostPaging: postdata: ".$postData);		
-		return $this->post($this->getFeature, $postData); //from class_ows!
 	}
 
-	public function countFeatures($featureTypeName, $filter=null, $version=false) {
+	public function countFeatures($featureTypeName, $filter=null, $destSrs=false, $version=false, $outputFormat=false, $method="POST") {
 //$e = new mb_exception("testwfs");
 		if ($version == false) {
 			$version = $this->getVersion();
@@ -543,73 +521,6 @@
 		} else {
 			$e = new mb_notice("classes/class_wfs.php: wfs version forced to ".$version."!");
 		}
-		switch ($version) {
-			case "2.0.2":
-				$typeNameParameterName = "typeNames";
-				$maxFeaturesParameterName = "COUNT";
-				break;
-			case "2.0.0":
-				$typeNameParameterName = "typeNames";
-				$maxFeaturesParameterName = "COUNT";
-				break;
-			default:
-				$typeNameParameterName = "typeName";
-				$maxFeaturesParameterName = "MAXFEATURES";
-				break;
-		}
-		if ($version == "1.0.0") {
-			$e = new mb_exception("Counting features not possible in wfs <= 1.0.0!");
-			return false;
-		}
-
-		$url = $this->getFeature .
-		$this->getConjunctionCharacter($this->getFeature) . 
-		"service=WFS&request=GetFeature&version=" . 
-		$version . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
-
-		if ($filter != null) {
-			$url .= "&FILTER=".urlencode($filter);
-			//$url .= "&FILTER=".$filter;
-		}
-		//auth is already integrated in ows class
-		//do request
-		$resultOfCount = $this->get($url); //from class_ows!
-		//parse hits
-		try {
-			$featureTypeHits =  new SimpleXMLElement($resultOfCount);
-			if ($featureTypeHits == false) {
-				throw new Exception('Cannot parse WFS number of hits request!');
-			}
-		}
-		catch (Exception $e) {
-    			$e = new mb_exception($e->getMessage());
-		}
-		switch ($version) {
-			case "2.0.0":
-				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberMatched');
-				break;
-			case "2.0.2":
-				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberMatched');
-				break;
-			case "1.1.0":
-				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberOfFeatures');
-				break;
-		}
-/*
-<?xml version='1.0' encoding='UTF-8'?>
-<wfs:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:wfs="http://www.opengis.net/wfs" timeStamp="2019-07-23T08:07:26Z" numberOfFeatures="183">
-</wfs:FeatureCollection>
-*/
-		return (integer)$hits[0];
-	}
-
-	public function countFeaturesPost($featureTypeName, $filter=null, $destSrs=false, $version=false, $outputFormat=false) {
-//$e = new mb_exception("testwfs");
-		if ($version == false) {
-			$version = $this->getVersion();
-		} else {
-			$e = new mb_notice("classes/class_wfs.php: wfs version forced to ".$version."!");
-		}
 		if ($destSrs != false) {
 			//check crs representation
 			$crs = new Crs($destSrs);
@@ -635,71 +546,65 @@
 			$e = new mb_exception("Counting features not possible in wfs <= 1.0.0!");
 			return false;
 		}
-		if($version == "2.0.0" || $version == "2.0.2") {
-			$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
-				"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
-				"xmlns:wfs=\"http://www.opengis.net/wfs/2.0\" ".
-				"xmlns:fes=\"http://www.opengis.net/fes/2.0\" ".
-				"xmlns:gml=\"http://www.opengis.net/gml/3.2\" ".
-				"xmlns:ogc=\"http://www.opengis.net/ogc\" " .
-				"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
-				"xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd\" resultType=\"hits\"";
-			if (isset($outputFormat) && $outputFormat != '') {
-				$postData .= "outputFormat=\"".$outputFormat."\" "; //tag ends later	
-			} else {
-				$postData .= ">";
-			}
-		}//TODO: not already implemented - maybe usefull for older geoserver/mapserver implementations
-		else if($version == "1.1.0") {
-			$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+		switch ($method) {
+		    case "POST":
+			if($version == "2.0.0" || $version == "2.0.2") {
+				$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
 					"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
-					"xmlns:wfs=\"http://www.opengis.net/wfs\" " .
-					"xmlns:gml=\"http://www.opengis.net/gml\" " .
+					"xmlns:wfs=\"http://www.opengis.net/wfs/2.0\" ".
+					"xmlns:fes=\"http://www.opengis.net/fes/2.0\" ".
+					"xmlns:gml=\"http://www.opengis.net/gml/3.2\" ".
 					"xmlns:ogc=\"http://www.opengis.net/ogc\" " .
 					"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
-					"xsi:schemaLocation=\"http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd\"";
-			if (isset($outputFormat) && $outputFormat != '') {
-				$postData .= "outputFormat=\"".$outputFormat."\" "; //tag ends later
-			} else {
-				$postData .= ">";
+					"xsi:schemaLocation=\"http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd\" resultType=\"hits\"";
+				if (isset($outputFormat) && $outputFormat != '') {
+					$postData .= "outputFormat=\"".$outputFormat."\" "; //tag ends later	
+				} else {
+					$postData .= ">";
+				}
+			}//TODO: not already implemented - maybe usefull for older geoserver/mapserver implementations
+			else if($version == "1.1.0") {
+				$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+						"<wfs:GetFeature service=\"WFS\" version=\"" . $version . "\" " .
+						"xmlns:wfs=\"http://www.opengis.net/wfs\" " .
+						"xmlns:gml=\"http://www.opengis.net/gml\" " .
+						"xmlns:ogc=\"http://www.opengis.net/ogc\" " .
+						"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " .
+						"xsi:schemaLocation=\"http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd\"";
+				if (isset($outputFormat) && $outputFormat != '') {
+					$postData .= "outputFormat=\"".$outputFormat."\" "; //tag ends later
+				} else {
+					$postData .= ">";
+				}
 			}
+			$postData .="<wfs:Query ";
+			if($destSrs) {
+				$postData .= "srsName=\"" . $srsName . "\" ";
+			}
+			//add namespace
+			if (strpos($featureTypeName, ":") !== false) {
+				$ft = $this->findFeatureTypeByName($featureTypeName);
+				$ns = $this->getNamespace($featureTypeName);
+				$url = $ft->getNamespace($ns);
+				$postData .= "xmlns:" . $ns . "=\"" . $url . "\" ";	
+			}
+			$postData .= $typeNameParameterName."=\"" . $featureTypeName . "\"  >";
+			$postData .= $filter ."</wfs:Query>";
+			$postData .= "</wfs:GetFeature>";		
+			$resultOfCount = $this->post($this->getFeature, $postData); //from class_ows!
+                	break;
+		    case "GET":
+			$url = $this->getFeature.$this->getConjunctionCharacter($this->getFeature)."service=WFS&request=GetFeature&version=".$version."&".strtolower($typeNameParameterName)."=".$featureTypeName."&resultType=hits";
+			if ($filter != null) {
+			    $url .= "&FILTER=".urlencode($filter);
+			}
+			//auth is already integrated in ows class
+			//do request
+			$resultOfCount = $this->get($url); //from class_ows!
+			break;
 		}
-		$postData .="<wfs:Query ";
-		if($destSrs) {
-			$postData .= "srsName=\"" . $srsName . "\" ";
-		}
-		//add namespace
-		if (strpos($featureTypeName, ":") !== false) {
-			$ft = $this->findFeatureTypeByName($featureTypeName);
-			$ns = $this->getNamespace($featureTypeName);
-			$url = $ft->getNamespace($ns);
-			$postData .= "xmlns:" . $ns . "=\"" . $url . "\" ";	
-		}
-		$postData .= $typeNameParameterName."=\"" . $featureTypeName . "\"  >";
-		$postData .= $filter ."</wfs:Query>";
-		$postData .= "</wfs:GetFeature>";
-			
-		//$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!
-//$e = new mb_exception("classes/class_wfs.php: getFeaturePostPaging: postdata: ".$postData);		
-		$resultOfCount = $this->post($this->getFeature, $postData); //from class_ows!
-		/*$url = $this->getFeature .
-		$this->getConjunctionCharacter($this->getFeature) . 
-		"service=WFS&request=GetFeature&version=" . 
-		$version . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
-
-		if ($filter != null) {
-			$url .= "&FILTER=".urlencode($filter);
-			//$url .= "&FILTER=".$filter;
-		}
-		//auth is already integrated in ows class
-		//do request
-		$resultOfCount = $this->get($url); //from class_ows!*/
-		//check or exception - if it 
+//$e = new mb_exception($url);
+//$e = new mb_exception($resultOfCount);
 		try {
 			$exceptionTest =  new SimpleXMLElement($resultOfCount);
 			if ($exceptionTest == false) {
@@ -743,7 +648,7 @@
 				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberOfFeatures');
 				break;
 		}
-/*
+/* example 
 <?xml version='1.0' encoding='UTF-8'?>
 <wfs:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:wfs="http://www.opengis.net/wfs" timeStamp="2019-07-23T08:07:26Z" numberOfFeatures="183">
 </wfs:FeatureCollection>

Modified: trunk/mapbender/http/php/mod_linkedDataProxy.php
===================================================================
--- trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-14 16:42:51 UTC (rev 10211)
+++ trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-15 15:13:03 UTC (rev 10212)
@@ -5,9 +5,12 @@
 require_once(dirname(__FILE__)."/../classes/class_gml_3_factory.php");
 require_once(dirname(__FILE__)."/../classes/class_owsConstraints.php");
 require_once(dirname(__FILE__)."/../classes/class_connector.php");//for resolving external @context content
+ini_set('memory_limit', '2000M');
+$wfs_http_method="GET";
+//$startmem = memory_get_usage();
 //http://localhost/mapbender/devel_tests/wfsClientTest.php?wfsid=16&ft=vermkv:fluren_rlp&bbox=7.9,50.8,8.0,52
 //initialize some parameter
-$limit = 20;
+$limit = 5;
 //objects per page
 //$maxObjectsPerPage = 10;
 //default page
@@ -30,7 +33,7 @@
 $maxyFC = 9;
 //	
 $newline = "\n";
-$allowedLimits = array("1","5","10","20","50","100");
+$allowedLimits = array("1","5","10","20","50","100","200");
 function microtime_float() {
     	list($usec, $sec) = explode(" ", microtime());
     	return ((float)$usec + (float)$sec);
@@ -497,8 +500,7 @@
 		        if ($cache->isActive) {
 		        //if (false) {
 		            if ($cache->cachedVariableExists(md5("count_".$wfsid."_".$collection."_".md5($filter))) == false) {
-		                //$numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
-				$numberOfObjects = $wfs->countFeaturesPost($collection, $filter, false, "2.0.0", false);
+				$numberOfObjects = $wfs->countFeatures($collection, $filter, "EPSG:4326", "2.0.0", false, $wfs_http_method);
 		                $cache->cachedVariableAdd(md5("count_".$wfsid."_".$collection."_".md5($filter)), $numberOfObjects);
 		            } else {
 //$e = new mb_exception("read count from cache!");
@@ -507,8 +509,9 @@
 		            //$e = new mb_notice("http/classes/class_crs.php - store crs info to cache!");
 		            //return true;
 		        } else {
+			    //TODO - define post/get central
 		            //$numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
-			    $numberOfObjects = $wfs->countFeaturesPost($collection, $filter, false, "2.0.0", false);
+			    $numberOfObjects = $wfs->countFeatures($collection, $filter, "EPSG:4326", "2.0.0", false, $wfs_http_method);
 		        }
 //$numberOfObjects = 1000;
 //$e = new mb_exception("counted features: ".$numberOfObjects);
@@ -565,7 +568,7 @@
 			//check if outputformat geojson is available - if - gml don't need to be parsed!!!!! TODO - where to become hits ????? - has to count in a special request!!!!!
 			if (in_array('application/json; subtype=geojson', explode(',', $ftOutputFormats)) && $nativeJson == true) {
 			//if (false) {
-			    $features = $wfs->getFeaturePaging($ftName, $filter, "EPSG:4326", null, null, $limit, $startIndex, "2.0.0", 'application/json; subtype=geojson');
+			    $features = $wfs->getFeaturePaging($ftName, $filter, "EPSG:4326", null, null, $limit, $startIndex, "2.0.0", 'application/json; subtype=geojson', $wfs_http_method);
 			    $geojsonList = json_decode($features);
 			    $geojsonBbox = array();
 			    $geojsonIndex = 0;
@@ -666,13 +669,18 @@
 			    echo $features;
 			    die();*/
 			} else {
-			    $features = $wfs->getFeaturePaging($ftName, $filter, "EPSG:4326", null, null, $limit, $startIndex, "2.0.0");
+//$e = new mb_exception($filter);
+			    $features = $wfs->getFeaturePaging($ftName, $filter, "EPSG:4326", null, null, $limit, $startIndex, "2.0.0", false, $wfs_http_method);
 			    //transform to geojson to allow rendering !
 			    $gml3Class = new Gml_3_Factory();
 			    //create featuretype object
 			    //TODO
-	//$e = new mb_exception("geom column type: ".$geomColumnName);	
+	//$e = new mb_exception("geom column type: ".$geomColumnName);
+
+//$memBeforeGmlParsing = memory_get_usage();
+//$e = new mb_exception("Memory before GML Object: ".((memory_get_usage() - $startmem) / 1000)." MB");
 			    $gml3Object = $gml3Class->createFromXml($features, null, $wfs, $myFeatureType, $geomColumnName);
+//$e = new mb_exception("Memory for GML Object: ".((memory_get_usage() - $memBeforeGmlParsing) / 1000)." MB");
 	//$e = new mb_exception("geojson from mb class: ".json_encode($gml3Object));
 			    $geojsonList = new stdClass();
 			    $geojsonList->type = "FeatureCollection";
@@ -688,10 +696,20 @@
 				$geoJsonVariable = "";
 				$geoJsonVariable = '<script>'.$newline;
 			    }
+//$e = new mb_exception("size of gml3Object: ".);
 			    foreach($gml3Object->featureCollection->featureArray as $mbFeature) {
-//$e = new mb_exception("geojson from mb feature exporthandler: ".$mbFeature->toGeoJSON());
+//$e = new mb_exception("geojson from mb feature exporthandler: ".json_encode($mbFeature));
+//$e = new mb_exception("geoJson object no.: ".$geojsonIndex." - current Memory usage: ".((memory_get_usage() - $startmem) / 1000)." MB");
 			        //bbox
-			        $geojsonBbox[$geojsonIndex]->mbBbox = $mbFeature->getBbox();
+				try {
+			            $geojsonBbox[$geojsonIndex]->mbBbox = $mbFeature->getBbox();
+//$e = new mb_exception('bbox: '.$geojsonBbox[$geojsonIndex]->mbBbox);
+				}
+				catch (Exception $e) {
+					$e = new mb_exception('Problem to resolve bbox from gml - set to default values!', $e->getMessage());
+					$geojsonBbox[$geojsonIndex]->mbBbox = "[(".$minxFC.",".$minyFC.",,urn:ogc:def:crs:EPSG::4326)(".$maxxFC.",".$maxyFC.",,urn:ogc:def:crs:EPSG::4326) urn:ogc:def:crs:EPSG::4326]";
+				}
+//$e = new mb_exception('bbox: '.$geojsonBbox[$geojsonIndex]->mbBbox);
 			        //transform to simple bbox object for leaflet
 				$bbox_new = explode(' ',str_replace(']','',str_replace('[','',$geojsonBbox[$geojsonIndex]->mbBbox)));
 				$bbox_new = explode('|',str_replace(')','',str_replace('(','',str_replace(')(','|',$bbox_new[0]))));
@@ -716,6 +734,8 @@
 				//get geomtype
 				$geomType = json_decode($mbFeature->toGeoJSON())->geometry->type;
 				$geojsonList->features[] = json_decode($mbFeature->toGeoJSON());
+				//free memory
+				unset($gml3Object->featureCollection->featureArray[$geojsonIndex]);
 				$geojsonIndex++;
 			    }
 			}
@@ -1054,19 +1074,19 @@
             $html .= '</ol>';
 	} else {
 	    if (!isset($collection) || $collections == 'all') {
-	        $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","wfsid"), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
+	        $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array("f","wfsid","nativeJson"), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
                 $html .= '<li class="breadcrumb-item active">'.$returnObject->title.'</li>'.$newline;
                 $html .= '</ol>';
 	    } else {
 		if (!isset($item) || $items == 'all') {
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
-                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox","nativeJson"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
+                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox","nativeJson"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
                     $html .= '<li class="breadcrumb-item active">'.$returnObject->collectionTitle.'</li>'.$newline;
                     $html .= '</ol>';
 		} else {
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
-                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
-		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","item","limit","offset","bbox"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'&items=all'.'">'.$returnObject->collectionTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","wfsid","collection","collections","item","items","limit","offset","bbox","nativeJson"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">Datasets</a></li>'.$newline; //TODO - use base uri
+                    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","collection","collections","item","items","limit","offset","bbox","nativeJson"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'">'.$returnObject->serviceTitle.'</a></li>'.$newline;
+		    $html .= '<li class="breadcrumb-item"><a href="'.rtrim(delTotalFromQuery(array_merge(array("f","item","limit","offset","bbox","nativeJson"), $stringFilterActive), $_SERVER['REQUEST_URI']),'?').'&items=all'.'">'.$returnObject->collectionTitle.'</a></li>'.$newline;
                     $html .= '<li class="breadcrumb-item active">'.$returnObject->id.'</li>'.$newline;
                     $html .= '</ol>';
 		}
@@ -1216,10 +1236,13 @@
 		    $html .= '<div id="app-wrapper" class="mb-5">'.$newline;
 		    $html .= '<div class="row mb-3">'.$newline;
 		    $html .= '<div class=" flex-row justify-content-start align-items-center flex-wrap col-md-3">'.$newline;
-		    $html .= '<span class="mr-2 font-weight-bold">Filter</span>';
+		    $html .= '<span class="mr-2 font-weight-bold">Filter</span>'.$newline;
 		    if (isset($bbox) && $bbox != "") {
 		        $html .= '<div class="mr-1 my-1 btn-group"><button disabled="" style="opacity: 1;" class="py-0 btn btn-primary btn-sm disabled">bbox≈'.$bbox.'</button><button type="button" aria-haspopup="true" aria-expanded="false" class="py-0 btn btn-danger btn-sm" onclick="location.href = URL_remove_parameter(URL_remove_parameter(location.href, \'bbox\'), \'offset\');return false;">×</button></div>'.$newline;
 		    }
+		    if (isset($nativeJson) && $nativeJson == true) {
+		        $html .= '<div class="mr-1 my-1 btn-group"><button disabled="" style="opacity: 1;" class="py-0 btn btn-primary btn-sm disabled">nativeJson=true</button><button type="button" aria-haspopup="true" aria-expanded="false" class="py-0 btn btn-danger btn-sm" onclick="location.href = URL_remove_parameter(location.href, \'nativeJson\');return false;">×</button></div>'.$newline;
+		    }
 		    //for each other set parameter show***********************************************
 		    //variable with parameters:
 		    foreach($stringFilterArray as $stringFilter) {
@@ -1233,7 +1256,28 @@
 		    $html .= '<button type="button" id="cancel_filter_button" class="py-0 btn btn-outline-secondary btn-sm collapse" onclick="var elements = [\'edit_filter_button\', \'cancel_filter_button\', \'filter_div\']; elements.forEach(myFunction); function myFunction(item) { var element = document.getElementById(item);element.classList.toggle(\'show\'); };">Cancel</button>'.$newline;
 		    //bbox filter part from ldproxy
 		    $html .= '<div id="filter_div" class="collapse">'.$newline;
+		    //nativeJson Filter - to use if some memory error occur - 
+if (in_array('application/json; subtype=geojson', explode(',', $ftOutputFormats))) {
 		    $html .= '    <form class="">'.$newline;
+		    $html .= '        <p class="text-muted text-uppercase" title="Use nativeJson if errors occur - it may also be faster, but the objects don\'t have persistent IDs!">Serverside format</p>'.$newline;
+		    $html .= '		    <div class="col-md-2">'.$newline;
+		    $html .= '			<button type="button" class="btn btn-primary btn-sm" onclick="location.href = URL_add_parameter(location.href, \'nativeJson\', \'true\');return false;">geoJson</button>'.$newline;
+		    $html .= '		    </div>'.$newline;
+		    $html .= '	    </form>'.$newline;
+}
+		    //paging options
+		    //allowedLimits
+	            $html .= '    <form class="">'.$newline;
+		    $html .= '        <p class="text-muted text-uppercase">Results per page</p>'.$newline;
+		    $html .= '                <select id="rppSelection" name="field" type="select" class="mr-2 text-muted form-control-sm form-control" onchange="location.href = URL_add_parameter(location.href, \'limit\', document.getElementById(\'rppSelection\').value);">'.$newline;
+		    $html .= '                    <option value="" class="d-none">'.$limit.'</option>'.$newline;
+		    foreach($allowedLimits as $rpp) {
+			$html .= '                    <option value="'.$rpp.'">'.$rpp.'</option>'.$newline;
+		    }
+		    $html .= '               </select>'.$newline;
+		    $html .= '	    </form>'.$newline;
+		    //
+		    $html .= '    <form class="">'.$newline;
 		    $html .= '        <p class="text-muted text-uppercase">bbox</p>'.$newline;
 		    $html .= '		<div class="row">'.$newline;
 		    $html .= '		    <div class="col-md-5">'.$newline;
@@ -1264,78 +1308,77 @@
 		    $html .= '          </div>'.$newline;
 		    $html .= '	    </form>'.$newline;
 		    if (is_array($ftAllowedAttributesArray) && count($ftAllowedAttributesArray) > 0) {
-$html .= '<form class="">'.$newline;
-$html .= '    <p class="text-muted text-uppercase">field</p>'.$newline;
-$html .= '    <div class="row">'.$newline;
-$html .= '        <div class="col-md-5">'.$newline;
-$html .= '            <div class="form-group">'.$newline;
-$html .= '                <select id="attributeSelection" name="field" type="select" class="mr-2 text-muted form-control-sm form-control" onchange="document.getElementById(\'filterValue\').value = \'\';">'.$newline;
-$html .= '                    <option value="" class="d-none">none</option>'.$newline;
-foreach($ftAllowedAttributesArray as $ftAllowedAttribute) {
-$html .= '                    <option value="'.$ftAllowedAttribute.'">'.$ftAllowedAttribute.'</option>'.$newline;
-}
-$html .= '               </select>'.$newline;
-$html .= '            </div>'.$newline;
-$html .= '        </div>'.$newline;
-$html .= '        <div class="col-md-5">'.$newline;
-$html .= '            <div class="form-group">'.$newline;
-$html .= '                <input id="filterValue" name="filterValue" placeholder="filter pattern" class="mr-2 form-control-sm form-control" value="" type="text">'.$newline;
-$html .= '                    <small class="form-text text-muted">Use * as wildcard</small>'.$newline;
-$html .= '                    <small class="form-text text-muted" id="filterNameErrMsg"></small>'.$newline;
-$html .= '            </div>'.$newline;
-$html .= '        </div>'.$newline;
-$html .= '        <div class="col-md-2">'.$newline;
-$html .= '            <button id="filterValueAddButton" name="filterValueAddButton" type="button" disabled="" class="btn btn-primary btn-sm disabled" onclick="var attributeSelection = document.getElementById(\'attributeSelection\'); var filterValue = document.getElementById(\'filterValue\'); var selectionValue = attributeSelection.options[attributeSelection.selectedIndex].value; location.href = URL_add_parameter(URL_remove_parameter(location.href, \'p\'), selectionValue, filterValue.value );return false;">Add</button>'.$newline;
-$html .= '        </div>'.$newline;
-$html .= '    </div>'.$newline;
-
-//add script
-$html .= '<script>';
-$html .= 'const filterValue = document.getElementById(\'filterValue\');';
-$html .= 'const filterErrMsgHolder = document.getElementById(\'filterNameErrMsg\');';
-$html .= 'const filterValueAddButton = document.getElementById(\'filterValueAddButton\');';
-$html .= 'const attributeSelection = document.getElementById(\'attributeSelection\');';
-$html .= 'function checkFilterValue() {';
-$html .= 'var inputValue = filterValue.value;';
-$html .= '    if (attributeSelection.options[attributeSelection.selectedIndex].value == "") {';
-$html .= '        filterErrMsgHolder.innerHTML =';
-$html .= '            \'Please select an attribute on the left side before setting the filter value\';';
-$html .= '        return false;';
-$html .= '    } else if (inputValue.length < 1) {';
-$html .= '        filterErrMsgHolder.innerHTML =';
-$html .= '            \'Please enter a text with at least 1 letters\';';
-$html .= '        return false;';
-$html .= '    } else if (!(/^\S{1,}$/.test(inputValue))) {';
-$html .= '        filterErrMsgHolder.innerHTML =';
-$html .= '            \'Name cannot contain whitespace\';';
-$html .= '        return false;';
-$html .= '    } else if(!(/^[a-zA-Z*0-9\-]+$/.test(inputValue)))';
-$html .= '    {';
-$html .= '       filterErrMsgHolder.innerHTML=';
-$html .= '                \'Only alphabets or * are allowed\'';
-$html .= '    }';
-//$html .= '    else if(!(/^(?:(\w)(?!\1\1))+$/.test(inputValue)))';
-//$html .= '    {';
-//$html .= '        filterErrMsgHolder.innerHTML=';
-//$html .= '                \'per 3 alphabets allowed\'';
-//$html .= '   }';
-$html .= '    else {';
-$html .= '        filterErrMsgHolder.innerHTML = \'\';';
-$html .= '        return true;';
-$html .= '    }       ';
-$html .= '}';
-$html .= 'filterValue.addEventListener(\'keyup\', function (event) {';
-$html .= '    isValidFilter = checkFilterValue();';
-$html .= '    if ( isValidFilter && attributeSelection.options[attributeSelection.selectedIndex].value != "") {';
-$html .= '        filterValueAddButton.classList.remove("disabled");';
-$html .= '        filterValueAddButton.disabled = false;';
-$html .= '    } else {';
-//$html .= '        filterValueAddButton.classList.add("disabled");';
-$html .= '        filterValueAddButton.disabled = true;';
-$html .= '   }';
-$html .= '});';
-$html .= '</script>';
-$html .= '</form>'.$newline;
+			$html .= '<form class="">'.$newline;
+			$html .= '    <p class="text-muted text-uppercase">field</p>'.$newline;
+			$html .= '    <div class="row">'.$newline;
+			$html .= '        <div class="col-md-5">'.$newline;
+			$html .= '            <div class="form-group">'.$newline;
+			$html .= '                <select id="attributeSelection" name="field" type="select" class="mr-2 text-muted form-control-sm form-control" onchange="document.getElementById(\'filterValue\').value = \'\';">'.$newline;
+			$html .= '                    <option value="" class="d-none">none</option>'.$newline;
+			foreach($ftAllowedAttributesArray as $ftAllowedAttribute) {
+			    $html .= '                    <option value="'.$ftAllowedAttribute.'">'.$ftAllowedAttribute.'</option>'.$newline;
+			}
+			$html .= '               </select>'.$newline;
+			$html .= '            </div>'.$newline;
+			$html .= '        </div>'.$newline;
+			$html .= '        <div class="col-md-5">'.$newline;
+			$html .= '            <div class="form-group">'.$newline;
+			$html .= '                <input id="filterValue" name="filterValue" placeholder="filter pattern" class="mr-2 form-control-sm form-control" value="" type="text">'.$newline;
+			$html .= '                    <small class="form-text text-muted">Use * as wildcard</small>'.$newline;
+			$html .= '                    <small class="form-text text-muted" id="filterNameErrMsg"></small>'.$newline;
+			$html .= '            </div>'.$newline;
+			$html .= '        </div>'.$newline;
+			$html .= '        <div class="col-md-2">'.$newline;
+			$html .= '            <button id="filterValueAddButton" name="filterValueAddButton" type="button" disabled="" class="btn btn-primary btn-sm disabled" onclick="var attributeSelection = document.getElementById(\'attributeSelection\'); var filterValue = document.getElementById(\'filterValue\'); var selectionValue = attributeSelection.options[attributeSelection.selectedIndex].value; location.href = URL_add_parameter(URL_remove_parameter(location.href, \'p\'), selectionValue, filterValue.value );return false;">Add</button>'.$newline;
+			$html .= '        </div>'.$newline;
+			$html .= '    </div>'.$newline;
+			//add script
+			$html .= '<script>';
+			$html .= 'const filterValue = document.getElementById(\'filterValue\');';
+			$html .= 'const filterErrMsgHolder = document.getElementById(\'filterNameErrMsg\');';
+			$html .= 'const filterValueAddButton = document.getElementById(\'filterValueAddButton\');';
+			$html .= 'const attributeSelection = document.getElementById(\'attributeSelection\');';
+			$html .= 'function checkFilterValue() {';
+			$html .= 'var inputValue = filterValue.value;';
+			$html .= '    if (attributeSelection.options[attributeSelection.selectedIndex].value == "") {';
+			$html .= '        filterErrMsgHolder.innerHTML =';
+			$html .= '            \'Please select an attribute on the left side before setting the filter value\';';
+			$html .= '        return false;';
+			$html .= '    } else if (inputValue.length < 1) {';
+			$html .= '        filterErrMsgHolder.innerHTML =';
+			$html .= '            \'Please enter a text with at least 1 letters\';';
+			$html .= '        return false;';
+			$html .= '    } else if (!(/^\S{1,}$/.test(inputValue))) {';
+			$html .= '        filterErrMsgHolder.innerHTML =';
+			$html .= '            \'Name cannot contain whitespace\';';
+			$html .= '        return false;';
+			$html .= '    } else if(!(/^[a-zA-Z*0-9\-]+$/.test(inputValue)))';
+			$html .= '    {';
+			$html .= '       filterErrMsgHolder.innerHTML=';
+			$html .= '                \'Only alphabets or * are allowed\'';
+			$html .= '    }';
+			//$html .= '    else if(!(/^(?:(\w)(?!\1\1))+$/.test(inputValue)))';
+			//$html .= '    {';
+			//$html .= '        filterErrMsgHolder.innerHTML=';
+			//$html .= '                \'per 3 alphabets allowed\'';
+			//$html .= '   }';
+			$html .= '    else {';
+			$html .= '        filterErrMsgHolder.innerHTML = \'\';';
+			$html .= '        return true;';
+			$html .= '    }       ';
+			$html .= '}';
+			$html .= 'filterValue.addEventListener(\'keyup\', function (event) {';
+			$html .= '    isValidFilter = checkFilterValue();';
+			$html .= '    if ( isValidFilter && attributeSelection.options[attributeSelection.selectedIndex].value != "") {';
+			$html .= '        filterValueAddButton.classList.remove("disabled");';
+			$html .= '        filterValueAddButton.disabled = false;';
+			$html .= '    } else {';
+			//$html .= '        filterValueAddButton.classList.add("disabled");';
+			$html .= '        filterValueAddButton.disabled = true;';
+			$html .= '   }';
+			$html .= '});';
+			$html .= '</script>';
+			$html .= '</form>'.$newline;
 		    }
 		    $html .= '</div>'.$newline;
 		    $html .= '</div>'.$newline;



More information about the Mapbender_commits mailing list