[Mapbender-commits] r3048 - branches/beck_dev/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Sep 30 06:44:47 EDT 2008
Author: beck
Date: 2008-09-30 06:44:47 -0400 (Tue, 30 Sep 2008)
New Revision: 3048
Added:
branches/beck_dev/http/classes/class_georss.php
Modified:
branches/beck_dev/http/classes/class_gml2.php
Log:
Added: branches/beck_dev/http/classes/class_georss.php
===================================================================
--- branches/beck_dev/http/classes/class_georss.php (rev 0)
+++ branches/beck_dev/http/classes/class_georss.php 2008-09-30 10:44:47 UTC (rev 3048)
@@ -0,0 +1,203 @@
+<?php
+# $Id: class_gml2.php 2915 2008-09-05 08:16:07Z 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_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml2.php");
+
+class geoRSS {
+ var $doc;
+ var $importItems = array("title","link","description");
+
+ function parseFile($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $data = $x->file;
+ $data = $this->removeWhiteSpace($data);
+ return $this->parseXML($data);
+ #$e = new mb_exception("data = ".$data);
+ }
+
+ /**
+ * Set the Rss Elements that should go to the property tags of geoJSON
+ * default is "title","link" and "description"
+ */
+ public function setImportTags($tags){
+ $importItems = $tags;
+ }
+
+ function parseXML($data) {
+ $this->doc = $data;
+ return $this->toGeoJSON();
+ }
+
+ function removeWhiteSpace ($string) {
+ return preg_replace("/\>(\s)+\</", "><", trim($string));
+ }
+
+ function toGeoJSON () {
+ $rssDoc = new SimpleXMLElement($this->doc);
+
+ $rssDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+ $rssDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+ $rssDoc->registerXPathNamespace('georss', 'http://www.georss.org/georss');
+
+ // build feature collection
+ $featureCollection = new FeatureCollection();
+
+ // elements of rss document
+ $rssItems = $rssDoc->xpath("//item");
+
+ if(count($rssItems)>0){
+ foreach($rssItems as $item){
+ $rssItem_dom = dom_import_simplexml($item);
+
+ $feature = new geoRSSItem();
+ $feature->parse($rssItem_dom, $this->importItems);
+ if (isset($feature->geometry)) {
+ $featureCollection->addFeature($feature);
+ }
+ }
+
+ return $featureCollection->toGeoJSON();
+ }
+ else{
+ return "{'errorMessage':'Kein Ergebnis'}";
+ }
+ }
+}
+
+class geoRSSItem extends Feature{
+ public function parse($domNode, $importItems = array("title","link","description")) {
+ $currentSibling = $domNode->firstChild;
+
+ while ($currentSibling) {
+ $tag = $currentSibling->nodeName;
+ if(in_array($tag, $importItems)){
+ $this->properties[$tag] = $currentSibling->nodeValue;
+ }
+ else{
+ switch ($tag) {
+ case "georss:where":
+ $this->parseGML($currentSibling);
+ break;
+ case "georss:point":
+ $this->geometry = new geoRSSPoint();
+ $this->geometry->parsePoint($currentSibling);
+ break;
+ case "georss:line":
+ $this->geometry = new geoRSSLine();
+ $this->geometry->parseLine($currentSibling);
+ break;
+ case "georss:box":
+ $this->geometry = new geoRSSBox();
+ $this->geometry->parseBox($currentSibling);
+ break;
+ case "georss:polygon":
+ $this->geometry = new geoRSSPolygon();
+ $this->geometry->parsePolygon($currentSibling);
+ break;
+ default:
+ break;
+ }
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+
+ function parseGML($domNode){
+ $currentSibling = $domNode->firstChild;
+
+ while ($currentSibling) {
+ $geomType = $currentSibling->nodeName;
+ switch ($geomType) {
+ case "gml:Polygon" :
+ $this->geometry = new GMLPolygon();
+ $this->geometry->parsePolygon($currentSibling);
+ break;
+ case "gml:LineString" :
+ $this->geometry = new GMLLine();
+ $this->geometry->parseLine($currentSibling);
+ break;
+ case "gml:Point" :
+ $this->geometry = new GMLPoint();
+ $this->geometry->parsePoint($currentSibling);
+ break;
+ case "gml:MultiLineString" :
+ $this->geometry = new GMLMultiLine();
+ $this->geometry->parseMultiLine($currentSibling);
+ break;
+ case "gml:MultiPolygon" :
+ $this->geometry = new GMLMultiPolygon();
+ $this->geometry->parseMultiPolygon($currentSibling);
+ break;
+ default:
+ break;
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+}
+
+class geoRSSPoint extends GMLPoint{
+ public function parsePoint($domNode){
+ list($y, $x) = explode(" ", $domNode->nodeValue);
+ $this->setPoint($x, $y);
+ }
+}
+
+class geoRSSLine extends GMLLine{
+ public function parseLine ($domNode) {
+ $cnt = 0;
+ $y = 0;
+ foreach(explode(' ',$domNode->nodeValue) as $cord){
+ if($cnt % 2)
+ $this->addPoint($cord, $y);
+ $y = $cord;
+ $cnt++;
+ }
+ }
+}
+
+class geoRSSPolygon extends GMLPolygon{
+ public function parsePolygon ($domNode) {
+ $cnt = 0;
+ $y = 0;
+ foreach(explode(' ',$domNode->nodeValue) as $cord){
+ if($cnt % 2)
+ $this->addPoint($cord, $y);
+ $y = $cord;
+ $cnt++;
+ }
+ }
+}
+
+class geoRSSBox extends GMLPolygon{
+ public function parseBox ($domNode) {
+ list($y1,$x1,$y2,$x2) = explode(' ',$domNode->nodeValue);
+ $this->addPoint($x1, $y1);
+ $this->addPoint($x1, $y2);
+ $this->addPoint($x2, $y2);
+ $this->addPoint($x2, $y1);
+ $this->addPoint($x1, $y1);
+ }
+}
+
+?>
\ No newline at end of file
Modified: branches/beck_dev/http/classes/class_gml2.php
===================================================================
--- branches/beck_dev/http/classes/class_gml2.php 2008-09-30 09:16:31 UTC (rev 3047)
+++ branches/beck_dev/http/classes/class_gml2.php 2008-09-30 10:44:47 UTC (rev 3048)
@@ -16,11 +16,11 @@
# 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_connector.php");
-require_once(dirname(__FILE__)."/../classes/class_json.php");
-
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
class gml2 {
var $geomtype_point = 'Point';
var $geomtype_polygon = 'Polygon';
@@ -197,7 +197,7 @@
xml_parser_free($parser);
foreach ($values as $element) {
- #$e = new mb_exception($element[tag]);
+ #$e = new mb_exception($element[tag]);
if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
$boundedBy = true;
}
@@ -359,7 +359,10 @@
elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
$js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
}
- else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
+ else{
+ $e = new mb_notice("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."' or no geometry existing");
+ return "";
+ }
$js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
@@ -428,49 +431,49 @@
return $nodeName;
}
- /**
- * Parses the feature segment of a GML and stores the geometry in the
- * $geometry variable of the class.
- *
- * Example of a feature segment of a GML.
- * <gml:featureMember>
- * <ms:ROUTE fid="ROUTE.228168">
- * <gml:boundedBy>
- * <gml:Box srsName="EPSG:31466">
- * <gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
- * </gml:Box>
- * </gml:boundedBy>
- * <ms:geometry>
- * <gml:LineString>
- * <gml:coordinates>
- * 2557380.97,5562526 2557390.96,
- * 5562523.22 2557404.03,5562518.2 2557422.31,
- * 5562512 2557437.16,5562508.37 2557441.79,
- * 5562507.49 2557454.31,5562505.1 2557464.27,
- * 5562503.97 2557473.24,5562502.97 2557491.67,
- * 5562502.12 2557505.65,5562502.43 2557513.78,
- * 5562501.12 2557520.89,5562498.79 2557528.5,
- * 5562495.07 2557538.9,5562488.91 2557549.5,
- * 5562483.83 2557558.55,5562476.61 2557569.07,
- * 5562469.82 2557576.61,5562462.72 2557582.75,
- * 5562457.92 2557588.57,5562452.56 2557590.38,
- * 5562449.69 2557593.57,5562445.07 2557596.17,
- * 5562441.31 2557601.71,5562433.93 2557612.97,
- * 5562421.03 2557626,5562405.33 2557639.66,
- * 5562389.75 2557653.69,5562371.12
- * </gml:coordinates>
- * </gml:LineString>
- * </ms:geometry>
- * <code>354</code>
- * <Verkehr>0</Verkehr>
- * <rlp>t</rlp>
- * </ms:ROUTE>
- * </gml:featureMember>
- *
- * @return void
- * @param $domNode DOMNodeObject the feature tag of the GML
- * (<gml:featureMember> in the above example)
- */
+ /**
+ * Parses the feature segment of a GML and stores the geometry in the
+ * $geometry variable of the class.
+ *
+ * Example of a feature segment of a GML.
+ * <gml:featureMember>
+ * <ms:ROUTE fid="ROUTE.228168">
+ * <gml:boundedBy>
+ * <gml:Box srsName="EPSG:31466">
+ * <gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
+ * </gml:Box>
+ * </gml:boundedBy>
+ * <ms:geometry>
+ * <gml:LineString>
+ * <gml:coordinates>
+ * 2557380.97,5562526 2557390.96,
+ * 5562523.22 2557404.03,5562518.2 2557422.31,
+ * 5562512 2557437.16,5562508.37 2557441.79,
+ * 5562507.49 2557454.31,5562505.1 2557464.27,
+ * 5562503.97 2557473.24,5562502.97 2557491.67,
+ * 5562502.12 2557505.65,5562502.43 2557513.78,
+ * 5562501.12 2557520.89,5562498.79 2557528.5,
+ * 5562495.07 2557538.9,5562488.91 2557549.5,
+ * 5562483.83 2557558.55,5562476.61 2557569.07,
+ * 5562469.82 2557576.61,5562462.72 2557582.75,
+ * 5562457.92 2557588.57,5562452.56 2557590.38,
+ * 5562449.69 2557593.57,5562445.07 2557596.17,
+ * 5562441.31 2557601.71,5562433.93 2557612.97,
+ * 5562421.03 2557626,5562405.33 2557639.66,
+ * 5562389.75 2557653.69,5562371.12
+ * </gml:coordinates>
+ * </gml:LineString>
+ * </ms:geometry>
+ * <code>354</code>
+ * <Verkehr>0</Verkehr>
+ * <rlp>t</rlp>
+ * </ms:ROUTE>
+ * </gml:featureMember>
+ *
+ * @return void
+ * @param $domNode DOMNodeObject the feature tag of the GML
+ * (<gml:featureMember> in the above example)
+ */
public function parse($domNode) {
$currentSibling = $domNode->firstChild;
@@ -487,12 +490,12 @@
$ns = $namespace['ns'];
$columnName = $namespace['value'];
- // check if this node is a geometry node.
- // however, even if it is a property node,
- // it has a child node, the text node!
- // So we might need to do something more
- // sophisticated here...
- if ($currentSibling->hasChildNodes()){
+ // check if this node is a geometry node.
+ // however, even if it is a property node,
+ // it has a child node, the text node!
+ // So we might need to do something more
+ // sophisticated here...
+ if ($currentSibling->hasChildNodes()){
$geomNode = $currentSibling->firstChild;
$geomType = $geomNode->nodeName;
switch ($geomType) {
@@ -516,13 +519,13 @@
$this->geometry = new GMLMultiPolygon();
$this->geometry->parseMultiPolygon($geomNode);
break;
- default:
- $this->properties[$columnName] = $value;
- break;
+ default:
+ $this->properties[$columnName] = $value;
+ break;
}
- }
- else {
- $this->properties[$columnName] = $value;
+ }
+ else {
+ $this->properties[$columnName] = $value;
}
$currentSibling = $currentSibling->nextSibling;
@@ -549,7 +552,7 @@
$cnt ++;
}
- $json = new Mapbender_JSON();
+ $json = new Mapbender_JSON();
$str .= $json->encode($prop);
$str .= "}";
@@ -577,7 +580,7 @@
}
}
- private function addPoint ($x, $y) {
+ protected function addPoint ($x, $y) {
array_push($this->pointArray, array("x" => $x, "y" => $y));
}
@@ -618,7 +621,7 @@
}
}
- private function setPoint ($x, $y) {
+ protected function setPoint ($x, $y) {
# echo "x: " . $x . " y: " . $y . "\n";
$this->point = array("x" => $x, "y" => $y);
}
@@ -672,7 +675,7 @@
}
- private function addPoint ($x, $y) {
+ protected function addPoint ($x, $y) {
array_push($this->pointArray, array("x" => $x, "y" => $y));
}
@@ -732,7 +735,7 @@
}
- private function addPoint ($x, $y, $i) {
+ protected function addPoint ($x, $y, $i) {
array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
}
@@ -804,7 +807,7 @@
}
- private function addPoint ($x, $y, $i) {
+ protected function addPoint ($x, $y, $i) {
array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
}
More information about the Mapbender_commits
mailing list