[Mapbender-commits] r3521 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Feb 6 11:14:30 EST 2009
Author: christoph
Date: 2009-02-06 11:14:29 -0500 (Fri, 06 Feb 2009)
New Revision: 3521
Modified:
trunk/mapbender/http/classes/class_connector.php
trunk/mapbender/http/classes/class_gml_3_factory.php
trunk/mapbender/http/classes/class_universal_gml_factory.php
trunk/mapbender/http/classes/class_wfs.php
Log:
WFS redesign
Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php 2009-02-06 14:54:33 UTC (rev 3520)
+++ trunk/mapbender/http/classes/class_connector.php 2009-02-06 16:14:29 UTC (rev 3521)
@@ -139,7 +139,7 @@
private function isValidHttpContentType ($value) {
$validHttpContentTypeArray = array("XML");
if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
- switch ($value) {
+ switch (mb_strtoupper($value)) {
case "XML":
$this->httpContentType = "application/xml";
break;
@@ -181,16 +181,36 @@
$port = 80;
}
$path = $urlComponentArray["path"];
+ $query = $urlComponentArray["query"];
$buf = '';
$fp = fsockopen($host, $port);
- fputs($fp, "POST $path HTTP/".$this->httpVersion . "\r\n");
- fputs($fp, "Host: $host\r\n");
+ $postStr = "";
+ $postPath = "POST " . $path . "?" . $query . " HTTP/".$this->httpVersion . "\r\n";
+ $postStr .= $postPath;
+ fputs($fp, $postPath);
+
+ $postHost = "Host: " . $host . "\r\n";
+ $postStr .= $postHost;
+ fputs($fp, $postHost);
+
if ($this->isValidHttpContentType($this->httpContentType)) {
- fputs($fp,"Content-type: " . $this->httpContentType . "\r\n");
+ $postContentType = "Content-type: " . $this->httpContentType . "\r\n";
+ $postStr .= $postContentType;
+ fputs($fp, $postContentType);
}
- fputs($fp, "Content-length: " . strlen($this->httpPostData) . "\r\n");
- fputs($fp, "Connection: close\r\n\r\n");
- fputs($fp, $this->httpPostData);
+ $postContentLength = "Content-length: " . strlen($this->httpPostData) . "\r\n";
+ $postStr .= $postContentLength;
+ fputs($fp, $postContentLength);
+
+ $postClose = "Connection: close\r\n\r\n";
+ $postStr .= $postClose;
+ fputs($fp, $postClose);
+
+ $postStr .= $this->httpPostData;
+ fputs($fp, $this->httpPostData);
+
+ new mb_exception($postStr);
+
$xmlstr = false;
while (!feof($fp)) {
$content = fgets($fp,4096);
Modified: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php 2009-02-06 14:54:33 UTC (rev 3520)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php 2009-02-06 16:14:29 UTC (rev 3521)
@@ -45,8 +45,17 @@
return parent::createFromXml($xml, $gml3);
}
+ protected function getDimensionFromNode ($domNode) {
+ if (!$domNode->hasAttribute("srsDimension")) {
+ return 2;
+ }
+ $dim = intval($domNode->getAttribute("srsDimension"), 10);
+ if (2 == $dim || 3 == $dim) {
+ return $dim;
+ }
+ return 2;
+ }
-
function findNameSpace($s){
list($ns,$FeaturePropertyName) = split(":",$s);
$nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName);
@@ -56,8 +65,8 @@
private function parsePoint ($domNode, $gmlPoint) {
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
- list($x, $y, $z) = explode(",", $currentSibling->nodeValue);
- $gmlPoint->setPoint($x, $y);
+ $coordArray = explode(" ", $currentSibling->nodeValue);
+ $gmlPoint->setPoint($coordArray[0], $coordArray[1]);
$currentSibling = $currentSibling->nextSibling;
}
}
@@ -65,9 +74,12 @@
private function parseLine ($domNode, $gmlLine) {
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
-
- foreach(explode(' ',$currentSibling->nodeValue) as $cords){
- list($x,$y,$z) = explode(',',$cords);
+
+ $dim = $this->getDimensionFromNode($currentSibling);
+ $coordArray = explode(' ', trim($currentSibling->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
$gmlLine->addPoint($x, $y);
}
$currentSibling = $currentSibling->nextSibling;
@@ -84,16 +96,14 @@
$cnt=0;
foreach ($allCoords as $Coords) {
$coordsDom = dom_import_simplexml($Coords);
-
- $dim = $coordsDom->getAttribute("srsDimension");
- if ($dim == "2") {
- $coordArray = explode(' ', trim($coordsDom->nodeValue));
- for ($i = 0; $i < count($coordArray); $i += 2) {
- $x = $coordArray[$i];
- $y = $coordArray[$i+1];
- $gmlPolygon->addPoint($x, $y);
- }
- }
+
+ $dim = $this->getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
+ $gmlPolygon->addPoint($x, $y);
+ }
$cnt++;
}
@@ -105,14 +115,12 @@
foreach ($coordinates as $coordinate) {
$coordsDom = dom_import_simplexml($coordinate);
- $dim = $coordsDom->getAttribute("srsDimension");
- if ($dim == "2") {
- $coordArray = explode(' ', trim($coordsDom->nodeValue));
- for ($i = 0; $i < count($coordArray); $i += 2) {
- $x = $coordArray[$i];
- $y = $coordArray[$i+1];
- $gmlPolygon->addPointToRing($ringCount, $x, $y);
- }
+ $dim = $this->getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
+ $gmlPolygon->addPointToRing($ringCount, $x, $y);
}
}
$ringCount++;
@@ -125,7 +133,7 @@
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
- $allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:coordinates");
+ $allCoords = $simpleXMLNode->xpath("gml:curveMembers/gml:LineString/gml:posList");
$cnt=0;
foreach ($allCoords as $Coords) {
@@ -133,16 +141,14 @@
$gmlMultiLine->lineArray[$cnt] = array();
$coordsDom = dom_import_simplexml($Coords);
-
-// $name = $coordsDom->nodeName;
-// $value = $coordsDom->nodeValue;
-// echo "===> name: ".$name. ", Value: ".$value."<br>";
-
- foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
- list($x,$y,$z) = explode(',',$pointCoords);
+
+ $dim = $this->getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
$gmlMultiLine->addPoint($x, $y, $cnt);
- }
-
+ }
$cnt++;
}
}
@@ -163,19 +169,14 @@
foreach ($allCoords as $Coords) {
$coordsDom = dom_import_simplexml($Coords);
- $dim = $coordsDom->getAttribute("srsDimension");
- if ($dim == "2") {
- $coordArray = explode(' ', trim($coordsDom->nodeValue));
- for ($i = 0; $i < count($coordArray); $i += 2) {
- $x = $coordArray[$i];
- $y = $coordArray[$i+1];
- $gmlMultiPolygon->addPoint($x, $y, $cnt);
- }
+
+ $dim = $this->getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
+ $gmlMultiPolygon->addPoint($x, $y, $cnt);
}
- // assume $dim == "3"
- else {
- $e = new mb_exception("GML with three-dimensional coordinates are not supported.");
- }
}
$gmlMultiPolygon->innerRingArray[$cnt] = array();
@@ -189,19 +190,13 @@
foreach ($coordinates as $coordinate) {
$coordsDom = dom_import_simplexml($coordinate);
- $dim = $coordsDom->getAttribute("srsDimension");
- if ($dim == "2") {
- $coordArray = explode(' ', trim($coordsDom->nodeValue));
- for ($i = 0; $i < count($coordArray); $i += 2) {
- $x = $coordArray[$i];
- $y = $coordArray[$i+1];
- $gmlMultiPolygon->addPointToRing($cnt, $ringCount, $x, $y);
- }
+ $dim = $this->getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
+ $gmlMultiPolygon->addPointToRing($cnt, $ringCount, $x, $y);
}
- // assume $dim == "3"
- else {
- $e = new mb_exception("GML with three-dimensional coordinates are not supported.");
- }
}
$ringCount++;
@@ -291,11 +286,11 @@
$geomNode = $currentSibling->firstChild;
$geomType = $geomNode->nodeName;
switch ($geomType) {
- case "gml:Polygon" :
+ case "gml:Polygon" :// untested!
$feature->geometry = new GMLPolygon();
$this->parsePolygon($geomNode, $feature->geometry);
break;
- case "gml:LineString" :
+ case "gml:LineString" :// untested!
$feature->geometry = new GMLLine();
$this->parseLine($geomNode, $feature->geometry);
break;
@@ -307,7 +302,7 @@
$feature->geometry = new GMLMultiLine();
$this->parseMultiLine($geomNode, $feature->geometry);
break;
- case "gml:MultiSurface" :
+ case "gml:MultiSurface" :
$feature->geometry = new GMLMultiPolygon();
$this->parseMultiPolygon($geomNode, $feature->geometry);
break;
Modified: trunk/mapbender/http/classes/class_universal_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_gml_factory.php 2009-02-06 14:54:33 UTC (rev 3520)
+++ trunk/mapbender/http/classes/class_universal_gml_factory.php 2009-02-06 16:14:29 UTC (rev 3521)
@@ -45,6 +45,12 @@
if (count($nodeArray) > 0 ) {
return "3";
}
+
+ $nodeArray = $simpleXml->xpath("gml:featureMember//gml:pos");
+ if (count($nodeArray) > 0 ) {
+ return "3";
+ }
+
return "2";
throw new Exception("GML version could not be determined from XML.");
}
Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php 2009-02-06 14:54:33 UTC (rev 3520)
+++ trunk/mapbender/http/classes/class_wfs.php 2009-02-06 16:14:29 UTC (rev 3521)
@@ -55,9 +55,24 @@
return null;
}
- public function getFeature ($featureTypeName, $filter) {
-/* POST */
+ protected function getFeatureGet ($featureTypeName, $filter) {
+ $url = $this->getFeature .
+ $this->getConjunctionCharacter($this->getFeature) .
+ "service=WFS&request=getFeature&version=" .
+ $this->getVersion() . "&typename=" . $featureTypeName .
+ "&filter=" . urlencode($filter);
+ $connection = new connector($url);
+ $data = $connection->file;
+ if (!$data) {
+ $e = new mb_exception("WFS request returned no result: " . $url);
+ return null;
+ }
+ new mb_exception("Reply from WFS: " . $url . "\n\n" . $data);
+ return $data;
+ }
+
+ protected function getFeaturePost ($featureTypeName, $filter) {
$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
"<wfs:GetFeature version=\"" . $this->getVersion() . "\" " .
"xmlns:wfs=\"http://www.opengis.net/wfs\">" .
@@ -86,25 +101,16 @@
return null;
}
return $data;
-
-
-/* GET */
-// $url = $this->getFeature .
-// $this->getConjunctionCharacter($this->getFeature) .
-// "service=WFS&request=getFeature&version=" .
-// $this->getVersion() . "&typename=" . $featureTypeName .
-// "&filter=" . urlencode($filter);
-//
-// $connection = new connector($url);
-// $data = $connection->file;
-// if (!$data) {
-// $e = new mb_exception("WFS request returned no result: " . $url);
-// return null;
-// }
-// return $data;
}
+ public function getFeature ($featureTypeName, $filter) {
+ if (strpos($this->getFeature, "?") === false) {
+ return $this->getFeaturePost($featureTypeName, $filter);
+ }
+ return $this->getFeatureGet($featureTypeName, $filter);
+ }
+
// -----------------------------------------------------------------------
//
// Output formats
More information about the Mapbender_commits
mailing list