[Mapbender-commits] r4655 - branches/2.6/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Sep 18 05:34:38 EDT 2009
Author: christoph
Date: 2009-09-18 05:34:36 -0400 (Fri, 18 Sep 2009)
New Revision: 4655
Added:
branches/2.6/http/classes/class_gml_multipoint.php
Modified:
branches/2.6/http/classes/class_gml_3_factory.php
branches/2.6/http/classes/class_gml_factory.php
branches/2.6/http/classes/class_gml_feature.php
branches/2.6/http/classes/class_gml_geometry.php
branches/2.6/http/classes/class_gml_line.php
branches/2.6/http/classes/class_gml_multiline.php
branches/2.6/http/classes/class_gml_multipolygon.php
branches/2.6/http/classes/class_gml_point.php
branches/2.6/http/classes/class_gml_polygon.php
Log:
* workaround axis order confusion
* added MultiPoint support
Modified: branches/2.6/http/classes/class_gml_3_factory.php
===================================================================
--- branches/2.6/http/classes/class_gml_3_factory.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_3_factory.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -151,7 +151,7 @@
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
- $allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:poslist");
+ $allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:posList");
$cnt=0;
foreach ($allCoords as $Coords) {
@@ -170,6 +170,31 @@
$cnt++;
}
return $gmlMultiLine;
+ }
+
+ public static function parseMultiPoint ($domNode) {
+ $gmlMultiPoint = new GmlMultiPoint();
+
+ $simpleXMLNode = simplexml_import_dom($domNode);
+
+ $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ $allCoords = $simpleXMLNode->xpath("gml:pointMember/gml:Point/gml:pos");
+
+ foreach ($allCoords as $Coords) {
+
+ $coordsDom = dom_import_simplexml($Coords);
+
+ $dim = self::getDimensionFromNode($coordsDom);
+ $coordArray = explode(' ', trim($coordsDom->nodeValue));
+ for ($i = 0; $i < count($coordArray); $i += $dim) {
+ $x = $coordArray[$i];
+ $y = $coordArray[$i+1];
+ $gmlMultiPoint->addPoint($x, $y);
+ break;
+ }
+ }
+ return $gmlMultiPoint;
}
public static function parseMultiCurve ($domNode) {
@@ -207,7 +232,7 @@
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
- $allPolygons = $simpleXMLNode->xpath("gml:surfaceMembers/gml:Polygon");
+ $allPolygons = $simpleXMLNode->xpath("gml:surfaceMember/gml:Polygon");
$cnt=0;
foreach ($allPolygons as $polygon) {
@@ -355,10 +380,25 @@
}
$feature->geometry->srs = $srs;
break;
+ case "gml:MultiPoint" :
+ $feature->geometry = self::parseMultiPoint($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parseMultiPoint($geomNode);
+ }
+ $feature->geometry->srs = $srs;
+ break;
+ case "gml:MultiLineString" :
+ new mb_exception("found multilinestring");
+ $feature->geometry = self::parseMultiLine($geomNode);
+ if ($feature->geometry->isEmpty()) {
+ $feature->geometry = Gml_2_Factory::parseMultiLine($geomNode);
+ }
+ $feature->geometry->srs = $srs;
+ break;
case "gml:MultiCurve" :
$feature->geometry = self::parseMultiCurve($geomNode);
if ($feature->geometry->isEmpty()) {
- $feature->geometry = self::parseMultiLine($geomNode);
+ $feature->geometry = Gml_2_Factory::parseMultiLine($geomNode);
}
$feature->geometry->srs = $srs;
break;
Modified: branches/2.6/http/classes/class_gml_factory.php
===================================================================
--- branches/2.6/http/classes/class_gml_factory.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_factory.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -68,7 +68,12 @@
$currentRing = $currentGeometry->coordinates[$i];
foreach ($currentRing as $coords) {
- list($x, $y) = $coords;
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $coords;
+ }
+ else {
+ list($x, $y) = $coords;
+ }
// exterior ring
if (0 == $i) {
@@ -83,14 +88,38 @@
break;
case "POINT":
$geometry = new GMLPoint();
- list($x, $y) = $currentGeometry->coordinates;
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $currentGeometry->coordinates;
+ }
+ else {
+ list($x, $y) = $currentGeometry->coordinates;
+ }
+
$geometry->setPoint($x, $y);
break;
+ case "MULTIPOINT":
+ $geometry = new GMLMultiPoint();
+ for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
+ $currentPoint = $currentGeometry->coordinates[$i];
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $currentPoint;
+ }
+ else {
+ list($x, $y) = $currentPoint;
+ }
+ $geometry->addPoint($x, $y);
+ }
+ break;
case "LINESTRING":
$geometry = new GMLLine();
for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
$currentLinePoint = $currentGeometry->coordinates[$i];
- list($x, $y) = $currentLinePoint;
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $currentLinePoint;
+ }
+ else {
+ list($x, $y) = $currentLinePoint;
+ }
$geometry->addPoint($x, $y);
}
break;
@@ -103,7 +132,12 @@
$currentRing = $currentPolygon[$j];
foreach ($currentRing as $coords) {
- list($x, $y) = $coords;
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $coords;
+ }
+ else {
+ list($x, $y) = $coords;
+ }
// exterior ring
if (0 == $j) {
@@ -117,16 +151,17 @@
}
}
break;
- case "MULTIPOINT":
- $e = new mb_exception($currentGeometry->type . " are not supported!");
- return null;
- break;
case "MULTILINESTRING": // not tested!
$geometry = new GMLMultiLine();
for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
$currentLine = $currentGeometry->coordinates[$i];
foreach ($currentLine as $currentLinePoint) {
- list($x, $y) = $currentLinePoint;
+ if (in_array($srs, $geometry->latLonSrs)) {
+ list($y, $x) = $currentLinePoint;
+ }
+ else {
+ list($x, $y) = $currentLinePoint;
+ }
$geometry->addPoint($x, $y, $i);
}
}
Modified: branches/2.6/http/classes/class_gml_feature.php
===================================================================
--- branches/2.6/http/classes/class_gml_feature.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_feature.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -20,6 +20,7 @@
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
require_once(dirname(__FILE__)."/../classes/class_json.php");
require_once(dirname(__FILE__)."/../classes/class_gml_point.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_multipoint.php");
require_once(dirname(__FILE__)."/../classes/class_gml_line.php");
require_once(dirname(__FILE__)."/../classes/class_gml_multiline.php");
require_once(dirname(__FILE__)."/../classes/class_gml_polygon.php");
Modified: branches/2.6/http/classes/class_gml_geometry.php
===================================================================
--- branches/2.6/http/classes/class_gml_geometry.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_geometry.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -31,5 +31,9 @@
abstract public function toGeoJSON ();
public $srs;
+
+ public $latLonSrs = array(
+ "urn:x-ogc:def:crs:EPSG:4326"
+ );
}
?>
\ No newline at end of file
Modified: branches/2.6/http/classes/class_gml_line.php
===================================================================
--- branches/2.6/http/classes/class_gml_line.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_line.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -77,7 +77,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->pointArray[$i]["y"].",".$this->pointArray[$i]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
}
$str .= "]}";
}
Modified: branches/2.6/http/classes/class_gml_multiline.php
===================================================================
--- branches/2.6/http/classes/class_gml_multiline.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_multiline.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -85,7 +85,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->lineArray[$cnt][$i]["x"].",".$this->lineArray[$cnt][$i]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->lineArray[$cnt][$i]["y"].",".$this->lineArray[$cnt][$i]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->lineArray[$cnt][$i]["x"].",".$this->lineArray[$cnt][$i]["y"]."]";
+ }
}
$str .="]";
}
Added: branches/2.6/http/classes/class_gml_multipoint.php
===================================================================
--- branches/2.6/http/classes/class_gml_multipoint.php (rev 0)
+++ branches/2.6/http/classes/class_gml_multipoint.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -0,0 +1,93 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
+
+
+class GMLMultiPoint extends GmlGeometry {
+
+ var $pointArray = array();
+
+ public function __construct() {
+
+ }
+
+ public function addPoint ($x, $y) {
+ array_push($this->pointArray, array("x" => $x, "y" => $y));
+ }
+
+ public function toGml2 () {
+ $str = "<gml:MultiPoint srsName='$srsName'>";
+ foreach ($this->pointArray as $point) {
+ $str .= "<gml:pointMember><gml:Point><gml:coordinates>";
+ $str .= $point["x"] . "," . $point["y"];
+ $str .= "</gml:coordinates></gml:Point>";
+ }
+ $str .= "<gml:pointMember><gml:MultiPoint>";
+ return $str;
+ }
+
+ public function toGml3 () {
+
+ $str = "<gml:MultiPoint srsName='$srsName'>";
+ foreach ($this->pointArray as $point) {
+ $str .= "<gml:pointMember><gml:Point>";
+ $str .= "<gml:pos>" . $point["x"] . " " . $point["y"] . "</gml:pos>";
+ $str .= "</gml:Point><gml:pointMember>";
+ }
+ $str .= "<gml:MultiPoint>";
+ return $str;
+
+ }
+
+ public function isEmpty () {
+ return !(count($this->pointArray) > 0);
+ }
+
+ public function toGeoJSON () {
+ $numberlineArray = count($this->pointArray);
+ $str = "";
+ if ($numberlineArray > 0) {
+ $str .= "{\"type\": \"MultiPoint\", \"coordinates\":[";
+
+ for ($cnt =0; $cnt < $numberlineArray; $cnt++){
+ if ($cnt > 0) {
+ $str .= ",";
+ }
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[" . $this->pointArray[$cnt]["y"] . "," .
+ $this->pointArray[$cnt]["x"]."]";
+ }
+ else {
+ $str .= "[" . $this->pointArray[$cnt]["x"] . "," .
+ $this->pointArray[$cnt]["y"]."]";
+ }
+ }
+ $str .= "]}";
+
+ }
+ else {
+ $e = new mb_exception("GMLMultiPoint: toGeoJSON: this multiPoint is null.");
+ }
+ return $str;
+ }
+}
+?>
\ No newline at end of file
Modified: branches/2.6/http/classes/class_gml_multipolygon.php
===================================================================
--- branches/2.6/http/classes/class_gml_multipolygon.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_multipolygon.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -147,7 +147,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->polygonArray[$cnt][$i]["y"].",".$this->polygonArray[$cnt][$i]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
+ }
}
$str .= "]";
@@ -157,7 +162,12 @@
if ($j > 0) {
$str .= ",";
}
- $str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->innerRingArray[$cnt][$i][$j]["y"].",".$this->innerRingArray[$cnt][$i][$j]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+ }
}
$str .= "]";
}
Modified: branches/2.6/http/classes/class_gml_point.php
===================================================================
--- branches/2.6/http/classes/class_gml_point.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_point.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -56,7 +56,12 @@
$str = "";
if ($this->point) {
$str .= "{\"type\": \"Point\", \"coordinates\":";
- $str .= "[".$this->point["x"].",".$this->point["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->point["y"].",".$this->point["x"]."]";
+ }
+ else {
+ $str .= "[".$this->point["x"].",".$this->point["y"]."]";
+ }
$str .= "}";
}
else {
Modified: branches/2.6/http/classes/class_gml_polygon.php
===================================================================
--- branches/2.6/http/classes/class_gml_polygon.php 2009-09-17 17:31:58 UTC (rev 4654)
+++ branches/2.6/http/classes/class_gml_polygon.php 2009-09-18 09:34:36 UTC (rev 4655)
@@ -112,7 +112,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->pointArray[$i]["y"].",".$this->pointArray[$i]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
}
$str .= "]";
@@ -122,7 +127,12 @@
if ($j > 0) {
$str .= ",";
}
- $str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+ if (in_array($this->srs, $this->latLonSrs)) {
+ $str .= "[".$this->innerRingArray[$i][$j]["y"].",".$this->innerRingArray[$i][$j]["x"]."]";
+ }
+ else {
+ $str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+ }
}
$str .= "]";
}
More information about the Mapbender_commits
mailing list