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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Aug 14 09:40:55 PDT 2019


Author: armin11
Date: 2019-08-14 09:40:55 -0700 (Wed, 14 Aug 2019)
New Revision: 10210

Modified:
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/php/mod_linkedDataProxy.php
Log:
New options - use post for counting features

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2019-08-14 14:09:57 UTC (rev 10209)
+++ trunk/mapbender/http/classes/class_wfs.php	2019-08-14 16:40:55 UTC (rev 10210)
@@ -561,14 +561,16 @@
 			$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;
 		}
-//$e = new mb_exception("class_wfs.php: getFeatureGet: ".$url);
 		//auth is already integrated in ows class
 		//do request
 		$resultOfCount = $this->get($url); //from class_ows!
@@ -601,6 +603,153 @@
 		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);
+			$alterAxisOrder = $crs->alterAxisOrder("wfs_".$version);
+			$srsId = $crs->identifierCode;
+			//add srs to request
+		}
+		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;
+		}
+		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" .
+					"<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>";
+			
+		//$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 
+		try {
+			$exceptionTest =  new SimpleXMLElement($resultOfCount);
+			if ($exceptionTest == false) {
+				throw new Exception('Cannot parse WFS number of hits request!');
+				return false;
+			}
+		}
+		catch (Exception $e) {
+    			$e = new mb_exception($e->getMessage());
+		}
+		switch ($version) {
+			case "2.0.0":
+				$errorMessage = $exceptionTest->xpath('/ows:ExceptionReport/ows:Exception/ows:ExceptionText');
+				break;
+			default:
+				$errorMessage = $exceptionTest->xpath('/ows:ExceptionReport/ows:Exception/ows:ExceptionText');
+				break;
+		}
+		if (isset($errorMessage[0])) {
+			$e = new mb_exception($errorMessage[0]);
+			return false;
+		}
+		//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];
+	}
 	
 	/**
 	 * Performs a WFS transaction (delete, update or insert).

Modified: trunk/mapbender/http/php/mod_linkedDataProxy.php
===================================================================
--- trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-14 14:09:57 UTC (rev 10209)
+++ trunk/mapbender/http/php/mod_linkedDataProxy.php	2019-08-14 16:40:55 UTC (rev 10210)
@@ -442,7 +442,7 @@
       </fes:PropertyIsLike>
 */
 //TODO allow combination of different text filters!!!! - Not all wfs support this ?
-			    if (true) {
+			    if (false) {
 				if (strpos($stringFilterArray[0]->elementFilter, "*") !== false) {
 				    $textFilter .= '<fes:PropertyIsLike wildCard="*" singleChar="." escapeChar="\">';
 				    $textFilter .= '<fes:ValueReference>'.$stringFilterArray[0]->elementName.'</fes:ValueReference>';
@@ -473,7 +473,7 @@
 					$textFilterIndex++;
 				    }
 				    if (count($textFilterArray) > 1) { //bbox is set
-					$textFilter = '<fes:And>'.implode('', $textFilterArray).'<fes:/And>';
+					$textFilter = '<fes:And>'.implode('', $textFilterArray).'</fes:And>';
 				    } else {
 					$textFilter = implode('', $textFilterArray);
 				    }
@@ -494,10 +494,11 @@
 //test
 //$e = new mb_exception("filter: ".$filter);
 		        //write number of features to ram cache:
-		        if ($cache->isActive) {
-		        //if (false) {
+		        //if ($cache->isActive) {
+		        if (false) {
 		            if ($cache->cachedVariableExists(md5("count_".$wfsid."_".$collection."_".md5($filter))) == false) {
-		                $numberOfObjects = $wfs->countFeatures($collection, $filter);
+		                //$numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
+				$numberOfObjects = $wfs->countFeaturesPost($collection, $filter, false, "2.0.0", false);
 		                $cache->cachedVariableAdd(md5("count_".$wfsid."_".$collection."_".md5($filter)), $numberOfObjects);
 		            } else {
 //$e = new mb_exception("read count from cache!");
@@ -506,9 +507,20 @@
 		            //$e = new mb_notice("http/classes/class_crs.php - store crs info to cache!");
 		            //return true;
 		        } else {
-		            $numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
+		            //$numberOfObjects = $wfs->countFeatures($collection, $filter, "2.0.0");
+			    $numberOfObjects = $wfs->countFeaturesPost($collection, $filter, false, "2.0.0", false);
 		        }
+//$numberOfObjects = 1000;
 //$e = new mb_exception("counted features: ".$numberOfObjects);
+			if ($numberOfObjects == 0 || $numberOfObjects == false) {
+			    $returnObject->success = false;
+    			    $returnObject->message = "No results found or an error occured - see server logs - please try it again! Use the back button!";
+			    //if ($f == "json") {
+			        header("application/json");
+			        echo json_encode($returnObject);
+			    //}	
+		            die();
+			}
 			//$e = new mb_exception("number of objects: ".$numberOfObjects);
 		        //request first object and metadata
 		        //count objects
@@ -1297,7 +1309,7 @@
 $html .= '        filterErrMsgHolder.innerHTML =';
 $html .= '            \'Name cannot contain whitespace\';';
 $html .= '        return false;';
-$html .= '    } else if(!(/^[a-zA-Z*0-9]+$/.test(inputValue)))';
+$html .= '    } else if(!(/^[a-zA-Z*0-9\-]+$/.test(inputValue)))';
 $html .= '    {';
 $html .= '       filterErrMsgHolder.innerHTML=';
 $html .= '                \'Only alphabets or * are allowed\'';



More information about the Mapbender_commits mailing list