[Mapbender-commits] r10185 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jul 24 05:37:47 PDT 2019
Author: armin11
Date: 2019-07-24 05:37:47 -0700 (Wed, 24 Jul 2019)
New Revision: 10185
Modified:
trunk/mapbender/http/classes/class_wfs.php
Log:
Some new options to support the generation of a wfs proxy for wfs 3.0 and lod things
Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php 2019-07-15 07:02:06 UTC (rev 10184)
+++ trunk/mapbender/http/classes/class_wfs.php 2019-07-24 12:37:47 UTC (rev 10185)
@@ -27,7 +27,8 @@
/**
* An abstract Web Feature Service (WFS) class, modelling for example
- * WFS 1.0.0, WFS 1.1.0 or WFS 2.0.0
+ * WFS 1.0.0, WFS 1.1.0, WFS 2.0.0, WFS 2.0.2
+ * To instantiate a wfs object, use universal_wfs_factory class instead!
*/
abstract class Wfs extends Ows {
var $describeFeatureType;
@@ -220,7 +221,7 @@
}
}
}
-
+
public function getFeature ($featureTypeName, $filter, $destSrs=null, $storedQueryId=null, $storedQueryParams=null, $maxFeatures=null) {
// FOR NOW, WE ONLY DO POST REQUESTS!
@@ -233,6 +234,171 @@
// }
// return $this->getFeatureGet($featureTypeName, $filter);
}
+
+ public function getFeaturePaging ($featureTypeName, $filter, $destSrs=null, $storedQueryId=null, $storedQueryParams=null, $maxFeatures=null, $startIndex=null) {
+
+// 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);
+// }
+// return $this->getFeatureGet($featureTypeName, $filter);
+ }
+
+ protected function getFeaturePostPaging ($featureTypeName, $filter, $destSrs, $storedQueryId, $storedQueryParams, $maxFeatures, $startIndex) {
+ //maxfeatures - in newer versions count is used - for paging
+ switch ($this->getVersion()) {
+ 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($storedQueryId && $storedQueryId != "") {
+ $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+ "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "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\">";
+ $postData .= "<wfs:StoredQuery id=\"" . $storedQueryId . "\">";
+ $postData .= $storedQueryParams;
+ $postData .= "</wfs:StoredQuery>";
+ }
+ else {
+ if($this->getVersion() == "2.0.0" || $this->getVersion() == "2.0.2") {
+ $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+ "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "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\" ".
+ "startIndex=\"".$startIndex."\" count=\"".$maxFeatures."\" >";
+ }
+ //TODO: not already implemented - maybe usefull for older geoserver/mapserver implementations
+ else if($this->getVersion() == "1.1.0") {
+ $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+ "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "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\">";
+ }
+ else {
+ $postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
+ "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "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.0.0/WFS-basic.xsd\">";
+ }
+ $postData .="<wfs:Query ";
+ if($destSrs) {
+ $postData .= "srsName=\"" . $destSrs . "\" ";
+ }
+ // add namespace
+ if (strpos($featureTypeName, ":") !== false) {
+ $ft = $this->findFeatureTypeByName($featureTypeName);
+ $ns = $this->getNamespace($featureTypeName);
+ $url = $ft->getNamespace($ns);
+ $postData .= "xmlns:" . $ns . "=\"" . $url . "\" ";
+ }
+ if($this->getVersion() == "2.0.0" || $this->getVersion() == "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 . "\">" .
+ $filter .
+ "</wfs:Query>";
+ }
+ $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 get request
+ $getRequest = $this->getFeature.""."SERVICE=wfs&VERSION=".$this->getVersion()."&REQUEST=GetFeature"."&".$typeNameParameterName."=".$featureTypeName."&".$maxFeaturesParameterName."=".$maxFeatures."&STARTINDEX=".$startIndex."&".$maxFeaturesParameterName."=".$maxFeatures;
+ return $this->get($getRequest);
+ //other variants
+ //return $this->post($this->getFeature.$maxFeaturesParameterName."=".$maxFeatures."&STARTINDEX=".$startIndex, $postData); //from class_ows!
+ //return $this->post($this->getFeature, $postData); //from class_ows!
+ }
+
+ public function countFeatures($featureTypeName) {
+ switch ($this->getVersion()) {
+ 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 ($this->getVersion() == "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=" .
+ $this->getVersion() . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
+ //$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!
+ //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 ($this->getVersion()) {
+ 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).
@@ -380,7 +546,30 @@
"</wfs:Update>";
}
- protected function getFeatureIdFilter ($fid) {
+ public function getFeatureById ($featureTypeName, $outputFormat=false, $id) {
+ switch ($this->getVersion()) {
+ case "2.0.2":
+ $typeNameParameterName = "typeNames";
+ $maxFeaturesParameterName = "COUNT";
+ $featureIdParameterName = "featureID";
+ break;
+ case "2.0.0":
+ $typeNameParameterName = "typeNames";
+ $maxFeaturesParameterName = "COUNT";
+ $featureIdParameterName = "featureID";
+ break;
+ default:
+ $typeNameParameterName = "typeName";
+ $maxFeaturesParameterName = "MAXFEATURES";
+ $featureIdParameterName = "featureID";
+ break;
+ }
+ $url = $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!
}
protected function transactionDelete ($feature, $featureType, $authWfsConfElement) {
More information about the Mapbender_commits
mailing list