[Mapbender-commits] r10189 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jul 31 00:01:29 PDT 2019
Author: armin11
Date: 2019-07-31 00:01:29 -0700 (Wed, 31 Jul 2019)
New Revision: 10189
Modified:
trunk/mapbender/http/classes/class_wfs.php
Log:
Better WFS 3.0 linked data proxy - to be enhanced ;-)
Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php 2019-07-29 13:41:26 UTC (rev 10188)
+++ trunk/mapbender/http/classes/class_wfs.php 2019-07-31 07:01:29 UTC (rev 10189)
@@ -262,30 +262,175 @@
// 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!
+ /*
+
+ */
+ $bboxArray = explode(',', $bbox);
+ $bboxArrayNew = array();
+ foreach ($bboxArray as $coord) {
+ if (strpos($coord,'.') !== false) {
+ $coordArray = explode('.',$coord);
+ $countDigits = (16 - strlen($coordArray[1]));
+ //$e = new mb_exception("coord array[1]: ".$coordArray[1]." - digits to add: ".$countDigits);
+ //add zeros to coord
+ $coord .= str_repeat("0", $countDigits);
+ } else {
+ $coord .= ".0000000000000000";
+ }
+ //alter last digits to 42
+ $coord = substr($coord, 0, -2).'42';
+ $bboxArrayNew[] = $coord;
+//$e = new mb_exception("classes/class_wfs.php: ccord: ".$coord." float: ".round(floatval($coord),10));
+ }
+ $bboxArray = $bboxArrayNew;
+ $crs = new Crs($srs);
+ $alterAxisOrder = $crs->alterAxisOrder("wfs_".$version);
+ if ($alterAxisOrder == true) {
+ //switch from geojson to lat/long - north/east
+ $bboxArrayNew[0] = $bboxArray[1];
+ $bboxArrayNew[1] = $bboxArray[0];
+ $bboxArrayNew[2] = $bboxArray[3];
+ $bboxArrayNew[3] = $bboxArray[2];
+ $bboxArray = $bboxArrayNew;
+ }
+ $srsId = $crs->identifierCode;
+ //add srs to request
+ switch ($version) {
+ case "2.0.2":
+ $targetSrs = "http://www.opengis.net/def/crs/EPSG/0/".$srsId;
+ break;
+ case "2.0.0":
+ $targetSrs = "urn:ogc:def:crs:EPSG::".$srsId;
+ //$targetSrs = "EPSG:".$srsId; - for mapserver?
+ break;
+ case "1.1.0":
+ $targetSrs = "urn:ogc:def:crs:EPSG::".$srsId;
+ break;
+ case "1.0.0":
+ $targetSrs = "EPSG:".$srsId;
+ break;
+ }
+ if ($version == false) {
+ $version = $this->getVersion();
+ } else {
+ $e = new mb_notice("classes/class_wfs.php: wfs version for generating spatial filter forced to ".$version."!");
+ }
+ $crs = new Crs($srs);
+ //geosjon have always long/lat
+ $srsId = $crs->identifierCode;
+ $spatialFilter = "";
+ switch($version) {
+ case "2.0.0":
+ //gml2 depends on the namespace in fes:Filter - gml2 and gml3 are possible - we use gml3!
+/*
+ <fes:Filter>
+ <fes:BBOX>
+ <fes:ValueReference>/RS1/geometry</fes:ValueReference>
+ <gml:Envelope srsName="urn:ogc:def:crs:EPSG::1234">
+ <gml:lowerCorner>10 10</gml:lowerCorner>
+ <gml:upperCorner>20 20</gml:upperCorner>
+ </gml:Envelope>
+ </fes:BBOX>
+ </fes:Filter>
+*/
+/*
+$bboxFilter = '<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0"><fes:BBOX>';
+ $bboxFilter .= '<fes:ValueReference>'.$geometryFieldName.'</fes:ValueReference>';
+ //<gml:Envelope srsName="urn:ogc:def:crs:EPSG::1234">
+ $bboxFilter .= '<gml:Envelope xmlns:gml="http://www.opengis.net/gml/3.2" srsName="'.$crs.'">';
+ //FIX for ESRI? TODO
+ $bboxFilter .= '<gml:lowerCorner>'.$currentBboxGetFeature[0].' '.$currentBboxGetFeature[1].'</gml:lowerCorner>';
+ $bboxFilter .= '<gml:upperCorner>'.$currentBboxGetFeature[2].' '.$currentBboxGetFeature[3].'</gml:upperCorner>';
+ $bboxFilter .= '</gml:Envelope>';
+ $bboxFilter .= '</fes:BBOX>';
+ $bboxFilter .= '</fes:Filter>';
+ $bboxFilter = rawurlencode(utf8_decode($bboxFilter));
+*/
+
+ $spatialFilter .= "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">";
+ $spatialFilter .= "<fes:BBOX>";
+ $spatialFilter .= "<fes:ValueReference>".$geometryColumn."</fes:ValueReference>";
+ $spatialFilter .= '<gml:Envelope xmlns:gml="http://www.opengis.net/gml/3.2" srsName="'.$targetSrs.'">';
+ $spatialFilter .= '<gml:lowerCorner>'.$bboxArray[0]." ".$bboxArray[1].'</gml:lowerCorner>';
+ $spatialFilter .= '<gml:upperCorner>'.$bboxArray[2]." ".$bboxArray[3].'</gml:upperCorner>';
+ $spatialFilter .= '</gml:Envelope>';
+ $spatialFilter .= "</fes:BBOX>";
+ $spatialFilter .= "</fes:Filter>";
+
+ break;
+ case "other_test":
+ //gml2
+ $spatialFilter .= "<ogc:Filter>";
+ $spatialFilter .= "<ogc:BBOX>";
+ $spatialFilter .= "<ogc:PropertyName>".$geometryColumn."</ogc:PropertyName>";
+ $spatialFilter .= '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="'.$targetSrs.'">';
+ $spatialFilter .= '<gml:coordinates decimal="." cs="," ts=" ">';
+ $spatialFilter .= $bboxArray[0].','.$bboxArray[1].' '.$bboxArray[2].','.$bboxArray[3];
+ $spatialFilter .= '</gml:coordinates></gml:Box>';
+ $spatialFilter .= "</ogc:BBOX>";
+ $spatialFilter .= "</ogc:Filter>";
+ break;
+ case "1.1.0":
+ //gml2
+ $spatialFilter .= "<ogc:BBOX>";
+ $spatialFilter .= "<ogc:PropertyName>".$geometryColumn."</ogc:PropertyName>";
+ $spatialFilter .= '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="'.$targetSrs.'">';
+ $spatialFilter .= '<gml:coordinates decimal="." cs="," ts=" ">';
+ $spatialFilter .= $bboxArray[0].','.$bboxArray[1].' '.$bboxArray[2].','.$bboxArray[3];
+ $spatialFilter .= '</gml:coordinates></gml:Box>';
+ $spatialFilter .= "</ogc:BBOX>";
+ break;
+ }
+ if ($spatialFilter == ""){
+ $spatialFilter = false;
+ }
+ //$e = new mb_exception("classes/class_wfs.php: spatialFilter: ".$spatialFilter);
+ 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);
if ($version == false) {
$version = $this->getVersion();
} else {
- $e = new mb_exception("classes/class_wfs.php: wfs version forced too ".$version."!");
+ $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
+ }
//maxfeatures - in newer versions count is used - for paging
switch ($version) {
case "2.0.2":
$typeNameParameterName = "typeNames";
$maxFeaturesParameterName = "COUNT";
+ $srsName = "http://www.opengis.net/def/crs/EPSG/0/".$srsId;
break;
case "2.0.0":
$typeNameParameterName = "typeNames";
$maxFeaturesParameterName = "COUNT";
+ $srsName = "urn:ogc:def:crs:EPSG::".$srsId; //mapserver error when requesting this?
+ //$srsName = "EPSG:".$srsId;
break;
+ case "1.1.0":
+ $typeNameParameterName = "typeName";
+ $maxFeaturesParameterName = "MAXFEATURES";
+ $srsName = "urn:ogc:def:crs:EPSG::".$srsId;
+ break;
default:
$typeNameParameterName = "typeName";
$maxFeaturesParameterName = "MAXFEATURES";
+ $srsName = "EPSG:".$srsId;
break;
}
if($storedQueryId && $storedQueryId != "") {
$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
- "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "<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\" ".
@@ -297,11 +442,10 @@
$postData .= "<wfs:StoredQuery id=\"" . $storedQueryId . "\">";
$postData .= $storedQueryParams;
$postData .= "</wfs:StoredQuery>";
- }
- else {
+ } else {
if($version == "2.0.0" || $version == "2.0.2") {
$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
- "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "<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\" ".
@@ -309,11 +453,10 @@
"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
+ }//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=\"" . $this->getVersion() . "\" " .
+ "<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\" " .
@@ -322,7 +465,7 @@
}
else {
$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
- "<wfs:GetFeature service=\"WFS\" version=\"" . $this->getVersion() . "\" " .
+ "<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\" " .
@@ -331,7 +474,7 @@
}
$postData .="<wfs:Query ";
if($destSrs) {
- $postData .= "srsName=\"" . $destSrs . "\" ";
+ $postData .= "srsName=\"" . $srsName . "\" ";
}
// add namespace
if (strpos($featureTypeName, ":") !== false) {
@@ -342,9 +485,9 @@
}
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("/ogc", "/fes", $filter);
- $filter = str_replace("PropertyName", "ValueReference", $filter);
+ $filter = str_replace("PropertyName", "ValueReference", $filter);*/
}
$postData .= $typeNameParameterName."=\"" . $featureTypeName . "\">" .
$filter .
@@ -354,42 +497,25 @@
//$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
+ //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) {
- //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;
- }
+ $getRequest .= "&SRSNAME=".$srsName;
}
-$e = new mb_exception($getRequest);
+ //$e = new mb_exception($getRequest);
//convert gml 3 to geojson!
- return $this->get($getRequest);
+ //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!
+//$e = new mb_exception("classes/class_wfs.php: getFeaturePostPaging: postdata: ".$postData);
+ return $this->post($this->getFeature, $postData); //from class_ows!
}
- public function countFeatures($featureTypeName) {
+ public function countFeatures($featureTypeName, $filter=null) {
switch ($this->getVersion()) {
case "2.0.2":
$typeNameParameterName = "typeNames";
@@ -412,6 +538,9 @@
$this->getConjunctionCharacter($this->getFeature) .
"service=WFS&request=GetFeature&version=" .
$this->getVersion() . "&".strtolower($typeNameParameterName)."=" . $featureTypeName."&resultType=hits";
+ if ($filter != null) {
+ $url .= "&FILTER=".$filter;
+ }
//$e = new mb_exception("class_wfs.php: getFeatureGet: ".$url);
//auth is already integrated in ows class
//do request
@@ -596,7 +725,7 @@
if ($version == false) {
$version = $this->getVersion();
} else {
- $e = new mb_exception("classes/class_wfs.php: wfs version forced too ".$version."!");
+ $e = new mb_notice("classes/class_wfs.php: wfs version forced to ".$version."!");
}
switch ($this->getVersion()) {
case "2.0.2":
More information about the Mapbender_commits
mailing list