[Mapbender-commits] r3891 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Apr 16 11:23:18 EDT 2009
Author: christoph
Date: 2009-04-16 11:23:18 -0400 (Thu, 16 Apr 2009)
New Revision: 3891
Modified:
trunk/mapbender/http/classes/class_gml_2_factory.php
trunk/mapbender/http/classes/class_gml_3_factory.php
trunk/mapbender/http/classes/class_gml_factory.php
trunk/mapbender/http/classes/class_gml_line.php
trunk/mapbender/http/classes/class_gml_multiline.php
trunk/mapbender/http/classes/class_gml_multipolygon.php
trunk/mapbender/http/classes/class_gml_point.php
trunk/mapbender/http/classes/class_gml_polygon.php
Log:
bugfix: GML parser: GML3 includes GML2, so there may be mixed syntax
Modified: trunk/mapbender/http/classes/class_gml_2_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2_factory.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_2_factory.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -48,16 +48,21 @@
return $nodeName;
}
- private function parsePoint ($domNode, $gmlPoint) {
+ public static function parsePoint ($domNode) {
+ $gmlPoint = new GmlPoint();
+
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
list($x, $y, $z) = explode(",", $currentSibling->nodeValue);
$gmlPoint->setPoint($x, $y);
$currentSibling = $currentSibling->nextSibling;
}
+ return $gmlPoint;
}
- private function parseLine ($domNode, $gmlLine) {
+ public static function parseLine ($domNode) {
+ $gmlLine = new GmlLine();
+
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
@@ -67,9 +72,12 @@
}
$currentSibling = $currentSibling->nextSibling;
}
+ return $gmlLine;
}
- private function parsePolygon ($domNode, $gmlPolygon) {
+ public static function parsePolygon ($domNode) {
+ $gmlPolygon = new GmlPolygon();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -106,9 +114,12 @@
$ringCount++;
}
}
+ return $gmlPolygon;
}
- private function parseMultiLine ($domNode, $gmlMultiLine) {
+ public static function parseMultiLine ($domNode) {
+ $gmlMultiLine = new GmlMultiLine();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -133,10 +144,12 @@
$cnt++;
}
+ return $gmlMultiLine;
}
- private function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
-// echo $domNode->nodeName."<br>";
+ public static function parseMultiPolygon ($domNode) {
+ $gmlMultiPolygon = new GmlMultiPolygon();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -181,8 +194,8 @@
}
}
$cnt++;
-// new mb_exception("create multipolygon " . serialize($gmlMultiPolygon->innerRingArray));
}
+ return $gmlMultiPolygon;
}
/**
@@ -260,29 +273,24 @@
$geomType = $geomNode->nodeName;
switch ($geomType) {
case "gml:Polygon" :
- $feature->geometry = new GMLPolygon();
+ $feature->geometry = self::parsePolygon($geomNode);
$feature->geometry->srs = $srs;
- $this->parsePolygon($geomNode, $feature->geometry);
break;
case "gml:LineString" :
- $feature->geometry = new GMLLine();
+ $feature->geometry = self::parseLine($geomNode);
$feature->geometry->srs = $srs;
- $this->parseLine($geomNode, $feature->geometry);
break;
case "gml:Point" :
- $feature->geometry = new GMLPoint();
+ $feature->geometry = self::parsePoint($geomNode);
$feature->geometry->srs = $srs;
- $this->parsePoint($geomNode, $feature->geometry);
break;
case "gml:MultiLineString" :
- $feature->geometry = new GMLMultiLine();
+ $feature->geometry = self::parseMultiLine($geomNode);
$feature->geometry->srs = $srs;
- $this->parseMultiLine($geomNode, $feature->geometry);
break;
case "gml:MultiPolygon" :
- $feature->geometry = new GMLMultiPolygon();
+ $feature->geometry = self::parseMultiPolygon($geomNode);
$feature->geometry->srs = $srs;
- $this->parseMultiPolygon($geomNode, $feature->geometry);
break;
default:
$feature->properties[$columnName] = $value;
Modified: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -53,7 +53,7 @@
return parent::createFromXml($xml, $wfsConf, $gml3);
}
- protected function getDimensionFromNode ($domNode) {
+ public static function getDimensionFromNode ($domNode) {
if (!$domNode->hasAttribute("srsDimension")) {
return 2;
}
@@ -70,20 +70,24 @@
return $nodeName;
}
- private function parsePoint ($domNode, $gmlPoint) {
+ public static function parsePoint ($domNode) {
+ $gmlPoint = new GmlPoint();
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
$coordArray = explode(" ", $currentSibling->nodeValue);
$gmlPoint->setPoint($coordArray[0], $coordArray[1]);
$currentSibling = $currentSibling->nextSibling;
}
+ return $gmlPoint;
}
- private function parseLine ($domNode, $gmlLine) {
+ public static function parseLine ($domNode) {
+ $gmlLine = new GmlLine();
+
$currentSibling = $domNode->firstChild;
while ($currentSibling) {
- $dim = $this->getDimensionFromNode($currentSibling);
+ $dim = self::getDimensionFromNode($currentSibling);
$coordArray = explode(' ', trim($currentSibling->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -92,9 +96,12 @@
}
$currentSibling = $currentSibling->nextSibling;
}
+ return $gmlLine;
}
- private function parsePolygon ($domNode, $gmlPolygon) {
+ public static function parsePolygon ($domNode) {
+ $gmlPolygon = new GmlPolygon();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -105,7 +112,7 @@
foreach ($allCoords as $Coords) {
$coordsDom = dom_import_simplexml($Coords);
- $dim = $this->getDimensionFromNode($coordsDom);
+ $dim = self::getDimensionFromNode($coordsDom);
$coordArray = explode(' ', trim($coordsDom->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -123,7 +130,7 @@
foreach ($coordinates as $coordinate) {
$coordsDom = dom_import_simplexml($coordinate);
- $dim = $this->getDimensionFromNode($coordsDom);
+ $dim = self::getDimensionFromNode($coordsDom);
$coordArray = explode(' ', trim($coordsDom->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -134,9 +141,12 @@
$ringCount++;
}
}
+ return $gmlPolygon;
}
- private function parseMultiLine ($domNode, $gmlMultiLine) {
+ public static function parseMultiLine ($domNode) {
+ $gmlMultiLine = new GmlMultiLine();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -150,7 +160,7 @@
$coordsDom = dom_import_simplexml($Coords);
- $dim = $this->getDimensionFromNode($coordsDom);
+ $dim = self::getDimensionFromNode($coordsDom);
$coordArray = explode(' ', trim($coordsDom->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -159,9 +169,12 @@
}
$cnt++;
}
+ return $gmlMultiLine;
}
- private function parseMultiPolygon ($domNode, $gmlMultiPolygon) {
+ public static function parseMultiPolygon ($domNode) {
+ $gmlMultiPolygon = new GmlMultiPolygon();
+
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
@@ -177,7 +190,7 @@
$coordsDom = dom_import_simplexml($Coords);
- $dim = $this->getDimensionFromNode($coordsDom);
+ $dim = self::getDimensionFromNode($coordsDom);
$coordArray = explode(' ', trim($coordsDom->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -197,7 +210,7 @@
foreach ($coordinates as $coordinate) {
$coordsDom = dom_import_simplexml($coordinate);
- $dim = $this->getDimensionFromNode($coordsDom);
+ $dim = self::getDimensionFromNode($coordsDom);
$coordArray = explode(' ', trim($coordsDom->nodeValue));
for ($i = 0; $i < count($coordArray); $i += $dim) {
$x = $coordArray[$i];
@@ -212,7 +225,8 @@
}
$cnt++;
// new mb_exception("create multipolygon " . serialize($gmlMultiPolygon->innerRingArray));
- }
+ }
+ return $gmlMultiPolygon;
}
/**
@@ -293,29 +307,39 @@
}
switch ($geomType) {
case "gml:Polygon" :// untested!
- $feature->geometry = new GMLPolygon();
+ $feature->geometry = self::parsePolygon($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parsePolygon($geomNode);
+ }
$feature->geometry->srs = $srs;
- $this->parsePolygon($geomNode, $feature->geometry);
break;
case "gml:LineString" :// untested!
- $feature->geometry = new GMLLine();
+ $feature->geometry = self::parseLine($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parseLine($geomNode);
+ }
$feature->geometry->srs = $srs;
- $this->parseLine($geomNode, $feature->geometry);
break;
case "gml:Point" :
- $feature->geometry = new GMLPoint();
+ $feature->geometry = self::parsePoint($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parsePoint($geomNode);
+ }
$feature->geometry->srs = $srs;
- $this->parsePoint($geomNode, $feature->geometry);
break;
case "gml:MultiCurve" :
- $feature->geometry = new GMLMultiLine();
+ $feature->geometry = self::parseMultiLine($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parseMultiLine($geomNode);
+ }
$feature->geometry->srs = $srs;
- $this->parseMultiLine($geomNode, $feature->geometry);
break;
case "gml:MultiSurface" :
- $feature->geometry = new GMLMultiPolygon();
+ $feature->geometry = self::parseMultiPolygon($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parseMultiPolygon($geomNode);
+ }
$feature->geometry->srs = $srs;
- $this->parseMultiPolygon($geomNode, $feature->geometry);
break;
default:
$feature->properties[$columnName] = $value;
Modified: trunk/mapbender/http/classes/class_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_factory.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_factory.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -44,8 +44,6 @@
$jsonObj = $json->decode($geoJson);
// check if valid feature collection
- new mb_exception("Is Array? " . is_array($jsonObj->features));
- new mb_exception("Type? " . strtoupper($jsonObj->type));
if (strtoupper($jsonObj->type) != "FEATURECOLLECTION" || !is_array($jsonObj->features)) {
$e = new mb_exception("Not a valid GeoJSON Feature Collection.");
return null;
Modified: trunk/mapbender/http/classes/class_gml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_line.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_line.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -64,6 +64,10 @@
return $str;
}
+ public function isEmpty () {
+ return !(count($this->pointArray) > 0);
+ }
+
public function toGeoJSON () {
$numberOfPoints = count($this->pointArray);
$str = "";
Modified: trunk/mapbender/http/classes/class_gml_multiline.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multiline.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_multiline.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -65,6 +65,10 @@
}
+ public function isEmpty () {
+ return !(count($this->lineArray) > 0);
+ }
+
public function toGeoJSON () {
$numberlineArray = count($this->lineArray);
$str = "";
Modified: trunk/mapbender/http/classes/class_gml_multipolygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multipolygon.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_multipolygon.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -125,6 +125,10 @@
return $str;
}
+
+ public function isEmpty () {
+ return !(count($this->polygonArray) > 0);
+ }
public function toGeoJSON () {
$numberPolygonArray = count($this->polygonArray);
Modified: trunk/mapbender/http/classes/class_gml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_point.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_point.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -48,6 +48,10 @@
return $str;
}
+ public function isEmpty () {
+ return ($this->point ? false : true);
+ }
+
public function toGeoJSON () {
$str = "";
if ($this->point) {
Modified: trunk/mapbender/http/classes/class_gml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_polygon.php 2009-04-16 14:24:49 UTC (rev 3890)
+++ trunk/mapbender/http/classes/class_gml_polygon.php 2009-04-16 15:23:18 UTC (rev 3891)
@@ -99,6 +99,10 @@
return $str;
}
+ public function isEmpty () {
+ return !(count($this->pointArray) > 0);
+ }
+
public function toGeoJSON () {
$numberOfPoints = count($this->pointArray);
$str = "";
More information about the Mapbender_commits
mailing list