[Mapbender-commits] r1949 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jan 4 11:32:18 EST 2008


Author: christoph
Date: 2008-01-04 11:32:18 -0500 (Fri, 04 Jan 2008)
New Revision: 1949

Added:
   trunk/mapbender/http/classes/class_kml_geometry.php
   trunk/mapbender/http/classes/class_kml_line.php
   trunk/mapbender/http/classes/class_kml_linearring.php
   trunk/mapbender/http/classes/class_kml_multigeometry.php
   trunk/mapbender/http/classes/class_kml_parser_2.2.php
   trunk/mapbender/http/classes/class_kml_parser_ows.php
   trunk/mapbender/http/classes/class_kml_placemark.php
   trunk/mapbender/http/php/mb_listKMLs.php
   trunk/mapbender/http/php/mod_displayKML.php
   trunk/mapbender/http/php/mod_updateKmlInDb.php
Modified:
   trunk/mapbender/http/classes/class_kml_ows.php
   trunk/mapbender/http/classes/class_kml_point.php
   trunk/mapbender/http/classes/class_kml_polygon.php
Log:
kml classes and files

Added: trunk/mapbender/http/classes/class_kml_geometry.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_geometry.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_geometry.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,56 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+
+require_once("../classes/class_kml_polygon.php");
+require_once("../classes/class_kml_linearring.php");
+require_once("../classes/class_kml_line.php");
+require_once("../classes/class_kml_point.php");
+require_once("../classes/class_kml_multigeometry.php");
+
+/**
+ * An abstract class representing a geometry, which is any of the following:
+ * {@link KMLPoint}, {@link KMLPolygon}, {@link KMLLine} or 
+ * {@link KMLMultiGeometry}
+ *
+ * @package KML 
+ * @abstract
+ */
+abstract class KMLGeometry {
+
+	/**
+	 * @param  object $obj 	an object.
+	 * @return bool			true, if the object is of type {@link KMLLine},
+	 * 						{@link KMLPoint}, {@link KMLPolygon} or
+	 * 						{@link KMLMultiGeometry}, or instance of 
+	 * 						another class extending KMLGeometry.
+	 */
+	protected function isGeometry($obj) {
+		if ($obj instanceof KMLGeometry) {
+			return true;
+		}
+		
+		//TODO: not sure if this type determination works
+		$type = get_class($obj) || gettype($obj);
+		$e = new mb_warning("class_kml_geometry.php: isGeometry: not a geometry, but " . $type);
+		return false;
+	}
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_geometry.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_line.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_line.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,100 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_geometry.php");
+
+/**
+ * Represents a line string, consisting of an array of points.
+ *  
+ * @package KML 
+ */
+class KMLLine extends KMLGeometry {
+	/**
+	 * @param string the content of the geometry tag of a KML. Note: KML 2.2 uses a 
+	 *               comma separated list, while KML OWS uses the GML syntax with 
+	 *               blanks as separators 
+	 */
+	public function __construct ($geometryString) {
+		# KML 2.2
+		if (preg_match("/,/", $geometryString)) {
+			$pointArray = explode(" ", $geometryString);
+			for ($i=0; $i < count($pointArray); $i++) {
+				#
+				# Some KMLs have a lot of whitespaces; this "if" is an
+				# ugly hack to prevent adding empty points
+				#
+				if (preg_match("/,/", $pointArray[$i])) {
+					$aPoint = explode(",", $pointArray[$i]);
+					# ignore altitude
+					$point = array("x" => $aPoint[0], "y" => $aPoint[1]);
+					array_push($this->pointArray, $point);
+				}
+			}
+		}
+		else {
+			$pointArray = explode(" ", $geometryString);
+			for ($i=0; $i < count($pointArray); $i+=2) {
+				#
+				# Some KMLs have a lot of whitespaces; this "if" is an
+				# ugly hack to prevent adding empty points
+				#
+				if ($pointArray[$i] && $pointArray[$i+1]) {
+					# ignore altitude
+					$point = array("x" => $pointArray[$i], "y" => $pointArray[$i+1]);
+					array_push($this->pointArray, $point);
+				}
+			}
+		}
+	}
+
+	/**
+	 * @return string a string representation of the object, currently geoJSON.
+	 */
+	public function __toString() {
+		return $this->toGeoJSON();
+	}
+
+	/**
+	 * @return string a geoJSON string representation of the object.
+	 */
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		if ($numberOfPoints > 0) {
+			$str = "";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			return "{\"type\": \"LineString\", \"coordinates\":[" . $str . "]}";
+		}
+
+		$e = new mb_exception("KMLLine: toGeoJSON: this line has no points.");
+		return "";
+	}
+
+	/**
+	 * An array of points, with a point being an associative 
+	 * array consisting of attributes "x" and "y".
+	 */
+	protected $pointArray = array();
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_line.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_linearring.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_linearring.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_linearring.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,53 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_line.php");
+
+/**
+ * Represents a linear ring, consisting of an array of points. 
+ * The first and last point must be identical (no validation up to now)
+ * 
+ * @package KML 
+ */
+class KMLLinearRing extends KMLLine {
+
+	/**
+	 * The only difference from the method of the super class is the exception.
+	 * 
+	 * @return string a geoJSON string representation of the object.
+	 */
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		if ($numberOfPoints > 0) {
+			$str = "";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			return "[" . $str . "]";
+		}
+
+		$e = new mb_exception("KMLLinearRing: toGeoJSON: no points in this linear ring.");
+		return "";
+	}
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_linearring.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_multigeometry.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_multigeometry.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_multigeometry.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,82 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_geometry.php");
+
+/**
+ * Represents a multi geometry, consisting of an array of geometries 
+ * ({@link KMLPoint}, {@link KMLPolygon}, {@link KMLLine} and 
+ * {@link KMLMultiGeometry} allowed)
+ * 
+ * @package KML
+ */
+class KMLMultiGeometry extends KMLGeometry {
+	
+	/**
+	 * Creates an empty multi geometry. Geometries may be added via {@link KMLMultiGeometry::append()}.
+	 */
+	public function __construct () {
+	}
+	
+	/**
+	 * @return string a string representation of the object, currently geoJSON.
+	 */
+	public function __toString() {
+		return $this->toGeoJSON();
+	}
+	
+	/**
+	 * @return string a geoJSON string representation of the object.
+	 */
+	public function toGeoJSON () {
+		$numberOfGeometries = count($this->geometryArray);
+		if ($numberOfGeometries > 0) {
+			$str = "";
+			for ($i=0; $i < $numberOfGeometries; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= $this->geometryArray[$i]->toGeoJSON();
+			}
+			return "{\"type\": \"GeometryCollection\", \"geometries\": [" . $str . "]}";
+		}
+
+		$e = new mb_exception("KMLMultiGeometry: toGeoJSON: this geometryArray is empty.");
+		return "";
+	}
+
+	/**
+	 * Appends a new geometry to this multi geometry.
+	 * 
+	 * @param  object	$aGeometry 	should be of type {@link KMLLine}, {@link KMLPoint}, 
+	 * 								{@link KMLPolygon} or {@link KMLMultiGeometry}. 
+	 * @return bool		true, if appending the geometry succeeded; else false.
+	 */
+	public function append ($aGeometry) {
+		if ($this->isGeometry($aGeometry)) {
+			array_push($this->geometryArray, $aGeometry);
+			return true;
+		}
+		return false;
+	}
+
+	private $geometryArray = array();
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_multigeometry.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php	2008-01-03 16:35:29 UTC (rev 1948)
+++ trunk/mapbender/http/classes/class_kml_ows.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -1,5 +1,5 @@
 <?php
-# $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $
+# $Id$
 # http://www.mapbender.org/index.php/class_wmc.php
 # Copyright (C) 2002 CCGIS 
 #
@@ -21,428 +21,126 @@
 mb_internal_encoding("UTF-8");
 
 require_once("../../conf/mapbender.conf");
-require_once("../classes/class_mb_exception.php");
 require_once("../extensions/JSON.php");
+require_once("../classes/class_mb_exception.php");
 
-/**
- * Represents a polygon, consisting of 1 outerboundary and 0..n inner boundaries 
- */
-class KMLPolygon {
-	var $outerBoundary;
-	var $innerBoundaryArray = array();
-	
-	public function __construct ($aLinearRing) {
-		$this->outerBoundary = $aLinearRing;
-	}
+require_once("../classes/class_kml_geometry.php");
+require_once("../classes/class_kml_placemark.php");
+require_once("../classes/class_kml_parser_ows.php");
 
-	public function __toString() {
-		$str = "Polygon:\n";
-		$str .= "OuterBoundary:\n" . $this->outerBoundary;
-		for ($i=0; $i < count($this->innerBoundaryArray); $i++) {
-			$str .= "InnerBoundary #" . $i . ":\n";
-			$str .= $this->innerBoundaryArray[$i];
-		}
-		return $str;
-	}
-	
-	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
-	 * 
-	 * This should be replaced by something JSON-like in the future.
-	 */
-	public function toGeoJSON () {
-		$str = "";
-		if ($this->outerBoundary !== null) {
-			$str .= "{\"type\": \"Polygon\", \"coordinates\": [";
-			$str .= $this->outerBoundary->toGeoJSON();
-			
-			$numberOfInnerBoundaries = count($this->innerBoundaryArray);
-			if ($numberOfInnerBoundaries > 0) {
-				$str .= ", ";
-				for ($i=0; $i < $numberOfInnerBoundaries; $i++) {
-					if ($i > 0) {
-						$str .= ",";
-					}
-					$str .= $this->innerBoundaryArray[$i]->toGeoJSON();
-				}
-			}
-			$str .= "]";
-			$str .= "}";
-		}
-		else {
-			$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
-		}
-		return $str;
-	}
-
-	public function appendInnerBoundary ($aLinearRing) {
-		array_push($this->innerBoundaryArray, $aLinearRing);
-	}
-}
-
 /**
- * Represents a linear ring, consisting of an array of points. 
- * I guess the first and last point must be identical.
+ * Allows parsing a KML file, extracting the placemarks.
+ * 
+ * @package KML
  */
-class KMLLinearRing {
-	var $pointArray = array();
-	
-	public function __construct ($geometryString) {
-		// KML 2.2
-		if (preg_match("/,/", $geometryString)) {
-			$pointArray = explode(" ", $geometryString);
-			for ($i=0; $i < count($pointArray); $i++) {
-				/*
-				 * Some KMLs have a lot of whitespaces; this "if" is an
-				 * ugly hack to prevent adding empty points
-				 */
-				if (preg_match("/,/", $pointArray[$i])) {
-					$aPoint = explode(",", $pointArray[$i]);
-					// ignore altitude
-					$point = array("x" => $aPoint[0], "y" => $aPoint[1]);
-					array_push($this->pointArray, $point);
-				}
-			}
-		}
-		else {
-			$pointArray = explode(" ", $geometryString);
-			for ($i=0; $i < count($pointArray); $i+=2) {
-				/*
-				 * Some KMLs have a lot of whitespaces; this "if" is an
-				 * ugly hack to prevent adding empty points
-				 */
-				if ($pointArray[$i] && $pointArray[$i+1]) {
-					// ignore altitude
-					$point = array("x" => $pointArray[$i], "y" => $pointArray[$i+1]);
-					array_push($this->pointArray, $point);
-				}
-			}
-		}
-	}
+class KML {
 
-	public function __toString() {
-		$str = "LinearRing:\n";
-		for ($i=0; $i < count($this->pointArray); $i++) {
-			$str .= "Point #" . $i . ": (" . $this->pointArray[$i]["x"] . ", " . $this->pointArray[$i]["y"] . ")\n";
-		}
-		return $str;
-	}
+	//
+	//
+	// ------------------------------- public -----------------------------------------------
+	//
+	//
 
 	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
-	 * 
-	 * This should be replaced by something JSON-like in the future.
-	 */
-	public function toGeoJSON () {
-		$numberOfPoints = count($this->pointArray);
-		$str = "";
-		if ($numberOfPoints > 0) {
-			$str .= "[";
-			for ($i=0; $i < $numberOfPoints; $i++) {
-				if ($i > 0) {
-					$str .= ",";
-				}
-				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
-			}
-			$str .= "]";
-		}
-		else {
-			$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
-		}
-		return $str;
-	}
-}
+	 * The constructor function, currently empty.
+	 */				
+	public function __construct() {
+	} 
 
-/**
- * Represents a linestring, consisting of an array of points. 
- */
-class KMLLine {
-	var $pointArray = array();
-	
-	public function __construct ($geometryString) {
-		// KML 2.2
-		if (preg_match("/,/", $geometryString)) {
-			$pointArray = explode(" ", $geometryString);
-			for ($i=0; $i < count($pointArray); $i++) {
-				/*
-				 * Some KMLs have a lot of whitespaces; this "if" is an
-				 * ugly hack to prevent adding empty points
-				 */
-				if (preg_match("/,/", $pointArray[$i])) {
-					$aPoint = explode(",", $pointArray[$i]);
-					// ignore altitude
-					$point = array("x" => $aPoint[0], "y" => $aPoint[1]);
-					array_push($this->pointArray, $point);
-				}
-			}
-		}
-		else {
-			$pointArray = explode(" ", $geometryString);
-			for ($i=0; $i < count($pointArray); $i+=2) {
-				/*
-				 * Some KMLs have a lot of whitespaces; this "if" is an
-				 * ugly hack to prevent adding empty points
-				 */
-				if ($pointArray[$i] && $pointArray[$i+1]) {
-					// ignore altitude
-					$point = array("x" => $pointArray[$i], "y" => $pointArray[$i+1]);
-					array_push($this->pointArray, $point);
-				}
-			}
-		}
-	}
-
-	public function __toString() {
-		$str = "LineString:\n";
-		for ($i=0; $i < count($this->pointArray); $i++) {
-			$str .= "Point #" . $i . ": (" . $this->pointArray[$i]["x"] . ", " . $this->pointArray[$i]["y"] . ")\n";
-		}
-		return $str;
-	}
-
 	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
-	 * 
-	 * This should be replaced by something JSON-like in the future.
+	 * @return string the KML document.
 	 */
-	public function toGeoJSON () {
-		$numberOfPoints = count($this->pointArray);
-		$str = "";
-		if ($numberOfPoints > 0) {
-			$str .= "{\"type\": \"LineString\", \"coordinates\":[";
-			for ($i=0; $i < $numberOfPoints; $i++) {
-				if ($i > 0) {
-					$str .= ",";
-				}
-				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
-			}
-			$str .= "]}";
-		}
-		else {
-			$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
-		}
-		return $str;
-	}
-}
-
-/**
- * Represents a point, consisting of a single point geometry. 
- */
-class KMLPoint {
-	var $point;
-	
-	public function __construct ($geometryString) {
-		// KML 2.2
-		if (preg_match("/,/", $geometryString)) {
-			$aPoint = explode(",", $geometryString);
-			// ignore altitude
-			$this->point = array("x" => $aPoint[0], "y" => $aPoint[1]);
-		}
-		else {
-			$aPoint = explode(" ", $geometryString);
-			// ignore altitude
-			$this->point = array("x" => $aPoint[0], "y" => $aPoint[1]);
-		}
-	}
-
 	public function __toString() {
-		$str = "Point: (" . $this->point["x"] . ", " . $this->point["y"] . ")\n";
-		return $str;
-	}
 
-	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
-	 * 
-	 * This should be replaced by something JSON-like in the future.
-	 */
-	public function toGeoJSON () {
-		$str = "";
-		if ($this->point !== null) {
-			$str .= "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"]."]}";
-		}
-		else {
-			$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
-		}
-		return $str;
-	}
-}
-
-/**
- * Represents a multigeometry, consisting of an array of geometries 
- * (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry allowed)
- */
-class KMLMultiGeometry {
-	var $geometryArray = array();
+		if (!$this->kml) {
+			$doc = new DOMDocument("1.0", CHARSET);
+			$doc->preserveWhiteSpace = false;
 	
-	public function __construct () {
-		
-	}
+			// attach kml and Document tag
+			$e_kml = $doc->createElementNS("http://earth.google.com/kml/2.2", "kml");
+			$e_document = $doc->createElement("Document");
+			$e_kml->appendChild($e_document);
+			$doc->appendChild($e_kml);
 	
-	public function __toString() {
-		$str = "";
-		for ($i=0; $i < count($this->geometryArray); $i++) {
-			$str .= "Geometry #" . $i . ":\n" . $this->geometryArray[$i];
+			// attach placemarks
+			
+			$this->kml = $doc->saveXML();
 		}
-		return $str;
+		return $this->kml;
 	}
 	
 	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
-	 * TODO: RETURNS "", AS NOT IMPLEMENTED IN geometry.js!!!!!!!!!!!!!!!!!
+	 * parses an incoming KML, creates the object, 
+	 * stores the kml in the object and in the database.
+	 * 
+	 * @param  string  a KML document.
+	 * @return boolean true if the parsing succeded, else false.
 	 */
-	public function toGeoJSON () {
-		$str = "";
-		$numberOfGeometries = count($this->geometryArray);
-		if ($numberOfGeometries > 0) {
-			$str .= "{\"type\": \"GeometryCollection\", \"geometries\": [";
-			for ($i=0; $i < $numberOfGeometries; $i++) {
-				if ($i > 0) {
-					$str .= ",";
-				}
-				$str .= $this->geometryArray[$i]->toGeoJSON();
-			}
-			$str .= "]}";
-			return $str;
+	public function parseKml ($kml) {
+		$this->kml = $kml;
+
+		if (!$this->storeInDb()) {
+			return false;
 		}
-		else {
-			$e = new mb_exception("KMLMultiGeometry: toGeoJSON: this geometryArray is empty.");
-		}
-		return $str;;
-	}
 
-	public function append ($aGeometry) {
-		array_push($this->geometryArray, $aGeometry);
-	}
-}
+		$parser = new KmlOwsParser($kml, $this->id);
+		$this->placemarkArray = $parser->placemarkArray; 
 
-/**
- * A Placemark consists of a geometry
- * (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry allowed)
- */
-class KMLPlacemark {
-	var $geometry;
-	private $properties = array();
-
-	public function __construct ($aGeometry) {
-		$this->geometry = $aGeometry;
+		return true;
 	}
 	
-	public function __toString () {
-		return "" . $this->geometry; 
-	}
-	
 	/**
-	 * deprecated
+	 * parses an incoming GeoJSON, creates the object, 
+	 * stores the kml in the object and in the database.
+	 * 
+	 * @param string a geoJSON.
+	 * @return boolean true if the parsing succeded, else false.
 	 */
-	public function getName () {
-		return $this->name;
-	}
-	
-	/**
-	 * deprecated
-	 */
-	public function setName ($aName) {
-		$this->name = $aName;
-	}
+	public function parseGeoJSON ($geoJSON) {
+		$parser = new KmlOwsParser($geoJSON);
+		$this->placemarkArray = $parser->placemarkArray; 
+		
+		$this->kml = $this->__toString();
 
-	public function setProperty ($key, $value) {
-		// TODO: keys are unique, may be not intended in KML OWS5
-		$this->properties[$key] = $value;
+		if (!$this->storeInDb()) {
+			return false;
+		}
+		return true;
 	}
 	
-	public function getProperties () {
-		return $this->properties;
-	}	
-	
 	/**
-	 * Exports the geometry to a JS format (geometryArray), see geometry.js
+	 * @return string the geoJSON representation of the KML.
 	 */
-	public function toGeoJSON () {
+	public function toGeoJSON() {
 		$str = "";
-		if ($this->geometry !== null) {
-			$str .= "{\"type\":\"Feature\", \"id\":\"id". time() ."\", ";
-			$str .= "\"geometry\": ";
-			$str .= $this->geometry->toGeoJSON();
-			$str .= ", \"properties\": {";
-			$cnt = 0;
-			foreach ($this->properties as $key => $value) {
-				if ($cnt > 0) {
+		$numberOfPlacemarks = count($this->placemarkArray);
+		if ($numberOfPlacemarks > 0) {
+			$str .= "{\"type\": \"FeatureCollection\", \"features\": [";
+			for ($i=0; $i < $numberOfPlacemarks; $i++) {
+				if ($i > 0) {
 					$str .= ",";
-				}
-				$str .= "\"" . $key . "\":\"" . $value . "\"";
-				$cnt ++;
+				}	
+				$str .= $this->placemarkArray[$i]->toGeoJSON();
 			}
-			$str .= "}}";
+			$str .= "]}";
 		}
 		else {
-			$e = new mb_exception("KMLPlacemark: toGeoJSON: this geometry is null!");
+			$e = new mb_exception("KML: toGeoJSON: this placemarkArray is empty!");
 		}
 		return $str;
 	}
-}
 
-/**
- * Allows parsing a KML file, extracting the placemarks.
- */
-class KML {
-
-	var $kml;
-	var $id;
-	var $placemarkArray = array();
-					
-	public function __construct() {
-	} 
-
-	/**
-	 * parses an incoming KML and stores it in the database
-	 */
-	public function parseKml ($kml) {
-		$this->kml = $kml;
-		
-		if (!$this->storeInDb()) {
-			return false;
-		}
-		$this->createObjFromKML($kml);
-		return true;
-	}
-	
-	public function getKmlDocument ($kmlId) {
-		$con = db_connect(DBSERVER,OWNER,PW);
-		db_select_db(DB,$con);
-		//get KML from database (check if user is allowed to access)
-# for now, do not restrict access 
-#		$sql = "SELECT kml_doc FROM gui_kml WHERE kml_id = $1 AND fkey_mb_user_id = $2 AND fkey_gui_id = $3 LIMIT 1";
-		$sql = "SELECT kml_doc FROM gui_kml WHERE kml_id = $1 LIMIT 1";
-#		$v = array($kmlId, $_SESSION["mb_user_id"], $_SESSION["mb_user_gui"]);
-#		$t = array("i", "i", "s");
-		$v = array($kmlId);
-		$t = array("i");
-		$result = db_prep_query($sql, $v, $t);
-		$row = db_fetch_array($result);
-		if ($row) {
-			return $row["kml_doc"];
-		}
-		return null;
-	}
-	
 	public function updateKml ($kmlId, $placemarkId, $geoJSON) {
-		$kmlFromDb = $this->getKmlDocument($kmlId);
+		$kmlFromDb = $this->getKmlDocumentFromDB($kmlId);
 		 
 		if ($kmlFromDb !== NULL) {
 			// load the KML from the database in the DOM object
-#			$kmlDoc = simplexml_load_string($kmlFromDb);			
 			$kmlDoc_DOM = new DOMDocument("1.0");
 			$kmlDoc_DOM->encoding = CHARSET;
 			$kmlDoc_DOM->preserveWhiteSpace = false;
 			$kmlDoc_DOM->loadXML($kmlFromDb); 
 
-#			$e = new mb_exception("xmlBEGIN:" . $kmlFromDb . ":xmlEND");
-#			echo CHARSET;
-#			echo "...." . $kmlFromDb . "....";
-#			print_r($kmlDoc);
-#			print_r($kmlDoc_DOM);die;
-
-			//gload ihe geoJSON
+			//load the geoJSON
 			$json = new Services_JSON();
 			$geoObj = $json->decode($geoJSON);
 
@@ -467,12 +165,9 @@
 			// apply the changes
 			//
 			
-#			$currentPlacemarkArray = $kmlDoc->xpath("//Placemark");
 			$currentPlacemarkArray = $kmlDoc_DOM->getElementsByTagName("Placemark");
-#			$currentPlacemark = $currentPlacemarkArray[$placemarkId]; 
 			$currentPlacemark = $currentPlacemarkArray->item($placemarkId);
 
-			#print_r($currentPlacemark);die;
 			if ($currentPlacemark) {
 				$metadataUpdateSuccessful = $this->updateMetadata($currentPlacemark, $metadataObj);
 				$geometryUpdateSuccessful = $this->updateGeometries($currentPlacemark, $geometryArray);
@@ -511,14 +206,76 @@
 		return true;
 	}
 
+	//
+	//
+	// ------------------------------- private -----------------------------------------------
+	//
+	//
+		
+	/**
+	 * Store this KML in the database, and sets the ID.
+	 * 
+	 * @return boolean true, if the KML could be stored in the database; else false.
+	 */
+	private function storeInDb () {
+		$con = db_connect(DBSERVER,OWNER,PW);
+		db_select_db(DB,$con);
+
+		$sql  = "INSERT INTO gui_kml ";
+		$sql .= "(fkey_mb_user_id, fkey_gui_id, kml_doc, kml_name, kml_description, kml_timestamp) ";
+		$sql .= "VALUES ";
+		$sql .= "($1, $2, $3, $4, $5, $6)";
+		$v = array ($_SESSION["mb_user_id"], $_SESSION["mb_user_gui"], $this->kml, "name", "description", time());
+		$t = array ("i", "s", "s", "s", "s", "s");
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			$e = new mb_exception("class_kml.php: storeInDb: failed to store KML in database: " . db_error());
+			return false;
+		}
+
+		$this->id = db_insert_id($con, "gui_kml", "kml_id");
+		return true;
+	}
+
+	/**
+	 * @param  integer  the ID of the KML.
+	 * @return string   the KML document with the given ID.
+	 */
+	public function getKmlDocumentFromDB ($kmlId) {
+		$con = db_connect(DBSERVER,OWNER,PW);
+		db_select_db(DB,$con);
+		//get KML from database (check if user is allowed to access)
+
+# for now, do not restrict access 
+#		$sql = "SELECT kml_doc FROM gui_kml WHERE kml_id = $1 AND fkey_mb_user_id = $2 AND fkey_gui_id = $3 LIMIT 1";
+#		$v = array($kmlId, $_SESSION["mb_user_id"], $_SESSION["mb_user_gui"]);
+#		$t = array("i", "i", "s");
+
+		$sql = "SELECT kml_doc FROM gui_kml WHERE kml_id = $1 LIMIT 1";
+		$v = array($kmlId);
+		$t = array("i");
+
+		$result = db_prep_query($sql, $v, $t);
+		$row = db_fetch_array($result);
+		if ($row) {
+			return $row["kml_doc"];
+		}
+		else {
+			$e = new mb_exception("class_kml.php: getKMLDocumentFromDB: no KML found for ID " . $kmlId);
+		}
+		return "";
+	}
+
+	/**
+	 * @param  string the tag name.
+	 * @return string the tag name without its namespace.
+	 */
 	private function sepNameSpace($s){
-		$c = mb_strpos($s,":"); 
-		if($c>0){
-			return mb_substr($s,$c+1);
+		$c = mb_strpos($s, ":"); 
+		if ($c > 0) {
+			$s = mb_substr($s, $c+1);
 		}
-		else{
-			return $s;
-		}		
+		return $s;
 	}
 
 	private function updateGeometries($currentPlacemark, $geometryArray) {
@@ -558,12 +315,10 @@
 			$kmlNode = $currentNode_SimpleXML->{"outerBoundaryIs"}->{"LinearRing"}->{"coordinates"};
 			if ($gmlNode->asXML()) {
 				$currentNode_SimpleXML->{"exterior"}->{"LinearRing"}->{"posList"} = preg_replace("/,/", " ", preg_replace("/\[|\]/", "", $json->encode($geometry->coordinates)));
-#				echo "updated polygon (KML OWS)\n";
 			}
 			// KML 2.2
 			else if ($kmlNode->asXML()) {
 				$currentNode_SimpleXML->{"outerBoundaryIs"}->{"LinearRing"}->{"coordinates"} = preg_replace("/\],/", " ", preg_replace("/\][^,]|\[/", "", $json->encode($geometry->coordinates)));
-#				echo "updated polygon (KML 2.2)\n";
 			}
 		}
 		elseif ($currentTypeXml == "POINT") {
@@ -573,14 +328,10 @@
 			// GML 3
 			if ($gmlNode->asXML()) {
 				$currentNode_SimpleXML->{"pos"} = preg_replace("/,/", " ", preg_replace("/\[|\]/", "", $json->encode($geometry->coordinates)));
-#				$nodeInDom = dom_import_simplexml($currentNode_SimpleXML->{"pos"});
-#				echo "nodevalue pre:" . $nodeInDom->nodeValue;
-#				echo "updated point (KML OWS)\n";
 			}
 			// KML 2.2
 			else if ($kmlNode->asXML()) {
 				$currentNode_SimpleXML->{"coordinates"} = preg_replace("/\[|\]/", "", $json->encode($geometry->coordinates));
-#				echo "updated point (KML 2.2)\n";
 			}
 		}
 		elseif ($currentTypeXml == "LINESTRING") {
@@ -590,12 +341,10 @@
 			// GML 3
 			if ($gmlNode->asXML()) {
 				$currentNode_SimpleXML->{"posList"} = preg_replace("/,/", " ", preg_replace("/\[|\]/", "", $json->encode($geometry->coordinates)));
-#				echo "updated linestring (KML OWS)\n";
 			}
 			// KML 2.2
 			else if ($kmlNode->asXML()) {
 				$currentNode_SimpleXML->{"coordinates"} = preg_replace("/\[|\]/", "", $json->encode($geometry->coordinates));
-#				echo "updated linestring (KML 2.2)\n";
 			}
 		}
 		return true;
@@ -603,27 +352,17 @@
 
 	private function updateMetadata($currentPlacemark, $metadataObj) {
 		$currentPlacemark_SimpleXML = simplexml_import_dom($currentPlacemark);
-#		print_r($currentPlacemark_SimpleXML);
 		$extendedDataNode = $currentPlacemark_SimpleXML->{"ExtendedData"};
-#		print_r($extendedDataNode);die;
 		if ($extendedDataNode) {
-#echo "extended data\n";
 			// Either, data is within a SCHEMADATA tag...
 			$simpleDataNodes = $extendedDataNode->{"SchemaData"}->{"SimpleData"};
 			if ($simpleDataNodes) {
-#				print_r($simpleDataNodes);
 				foreach ($simpleDataNodes as $simpleDataNode) {
 					$tmp = dom_import_simplexml($simpleDataNode);					
 					$name = $tmp->getAttribute("name");
-#$name = $simpleDataNode->attributes()->name;
-#print_r($simpleDataNode);
-#echo "attrib: " . $simpleDataNode->attributes() . "\n";
-#echo "name: " . $name . "\n";
 					// if there is a metadata entry, update it
 					if (isset($metadataObj->$name)) {
-#						$tmp = dom_import_simplexml($simpleDataNode);
 						$tmp->nodeValue = $metadataObj->$name;
-#echo "setting: " . $tmp->nodeValue . "\n";
 					}										
 				}
 			}
@@ -631,513 +370,33 @@
 			// ...or within a DATA tag
 			$dataNodes = $extendedDataNode->{"Data"};
 			if ($dataNodes) {
-#				print_r($metadataObj);
-#echo "data nodes\n";
 				foreach ($dataNodes as $dataNode) {
 					$tmp = dom_import_simplexml($dataNode);
 					$name = $tmp->getAttribute("name");
-#echo "data node: " . $name . "\n";
 					// if there is a metadata entry, update it
 					if (isset($metadataObj->$name)) {
 						$tmp->nodeValue = $metadataObj->$name;
-#echo "set to " . $dataNode->nodeValue . "\n";
 					}										
 				}
 			}
 			return true;
 		}
-#		echo "false";
 		return false;
 	}
-	
-	/**
-	 * Store this KML in the database.
-	 */
-	private function storeInDb () {
-		$con = db_connect(DBSERVER,OWNER,PW);
-		db_select_db(DB,$con);
 
-		$sql  = "INSERT INTO gui_kml ";
-		$sql .= "(fkey_mb_user_id, fkey_gui_id, kml_doc, kml_name, kml_description, kml_timestamp) ";
-		$sql .= "VALUES ";
-		$sql .= "($1, $2, $3, $4, $5, $6)";
-		$v = array ($_SESSION["mb_user_id"], $_SESSION["mb_user_gui"], $this->kml, "name", "description", time());
-		$t = array ("i", "s", "s", "s", "s", "s");
-		$res = db_prep_query($sql, $v, $t);
-		if (!$res) {
-			$e = new mb_exception("class_kml.php: storeInDb: failed to store KML in database: " . db_error());
-			return false;
-		}
-
-		$this->id = db_insert_id($con, "gui_kml", "kml_id");
-		return true;
-	}
-
-	public function __toString() {
-		$str = "";
-		for ($i=0; $i < count($this->placemarkArray); $i++) {
-			$str .= "Placemark #" . $i . ":\n " . $this->placemarkArray[$i] . "\n\n"; 
-		}
-		return $str;
-	}
-	
-	public function toGeoJSON() {
-		$str = "";
-		$numberOfPlacemarks = count($this->placemarkArray);
-		if ($numberOfPlacemarks > 0) {
-			$str .= "{\"type\": \"FeatureCollection\", \"features\": [";
-			for ($i=0; $i < $numberOfPlacemarks; $i++) {
-				if ($i > 0) {
-					$str .= ",";
-				}	
-				$str .= $this->placemarkArray[$i]->toGeoJSON();
-			}
-			$str .= "]}";
-		}
-		else {
-			$e = new mb_exception("KML: toGeoJSON: this placemarkArray is empty!");
-		}
-		return $str;
-	}
-
 	/**
-	 * Parses the given KML and extracts its placemarks 
+	 * The KML document.
 	 */
-	private function createObjFromKML() {
-		$parser = new KmlOwsParser($this);
-		$this->placemarkArray = $parser->placemarkArray; 
-		return true;
-	}
-
-/*	
-	function createObjFromDB($kml_id) {
-		$this->kml_id = $kml_id;
-
-		$sql = "SELECT kml FROM mb_meetingpoint WHERE mb_meetingpoint_id = $1";
-		$v = array($kml_id);
-		$t = array('s');
-		$res = db_prep_query($sql, $v, $t);
-		$row = db_fetch_array($res);
-		return $this->createObjFromKML($row['kml']);
-	}
-
-	function createKMLFromObj(){
-		$kml = "";
-		$kml .= "<?xml version=\"1.0\" encoding=\"".CHARSET."\"?>\n";
-		$kml .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n";
-		$kml .= "<Placemark>\n";
-		$kml .= "\t<description>" . $this->description . "</description>\n";
-		$kml .= "\t<name>" . $this->title . "</name>\n";
-		$kml .= "\t<LookAt>\n";
-		$kml .= "\t\t<longitude>" . $this->x . "</longitude>\n";
-		$kml .= "\t\t<latitude>" . $this->y . "</latitude>\n";
-		$kml .= "\t\t<range>" . $this->lookAt_range . "</range>\n";
-		$kml .= "\t\t<tilt>" . $this->lookAt_tilt . "</tilt>\n";
-		$kml .= "\t\t<heading>" . $this->lookAt_heading . "</heading>\n";
-		$kml .= "\t</LookAt>\n";
-		$kml .= "\t<visibility>0</visibility>\n";
-		$kml .= "\t<Style>\n";
-		$kml .= "\t\t<IconStyle>\n";
-		$kml .= "\t\t\t<Icon>\n";
-		$kml .= "\t\t\t\t<href>" . $this->icon . "</href>\n";
-		$kml .= "\t\t\t</Icon>\n";
-		$kml .= "\t\t</IconStyle>\n";
-		$kml .= "\t</Style>\n";
-		$kml .= "\t<Point>\n";
-		$kml .= "\t\t<extrude>1</extrude>\n";
-		$kml .= "\t\t<coordinates>" . $this->x . "," . $this->y . "</coordinates>\n";
-		$kml .= "\t</Point>\n";
-		$kml .= "</Placemark>\n";
-		$kml .= "</kml>";
-		
-		$this->kml = $kml;
-		
-		return $kml;
-	}
-*/
-} 
-
-class KmlOwsParser {
-	var $placemarkArray = array();
+	private $kml;
 	
-	public function __construct($kmlObj) {
-		
-		$doc = new DOMDocument("1.0");
-		$doc->preserveWhiteSpace = false;
-		$doc->loadXML($kmlObj->kml);
-#		print_r($doc);
-#		$doc_db = new DOMDocument("1.0");
-#		$doc_db->preserveWhiteSpace = false;
-#		$doc_db->loadXML($kmlObj->getKmlDocument($kmlObj->id));
-#		print_r($doc_db);
-#		$e = new mb_exception("Vergleich:" . strcmp($doc->saveXML(), $doc_db->saveXML()));
-#die;
-		/*
-		 * Get geometry information only, store it in placemarkArray
-		 */
-		$placemarkTagArray = $doc->getElementsByTagName("Placemark");
-		
-		if (count($placemarkTagArray) > 0) {
-			$id = 0;
-			
-			foreach ($placemarkTagArray as $node) {
-	
-				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($node);
-				$metadataArray = $this->getMetadataFromPlacemarkNode($node);
-				
-				/*
-				 * For a placemark, the geometryArray should only contain 1 geometry!
-				 */
-				for ($i=0; $i < count($geometryArray); $i++) {
-					$currentPlacemark = new KMLPlacemark($geometryArray[$i]);
-					
-					foreach ($metadataArray as $key => $value) {
-						$currentPlacemark->setProperty($key, $value);
-					}
-					$currentPlacemark->setProperty("Mapbender:kml", true);
-					$currentPlacemark->setProperty("Mapbender:name", "unknown");
-					$currentPlacemark->setProperty("Mapbender:id", $kmlObj->id);
-					$currentPlacemark->setProperty("Mapbender:placemarkId", $id);
-					array_push($this->placemarkArray, $currentPlacemark);
-				}
-				$id ++;		    
-			}
-		}
-		else {
-			$e = new mb_exception("class_kml.php: KMLOWSParser: No placemarks found in KML.");
-			return false;
-		}
-		return true;
-	}
-
 	/**
-	 * Returns an associative array, containing metadata
+	 * The ID of this KML in the database.
 	 */
-	private function getMetadataFromPlacemarkNode ($node) {
-	    $children = $node->childNodes;
-	    
-	    $metadataArray = array();
-	    
-		// search "ExtendedData" tag
-		foreach ($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "EXTENDEDDATA") {  
-				$extendedDataNode = $child;
-				$extDataChildren = $extendedDataNode->childNodes; 
-				
-				// search "Data" or "SchemaData" tag
-				foreach ($extDataChildren as $extDataChild) {
-					if (mb_strtoupper($this->sepNameSpace($extDataChild->nodeName)) == "SCHEMADATA") {
-						$simpleDataNode = $extDataChild->firstChild;
-						while ($simpleDataNode !== NULL) {
-							if (mb_strtoupper($this->sepNameSpace($simpleDataNode->nodeName)) == "SIMPLEDATA") {
-								$name = $simpleDataNode->getAttribute("name");
-								$value = $simpleDataNode->nodeValue;
-								$metadataArray[$name] = $value;
-							}
-							$simpleDataNode = $simpleDataNode->nextSibling;
-						}
-					}
-					if (mb_strtoupper($this->sepNameSpace($extDataChild->nodeName)) == "DATA") {
-						$dataNode = $extDataChild;
-						$name = $dataNode->getAttribute("name");
-#						$dataChildren = $dataNode->childNodes;
-#						foreach ($dataChildren as $dataChild) {
-#							if (mb_strtoupper($this->sepNameSpace($extDataChild->nodeName)) == "VALUE") {
-#								$metadataArray[$name] = $dataChild->nodeValue;
-#							}					
-#						}
-						$metadataArray[$name] = $dataNode->nodeValue;
-					}
-				}
-			}
-		}
-		return $metadataArray;		
-	}
+	private $id;
 	
 	/**
-	 * Given a "Point" node, this function returns the geometry (KMLPoint)
-	 * from within the node.
+	 * An array of {@link KMLPlacemark}
 	 */
-	private function getGeometryFromPointNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLPoint($geomString);
-	}
-	
-	/**
-	 * Given a "LineString" node, this function returns the geometry (KMLLine)
-	 * from within the node.
-	 */
-	private function getGeometryFromLinestringNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLLine($geomString);
-	}
-	
-	/**
-	 * Given a "Polygon" node, this function returns the geometry (KMLPolygon)
-	 * from within the node.
-	 */
-	private function getGeometryFromPolygonNode ($node) {
-		$polygon = null;
-
-	    $children = $node->childNodes;
-	    
-		// create new KMLPolygon
-		foreach ($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "EXTERIOR" || 
-				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "OUTERBOUNDARYIS") {
-				// create a new Linear Ring
-				$outerBoundary = $this->getGeometryFromLinearRingNode($child);
-				$polygon = new KMLPolygon($outerBoundary);
-			}
-		}
-		
-		if ($polygon !== null) {
-			// append inner boundaries to KMLPolygon
-			foreach ($children as $child) {
-				if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "INTERIOR" || 
-					mb_strtoupper($this->sepNameSpace($child->nodeName)) == "INNERBOUNDARYIS") {
-					// create a new Linear Ring
-					$innerBoundary = $this->getGeometryFromLinearRingNode($child);
-					$polygon->appendInnerBoundary($innerBoundary);
-				}
-			}
-		}
-		return $polygon;
-	}
-	
-	/**
-	 * Given a "OuterBoundaryIs" or "InnerBoundaryIs" node, this function 
-	 * returns the geometry (KMLLinearRing) within the child node named "linearring"
-	 */
-	private function getGeometryFromLinearRingNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "LINEARRING") {
-				$coordinatesNode = $this->getCoordinatesNode($child);
-				$geomString = $coordinatesNode->nodeValue;
-				return new KMLLinearRing($geomString);
-			}
-		}
-		return null;
-	}
-	
-	/**
-	 * Checks if the child nodes of a given KML node contains any geometries and
-	 * returns an array of geometries (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry)
-	 */
-	private function getGeometryArrayFromPlacemarkOrMultigeometryNode ($node) {
-	    $geometryArray = array();
-	    
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POINT") {
-				array_push($geometryArray, $this->getGeometryFromPointNode($child));
-			}
-			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POLYGON") {
-				array_push($geometryArray, $this->getGeometryFromPolygonNode($child));
-			}
-			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "LINESTRING") {
-				array_push($geometryArray, $this->getGeometryFromLinestringNode($child));
-			}
-			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "MULTIGEOMETRY") {
-				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($child);
-				$multigeometry = new KMLMultiGeometry();
-				
-				for ($i=0; $i < count($geometryArray); $i++) {
-					$multigeometry->append($geometryArray[$i]);	
-				}
-				array_push($geometryArray, $multigeometry);
-			}
-		}
-		return $geometryArray;
-	}
-
-	/**
-	 * Returns the child node with node name "coordinates" of a given KML node.
-	 * If no node is found, null is returned.
-	 */
-	private function getCoordinatesNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POSLIST" || 
-				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POS" || 
-				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "COORDINATES") {
-				return $child;
-			}
-		}
-		return null;
-	}
-
-	private function sepNameSpace($s){
-		$c = mb_strpos($s,":"); 
-		if($c>0){
-			return mb_substr($s,$c+1);
-		}
-		else{
-			return $s;
-		}		
-	}
-}
-
-/**
- * not used in OGC KML Mapbender project, may be buggy
- */
-class Kml22Parser {
-	public function __construct($kml) {
-		$doc = new DOMDocument("1.0");
-		$doc->preserveWhiteSpace = false;
-		$doc->loadXML($kml);
-
-		/*
-		 * Get geometry information only, store it in placemarkArray
-		 */
-		$placemarkTagArray = $doc->getElementsByTagName("Placemark");
-		
-		foreach ($placemarkTagArray as $node) {
-
-			$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($node);
-			
-			/*
-			 * For a placemark, the geometryArray should only contain 1 geometry!
-			 */
-			for ($i=0; $i < count($geometryArray); $i++) {
-				$currentPlacemark = new KMLPlacemark($geometryArray[$i]);
-				$currentPlacemark->setName($this->getNameFromPlacemarkNode($node));
-				array_push($this->placemarkArray, $currentPlacemark);
-			}		    
-		}
-//		print_r($this->placemarkArray);
-	}
-
-	/**
-	 * Given a "Point" node, this function returns the geometry (KMLPoint)
-	 * from within the node.
-	 */
-	private function getGeometryFromPointNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLPoint($geomString);
-	}
-	
-	/**
-	 * Given a "LineString" node, this function returns the geometry (KMLLine)
-	 * from within the node.
-	 */
-	private function getGeometryFromLinestringNode ($node) {
-		$coordinatesNode = $this->getCoordinatesNode($node);
-		$geomString = $coordinatesNode->nodeValue;
-		return new KMLLine($geomString);
-	}
-	
-	/**
-	 * Given a "Polygon" node, this function returns the geometry (KMLPolygon)
-	 * from within the node.
-	 */
-	private function getGeometryFromPolygonNode ($node) {
-		$polygon = null;
-
-	    $children = $node->childNodes;
-	    
-		// create new KMLPolygon
-		foreach ($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "OUTERBOUNDARYIS") {
-				// create a new Linear Ring
-				$outerBoundary = $this->getGeometryFromLinearRingNode($child);
-				$polygon = new KMLPolygon($outerBoundary);
-			}
-		}
-		
-		if ($polygon !== null) {
-			// append inner boundaries to KMLPolygon
-			foreach ($children as $child) {
-				if (mb_strtoupper($child->nodeName) == "INNERBOUNDARYIS") {
-					// create a new Linear Ring
-					$innerBoundary = $this->getGeometryFromLinearRingNode($child);
-					$polygon->appendInnerBoundary($innerBoundary);
-				}
-			}
-		}
-		return $polygon;
-	}
-	
-	/**
-	 * Given a "OuterBoundaryIs" or "InnerBoundaryIs" node, this function 
-	 * returns the geometry (KMLLinearRing) within the child node named "linearring"
-	 */
-	private function getGeometryFromLinearRingNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "LINEARRING") {
-				$coordinatesNode = $this->getCoordinatesNode($child);
-				$geomString = $coordinatesNode->nodeValue;
-				return new KMLLinearRing($geomString);
-			}
-		}
-		return null;
-	}
-	
-	/**
-	 * Checks if the child nodes of a given KML node contains any geometries and
-	 * returns an array of geometries (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry)
-	 */
-	private function getGeometryArrayFromPlacemarkOrMultigeometryNode ($node) {
-	    $geometryArray = array();
-	    
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "POINT") {
-				array_push($geometryArray, $this->getGeometryFromPointNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "POLYGON") {
-				array_push($geometryArray, $this->getGeometryFromPolygonNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "LINESTRING") {
-				array_push($geometryArray, $this->getGeometryFromLinestringNode($child));
-			}
-			elseif (mb_strtoupper($child->nodeName) == "MULTIGEOMETRY") {
-				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($child);
-				$multigeometry = new KMLMultiGeometry();
-				
-				for ($i=0; $i < count($geometryArray); $i++) {
-					$multigeometry->append($geometryArray[$i]);	
-				}
-				array_push($geometryArray, $multigeometry);
-			}
-		}
-		return $geometryArray;
-	}
-	
-	/**
-	 * Returns the name of the placemark from the placemark node
-	 */
-	function getNameFromPlacemarkNode($node) {
-	    $name = "new";
-	    
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "NAME") {
-				$name = $child->nodeValue;
-			}
-		}
-		return $name;
-	}
-	
-	/**
-	 * Returns the child node with node name "coordinates" of a given KML node.
-	 * If no node is found, null is returned.
-	 */
-	private function getCoordinatesNode ($node) {
-	    $children = $node->childNodes;
-		foreach($children as $child) {
-			if (mb_strtoupper($child->nodeName) == "COORDINATES") {
-				return $child;
-			}
-		}
-		return null;
-	}
-}
-
-// end class
-?>
+	private $placemarkArray = array();
+} 
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_ows.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_parser_2.2.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_2.2.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_parser_2.2.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,186 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_polygon.php");
+require_once("../classes/class_kml_linearring.php");
+require_once("../classes/class_kml_line.php");
+require_once("../classes/class_kml_point.php");
+require_once("../classes/class_kml_multigeometry.php");
+require_once("../classes/class_kml_placemark.php");
+
+/**
+ * not used in OGC KML Mapbender project, may be buggy
+ */
+class Kml22Parser {
+	public function __construct($kml) {
+		$doc = new DOMDocument("1.0");
+		$doc->preserveWhiteSpace = false;
+		$doc->loadXML($kml);
+
+		/*
+		 * Get geometry information only, store it in placemarkArray
+		 */
+		$placemarkTagArray = $doc->getElementsByTagName("Placemark");
+		
+		foreach ($placemarkTagArray as $node) {
+
+			$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($node);
+			
+			/*
+			 * For a placemark, the geometryArray should only contain 1 geometry!
+			 */
+			for ($i=0; $i < count($geometryArray); $i++) {
+				$currentPlacemark = new KMLPlacemark($geometryArray[$i]);
+				$currentPlacemark->setName($this->getNameFromPlacemarkNode($node));
+				array_push($this->placemarkArray, $currentPlacemark);
+			}		    
+		}
+	}
+
+	/**
+	 * Given a "Point" node, this function returns the geometry (KMLPoint)
+	 * from within the node.
+	 */
+	private function getGeometryFromPointNode ($node) {
+		$coordinatesNode = $this->getCoordinatesNode($node);
+		$geomString = $coordinatesNode->nodeValue;
+		return new KMLPoint($geomString);
+	}
+	
+	/**
+	 * Given a "LineString" node, this function returns the geometry (KMLLine)
+	 * from within the node.
+	 */
+	private function getGeometryFromLinestringNode ($node) {
+		$coordinatesNode = $this->getCoordinatesNode($node);
+		$geomString = $coordinatesNode->nodeValue;
+		return new KMLLine($geomString);
+	}
+	
+	/**
+	 * Given a "Polygon" node, this function returns the geometry (KMLPolygon)
+	 * from within the node.
+	 */
+	private function getGeometryFromPolygonNode ($node) {
+		$polygon = null;
+
+	    $children = $node->childNodes;
+	    
+		// create new KMLPolygon
+		foreach ($children as $child) {
+			if (mb_strtoupper($child->nodeName) == "OUTERBOUNDARYIS") {
+				// create a new Linear Ring
+				$outerBoundary = $this->getGeometryFromLinearRingNode($child);
+				$polygon = new KMLPolygon($outerBoundary);
+			}
+		}
+		
+		if ($polygon !== null) {
+			// append inner boundaries to KMLPolygon
+			foreach ($children as $child) {
+				if (mb_strtoupper($child->nodeName) == "INNERBOUNDARYIS") {
+					// create a new Linear Ring
+					$innerBoundary = $this->getGeometryFromLinearRingNode($child);
+					$polygon->appendInnerBoundary($innerBoundary);
+				}
+			}
+		}
+		return $polygon;
+	}
+	
+	/**
+	 * Given a "OuterBoundaryIs" or "InnerBoundaryIs" node, this function 
+	 * returns the geometry (KMLLinearRing) within the child node named "linearring"
+	 */
+	private function getGeometryFromLinearRingNode ($node) {
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($child->nodeName) == "LINEARRING") {
+				$coordinatesNode = $this->getCoordinatesNode($child);
+				$geomString = $coordinatesNode->nodeValue;
+				return new KMLLinearRing($geomString);
+			}
+		}
+		return null;
+	}
+	
+	/**
+	 * Checks if the child nodes of a given KML node contains any geometries and
+	 * returns an array of geometries (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry)
+	 */
+	private function getGeometryArrayFromPlacemarkOrMultigeometryNode ($node) {
+	    $geometryArray = array();
+	    
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($child->nodeName) == "POINT") {
+				array_push($geometryArray, $this->getGeometryFromPointNode($child));
+			}
+			elseif (mb_strtoupper($child->nodeName) == "POLYGON") {
+				array_push($geometryArray, $this->getGeometryFromPolygonNode($child));
+			}
+			elseif (mb_strtoupper($child->nodeName) == "LINESTRING") {
+				array_push($geometryArray, $this->getGeometryFromLinestringNode($child));
+			}
+			elseif (mb_strtoupper($child->nodeName) == "MULTIGEOMETRY") {
+				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($child);
+				$multigeometry = new KMLMultiGeometry();
+				
+				for ($i=0; $i < count($geometryArray); $i++) {
+					$multigeometry->append($geometryArray[$i]);	
+				}
+				array_push($geometryArray, $multigeometry);
+			}
+		}
+		return $geometryArray;
+	}
+	
+	/**
+	 * Returns the name of the placemark from the placemark node
+	 */
+	function getNameFromPlacemarkNode($node) {
+	    $name = "new";
+	    
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($child->nodeName) == "NAME") {
+				$name = $child->nodeValue;
+			}
+		}
+		return $name;
+	}
+	
+	/**
+	 * Returns the child node with node name "coordinates" of a given KML node.
+	 * If no node is found, null is returned.
+	 */
+	private function getCoordinatesNode ($node) {
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($child->nodeName) == "COORDINATES") {
+				return $child;
+			}
+		}
+		return null;
+	}
+}
+
+// end class
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_parser_2.2.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_parser_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_ows.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_parser_ows.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,242 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_polygon.php");
+require_once("../classes/class_kml_linearring.php");
+require_once("../classes/class_kml_line.php");
+require_once("../classes/class_kml_point.php");
+require_once("../classes/class_kml_multigeometry.php");
+require_once("../classes/class_kml_placemark.php");
+
+/**
+ * @package KML
+ */
+ class KmlOwsParser {
+	var $placemarkArray = array();
+	
+	public function __construct($kml, $kmlId) {
+		
+		$doc = new DOMDocument("1.0");
+		$doc->preserveWhiteSpace = false;
+		$doc->loadXML($kml);
+
+		/*
+		 * Get geometry information only, store it in placemarkArray
+		 */
+		$placemarkTagArray = $doc->getElementsByTagName("Placemark");
+		
+		if (count($placemarkTagArray) > 0) {
+			$id = 0;
+			
+			foreach ($placemarkTagArray as $node) {
+	
+				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($node);
+				$metadataArray = $this->getMetadataFromPlacemarkNode($node);
+				
+				/*
+				 * For a placemark, the geometryArray should only contain 1 geometry!
+				 */
+				for ($i=0; $i < count($geometryArray); $i++) {
+					$currentPlacemark = new KMLPlacemark($geometryArray[$i]);
+					
+					foreach ($metadataArray as $key => $value) {
+						$currentPlacemark->setProperty($key, $value);
+					}
+					$currentPlacemark->setProperty("Mapbender:kml", true);
+					$currentPlacemark->setProperty("Mapbender:name", "unknown");
+					$currentPlacemark->setProperty("Mapbender:id", $kmlId);
+					$currentPlacemark->setProperty("Mapbender:placemarkId", $id);
+					array_push($this->placemarkArray, $currentPlacemark);
+				}
+				$id ++;		    
+			}
+		}
+		else {
+			$e = new mb_exception("class_kml.php: KMLOWSParser: No placemarks found in KML.");
+			return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Returns an associative array, containing metadata
+	 */
+	private function getMetadataFromPlacemarkNode ($node) {
+	    $children = $node->childNodes;
+	    
+	    $metadataArray = array();
+	    
+		// search "ExtendedData" tag
+		foreach ($children as $child) {
+			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "EXTENDEDDATA") {  
+				$extendedDataNode = $child;
+				$extDataChildren = $extendedDataNode->childNodes; 
+				
+				// search "Data" or "SchemaData" tag
+				foreach ($extDataChildren as $extDataChild) {
+					if (mb_strtoupper($this->sepNameSpace($extDataChild->nodeName)) == "SCHEMADATA") {
+						$simpleDataNode = $extDataChild->firstChild;
+						while ($simpleDataNode !== NULL) {
+							if (mb_strtoupper($this->sepNameSpace($simpleDataNode->nodeName)) == "SIMPLEDATA") {
+								$name = $simpleDataNode->getAttribute("name");
+								$value = $simpleDataNode->nodeValue;
+								$metadataArray[$name] = $value;
+							}
+							$simpleDataNode = $simpleDataNode->nextSibling;
+						}
+					}
+					if (mb_strtoupper($this->sepNameSpace($extDataChild->nodeName)) == "DATA") {
+						$dataNode = $extDataChild;
+						$name = $dataNode->getAttribute("name");
+						$metadataArray[$name] = $dataNode->nodeValue;
+					}
+				}
+			}
+		}
+		return $metadataArray;		
+	}
+	
+	/**
+	 * Given a "Point" node, this function returns the geometry (KMLPoint)
+	 * from within the node.
+	 */
+	private function getGeometryFromPointNode ($node) {
+		$coordinatesNode = $this->getCoordinatesNode($node);
+		$geomString = $coordinatesNode->nodeValue;
+		return new KMLPoint($geomString);
+	}
+	
+	/**
+	 * Given a "LineString" node, this function returns the geometry (KMLLine)
+	 * from within the node.
+	 */
+	private function getGeometryFromLinestringNode ($node) {
+		$coordinatesNode = $this->getCoordinatesNode($node);
+		$geomString = $coordinatesNode->nodeValue;
+		return new KMLLine($geomString);
+	}
+	
+	/**
+	 * Given a "Polygon" node, this function returns the geometry (KMLPolygon)
+	 * from within the node.
+	 */
+	private function getGeometryFromPolygonNode ($node) {
+		$polygon = null;
+
+	    $children = $node->childNodes;
+	    
+		// create new KMLPolygon
+		foreach ($children as $child) {
+			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "EXTERIOR" || 
+				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "OUTERBOUNDARYIS") {
+				// create a new Linear Ring
+				$outerBoundary = $this->getGeometryFromLinearRingNode($child);
+				$polygon = new KMLPolygon($outerBoundary);
+			}
+		}
+		
+		if ($polygon !== null) {
+			// append inner boundaries to KMLPolygon
+			foreach ($children as $child) {
+				if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "INTERIOR" || 
+					mb_strtoupper($this->sepNameSpace($child->nodeName)) == "INNERBOUNDARYIS") {
+					// create a new Linear Ring
+					$innerBoundary = $this->getGeometryFromLinearRingNode($child);
+					$polygon->appendInnerBoundary($innerBoundary);
+				}
+			}
+		}
+		return $polygon;
+	}
+	
+	/**
+	 * Given a "OuterBoundaryIs" or "InnerBoundaryIs" node, this function 
+	 * returns the geometry (KMLLinearRing) within the child node named "linearring"
+	 */
+	private function getGeometryFromLinearRingNode ($node) {
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "LINEARRING") {
+				$coordinatesNode = $this->getCoordinatesNode($child);
+				$geomString = $coordinatesNode->nodeValue;
+				return new KMLLinearRing($geomString);
+			}
+		}
+		return null;
+	}
+	
+	/**
+	 * Checks if the child nodes of a given KML node contains any geometries and
+	 * returns an array of geometries (KMLPoint, KMLPolygon, KMLLinestring and KMLMultigeometry)
+	 */
+	private function getGeometryArrayFromPlacemarkOrMultigeometryNode ($node) {
+	    $geometryArray = array();
+	    
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POINT") {
+				array_push($geometryArray, $this->getGeometryFromPointNode($child));
+			}
+			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POLYGON") {
+				array_push($geometryArray, $this->getGeometryFromPolygonNode($child));
+			}
+			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "LINESTRING") {
+				array_push($geometryArray, $this->getGeometryFromLinestringNode($child));
+			}
+			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "MULTIGEOMETRY") {
+				$geometryArray = $this->getGeometryArrayFromPlacemarkOrMultigeometryNode($child);
+				$multigeometry = new KMLMultiGeometry();
+				
+				for ($i=0; $i < count($geometryArray); $i++) {
+					$multigeometry->append($geometryArray[$i]);	
+				}
+				array_push($geometryArray, $multigeometry);
+			}
+		}
+		return $geometryArray;
+	}
+
+	/**
+	 * Returns the child node with node name "coordinates" of a given KML node.
+	 * If no node is found, null is returned.
+	 */
+	private function getCoordinatesNode ($node) {
+	    $children = $node->childNodes;
+		foreach($children as $child) {
+			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POSLIST" || 
+				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POS" || 
+				mb_strtoupper($this->sepNameSpace($child->nodeName)) == "COORDINATES") {
+				return $child;
+			}
+		}
+		return null;
+	}
+
+	private function sepNameSpace($s){
+		$c = mb_strpos($s,":"); 
+		if($c>0){
+			return mb_substr($s,$c+1);
+		}
+		else{
+			return $s;
+		}		
+	}
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_parser_ows.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/classes/class_kml_placemark.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_placemark.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_kml_placemark.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,101 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_wmc.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("../classes/class_mb_exception.php");
+
+/**
+ * A Placemark consists of a geometry of type {@link KMLPoint}, {@link KMLPolygon}, 
+ * {@link KMLLineString} or {@link KMLMultiGeometry} and an array of properties.
+ * 
+ * @package KML
+ */
+class KMLPlacemark {
+	/**
+	 * @param	KMLGeometry	$aGeometry 
+	 */
+	public function __construct ($aGeometry) {
+		$this->geometry = $aGeometry;
+	}
+	
+	/**
+	 * @return	string	a string representation of the object, currently geoJSON.
+	 */
+	public function __toString() {
+		return $this->toGeoJSON();
+	}
+
+	/**
+	 * @param 	mixed 	$key	The key of the property.
+	 * @param	mixed	$value	The value of the property.
+	 */
+	public function setProperty ($key, $value) {
+		// TODO: keys are unique, may be not intended in KML OWS5
+		$this->properties[$key] = $value;
+	}
+	
+	/**
+	 * @param  string $key the property name
+	 * @return mixed       the property value; if none exists, null.
+	 */
+	public function getProperty ($key) {
+		if (array_key_exists($key)) {
+			return $this->properties[$key];
+		}
+		$e = new mb_exception("class_kml_placemark.php: getProperty: no value for key '" . $key . "'");
+		return null;
+	}
+	
+	/**
+	 * @return array the array of properties.
+	 */
+	public function getProperties () {
+		return $this->properties;
+	}	
+
+	/**
+	 * @return string a geoJSON string representation of the object.
+	 */
+	public function toGeoJSON () {
+		$str = "";
+		if ($this->geometry !== null) {
+			$str .= "{\"type\":\"Feature\", ";
+//			$str .= "\"sid\":\"id". time() ."\", ";
+			$str .= "\"geometry\": ";
+			$str .= $this->geometry->toGeoJSON();
+			$str .= ", \"properties\": {";
+			$cnt = 0;
+			foreach ($this->properties as $key => $value) {
+				if ($cnt > 0) {
+					$str .= ",";
+				}
+				$str .= "\"" . $key . "\":\"" . $value . "\"";
+				$cnt ++;
+			}
+			$str .= "}}";
+		}
+		else {
+			$e = new mb_exception("KMLPlacemark: toGeoJSON: this geometry is null!");
+		}
+		return $str;
+	}
+
+	private $geometry;
+	private $properties = array();
+}
+?>
\ No newline at end of file


Property changes on: trunk/mapbender/http/classes/class_kml_placemark.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: trunk/mapbender/http/classes/class_kml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_point.php	2008-01-03 16:35:29 UTC (rev 1948)
+++ trunk/mapbender/http/classes/class_kml_point.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -1,6 +1,7 @@
 <?php
 /**
  * $Id$
+ * 
  * @link 		http://www.mapbender.org/index.php/class_wmc.php
  * @copyright 	2002 CCGIS 
  * @license		http://opensource.org/licenses/gpl-license.php
@@ -60,14 +61,12 @@
 	 * @return 	string	a geoJSON string representation of the object.
 	 */
 	public function toGeoJSON () {
-		$str = "";
 		if ($this->point !== null) {
-			$str .= "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"]."]}";
+			return "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"]."]}";
 		}
-		else {
-			$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
-		}
-		return $str;
+
+		$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
+		return "";
 	}
 	
 	/**

Modified: trunk/mapbender/http/classes/class_kml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_polygon.php	2008-01-03 16:35:29 UTC (rev 1948)
+++ trunk/mapbender/http/classes/class_kml_polygon.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -1,7 +1,6 @@
 <?php
- # $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $
- 
 /**
+ * $Id$
  * @link 		http://www.mapbender.org/index.php/class_wmc.php
  * @copyright 	2002 CCGIS 
  * @license		http://opensource.org/licenses/gpl-license.php
@@ -22,6 +21,7 @@
 
 require_once("../classes/class_mb_exception.php");
 require_once("../classes/class_kml_geometry.php");
+require_once("../classes/class_kml_linearring.php");
 
 /**
  * Represents a polygon, consisting of 1 outer boundary and 0..n inner boundaries 
@@ -38,7 +38,9 @@
 		if ($aLinearRing instanceof KMLLinearRing) {
 			$this->outerBoundary = $aLinearRing;
 		}
-		$e = new mb_exception("class_kml_polygon.php: __construct: parameter not a linear ring.");
+		else {
+			$e = new mb_exception("class_kml_polygon.php: __construct: parameter not a linear ring, but a " . get_class($aLinearRing));
+		}
 	}
 
 	/**
@@ -53,9 +55,8 @@
 	 * @return	string	the geoJSON representation of the object
 	 */
 	public function toGeoJSON () {
-		$str = "";
 		if ($this->outerBoundary !== null) {
-			$str .= $this->outerBoundary->toGeoJSON();
+			$str = $this->outerBoundary->toGeoJSON();
 			
 			$numberOfInnerBoundaries = count($this->innerBoundaryArray);
 			if ($numberOfInnerBoundaries > 0) {
@@ -67,12 +68,11 @@
 					$str .= $this->innerBoundaryArray[$i]->toGeoJSON();
 				}
 			}
-			$str .= "{\"type\": \"Polygon\", \"coordinates\": [" . $str . "]}";
+			return "{\"type\": \"Polygon\", \"coordinates\": [" . $str . "]}";
 		}
-		else {
-			$e = new mb_exception("KMLPolygon: toGeoJSON: this point is null.");
-		}
-		return $str;
+		
+		$e = new mb_exception("KMLPolygon: toGeoJSON: this point is null.");
+		return "";
 	}
 
 	/**


Property changes on: trunk/mapbender/http/classes/class_kml_polygon.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: trunk/mapbender/http/php/mb_listKMLs.php
===================================================================
--- trunk/mapbender/http/php/mb_listKMLs.php	                        (rev 0)
+++ trunk/mapbender/http/php/mb_listKMLs.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,254 @@
+<?php
+# $Id: mb_listWMCs.php 1686 2007-09-26 09:05:01Z christoph $
+# http://www.mapbender.org/index.php/mb_listWMCs.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.
+
+session_start();
+
+require_once("../../conf/mapbender.conf");
+require_once("../classes/class_administration.php");
+require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_connector.php");
+require_once("../classes/class_kml_ows.php");
+
+$gui_id = $_SESSION["mb_user_gui"];
+$user_id = $_SESSION["mb_user_id"];
+
+$action = $_GET["action"];
+$kmlId = $_GET["kml_id"];
+
+$delKmlId = $_POST["del_kml_id"];
+$clientFilename = $_FILES["local_kml_filename"]["tmp_name"];
+$kmlUrl = $_POST["local_kml_url"];
+
+$form_target = $_SERVER["PHP_SELF"] . "?" . SID;
+
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+	<head>
+		<meta http-equiv="cache-control" content="no-cache">
+		<meta http-equiv="pragma" content="no-cache">
+		<meta http-equiv="expires" content="0">
+		<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;?>">	
+		<title>Load KML</title>
+	</head>
+	<body>
+		<form name='delete_kml' action='<?php echo $form_target; ?>' method='POST'>
+			<input type='hidden' id='delete_kml' name='del_kml_id' value ='' >
+		</form>
+
+<?php
+function mb_listKMLs($kmlIdArray, $form_target){
+	$display = "<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;background-color: White;'><font align='left' color='#000000'>load KML from list</font></h2>";
+	$display .= "<table width='90%' style='font-family: Arial, Helvetica, sans-serif;font-size : 12px;color: #808080;' border='1' cellpadding='3' rules='rows'><tr style='background-color:#F0F0F0;' width='80px'><td ><b>KML name</b></td><td><b>last update</b></td><td colspan=5></td></tr>";
+
+	if (count($kmlIdArray) > 0) {
+		$v = array();
+		$t = array();
+
+		$kmlIdList = "";
+		for ($i = 0; $i < count($kmlIdArray); $i++){
+			if ($i > 0){ 
+				$kmlIdList .= ",";
+			}
+			$kmlIdList .= "$".($i+1);
+			array_push($v, $kmlIdArray[$i]);
+			array_push($t, 's');
+		}
+		$sql_list_kmls = "SELECT DISTINCT kml_id, kml_title, kml_timestamp FROM mb_user_kml ";
+		$sql_list_kmls .= "WHERE kml_id IN (" . $kmlIdList . ") ";
+		$sql_list_kmls .= "ORDER BY kml_timestamp DESC";
+		
+		$res_list_kmls = db_prep_query($sql_list_kmls, $v, $t);
+		while($row = db_fetch_array($res_list_kmls)){
+			$this_id = $row["kml_id"];
+			$this_title = $row["kml_title"];
+			$this_timestamp = date("M d Y H:i:s", $row["kml_timestamp"]); 
+
+			$display .= "<tr onmouseover='this.style.backgroundColor = \"#F08080\"' onmouseout='this.style.backgroundColor = \"#ffffff\"'>";
+			$display .= "<td>".$this_title."</td>";
+			$display .= "<td>".$this_timestamp. "</td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=load&kml_id=".$this_id."\"><img src=\"../img/button_gray/kml_load.png\" title=\"load this KML\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=merge&kml_id=".$this_id."\"><img src=\"../img/button_gray/kml_merge.png\" title=\"merge KML\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=append&kml_id=".$this_id."\"><img src=\"../img/button_gray/kml_append.png\" title=\"append KML\"  border=0></a></td>";
+			$display .= "<td><a href='../javascripts/mod_displayKml.php?kml_id=".$this_id."' target = '_blank'><img src=\"../img/button_gray/kml_xml.png\" title=\"display KML XML\"  border=0></a></td>";
+			$display .= "<td><a href=\"" . $form_target . "&action=delete&kml_id=".$this_id."\"><img src=\"../img/button_gray/del.png\" title=\"delete this KML\"  border=0></a></td>";
+			$display .= "</tr>";
+		}
+	}
+	else{
+		$display .= "<tr><td>There are no KMLs availiable</td></tr>";
+	}	
+	$display .= "</table>";
+	   
+	return $display;
+}
+
+function getTarget($gui_id) {
+	$sql = "SELECT e_requires, e_target FROM gui_element WHERE e_id = 'loadkml' AND fkey_gui_id = '".$gui_id."'";
+	$res = db_query($sql);
+	$cnt = 0;
+	while($row = db_fetch_array($res)){ 
+		$e_target = $row["e_target"];
+		$e_require = $row["e_requires"];
+		$cnt++;
+	}
+	if ($cnt > 1) { 
+		$e = new mb_exception("listKMLs: e_id 'loadkml' not unique in GUI '" . $gui_id . "'!");
+	}
+
+	$targetArray = explode(",", $e_target);
+	if (in_array('mapframe1', $targetArray)) {
+		return 'mapframe1';
+	}
+	else {
+		return trim($targetArray[0]);
+	}
+}
+
+function loadFile($filename) {
+	$handle = fopen($filename, "r");
+	$cnt = 0;
+	while (!feof($handle)) {
+    	$buffer .= fgets($handle, 4096);
+	}
+	fclose ($handle);
+	return $buffer;
+}
+
+$admin = new administration();
+//$kmlIdArray = $admin->getKmlByOwner($user_id);
+
+// kml is being deleted
+if (!empty($delKmlId)) {
+	$result = $admin->deleteKml($delKmlId, $user_id);
+	if (!$result) {
+		echo "<script language='javascript'>";
+		echo "alert('KML could not be deleted!');";
+		echo "</script>";
+	}
+}
+// kml is being loaded from file
+elseif ($clientFilename) {
+	$serverFilename = "../tmp/kml" . time() . ".xml";
+	copy($clientFilename, $serverFilename);
+	
+	$kmlDoc = loadFile($serverFilename);
+	$kmlObj = new KML();
+	if ($kmlObj->parseKml($kmlDoc)) {
+		$geoJSON = $kmlObj->toGeoJSON();
+		setGeoJson($geoJSON);
+	}
+	else {
+		echo "<script language='javascript'>";
+		echo "alert('KML load failed. See the error log for details.');";
+		echo "</script>";
+	}
+}
+// load KML from URL
+elseif ($kmlUrl) {
+	$connector = new connector($kmlUrl);
+	$kmlDoc = $connector->file;
+	$kmlObj = new KML();
+	if ($kmlObj->parseKml($kmlDoc)) {
+		$geoJSON = $kmlObj->toGeoJSON();
+		setGeoJson($geoJSON);
+	}
+	else {
+		echo "<script language='javascript'>";
+		echo "alert('KML load failed. See the error log for details.');";
+		echo "</script>";
+	}
+}
+
+function setGeoJson ($geoJSON) {
+	echo "<script language='javascript'>";
+	if ($geoJSON) {
+		echo "var geoJSON = " . $geoJSON . ";"; 
+		echo "window.opener.kmlHasLoaded.trigger(geoJSON);";
+		echo "alert('KML loaded succesfully.');";
+	}
+	else {
+		echo "alert('Loading KML failed.');";
+	}
+	echo "window.close();";
+	echo "</script>";
+}
+
+// load a KML from file
+?>
+<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;background-color: White;'><font align='left' color='#000000'>load KML from file</font></h2>
+<form enctype="multipart/form-data" action="<?php echo $form_target;?>" method=POST target="_self"> 
+<input type='file' name='local_kml_filename'>
+<input id='kml_load_from_file' type='submit' value='load'>
+</form>
+
+<?php
+// load a KML from URL
+?>
+<h2 style='font-family: Arial, Helvetica, sans-serif; color: #808080;background-color: White;'><font align='left' color='#000000'>load KML from URL</font></h2>
+<form action="<?php echo $form_target;?>" method=POST target="_self"> 
+<input type='text' name='local_kml_url' value='http://code.google.com/apis/kml/documentation/KML_Samples.kml' maxlength=512 size=50>
+
+<br/><br/>Choose URL below or enter above
+<select name='local_kml_url_select' onChange='local_kml_url.value=this.value'>
+<option value='http://code.google.com/apis/kml/documentation/KML_Samples.kml'>Google KML Sample</option>
+<option value='http://geo.openplans.org:8080/geoserver/wms?bbox=-128,23,-64,51&Format=application/vnd.google-earth.kml+xml&request=GetMap&&width=600&height=317&srs=EPSG:4326&sld=http://artois.openplans.org/slds/population.sld'>TOPP OWS-5 Demo Service KML 2.2 (states US)</option>
+<option value='http://geo.openplans.org:8080/geoserver/wms?bbox=-128,23,-64,51&Format=application/kml+xml&request=GetMap&&width=600&height=317&srs=EPSG:4326&sld=http://artois.openplans.org/slds/population.sld&layers=topp:states&format_options=extendedData:true;style:false'>TOPP OWS-5 Demo Service KML OWS-5 (states US)</option>
+<option value='http://wight.demos.galdosinc.com/fps/wms/http?request=GetMap&version=1.1.1&layers=DepthArea&styles=DepthArea&service=WMS&srs=urn:ogc:def:crs:ogc:1.3:CRS84&BBOX=-1.62,50.55,-1.02,50.9&format=kml&WIDTH=500&HEIGHT=500'>Galdos OWS-5 Demo Service</option>
+<option value='http://geo.openplans.org:8080/geoserver/wms?bbox=-180,-90,180,90&Format=application/kml+xml&request=GetMap&&width=600&height=317&srs=EPSG:4326&sld=http://artois.openplans.org/slds/population.sld&layers=topp:tasmania_roads,topp:tasmania_state_boundaries&format_options=extendedData:true;style:false'>TOPP OWS-5 Demo Service KML OWS-5 (Tasmania)</option>
+</select>
+<input id='kml_load_from_url' type='submit' value='load'>
+</form>
+<?php
+/*
+// load a KML from list
+echo mb_listKMLs($kmlIdArray, $form_target);
+		
+if ($kmlId && in_array($kmlId, $kmlIdArray)){
+	if ($action == "delete") {
+		echo "<script language='javascript'>";
+		echo "value = confirm('Do you really want to delete this document?');";
+		echo "if (value == true) {";
+		echo "document.delete_kml.del_kml_id.value = '" . $kmlId . "';";
+		echo "document.delete_kml.submit();";
+		echo "}";
+		echo "</script>";
+	}
+	else if ($action == "append" || $action == "merge" || $action == "load") {
+		$mytarget = getTarget($gui_id);
+
+		$kml = new kml();
+		$kml->createObjFromKML_id($kmlId);
+		$js = $kml->createJsObjFromKML("window.opener.", $mytarget, $action);
+
+		echo "<script language='javascript'>";
+		echo $js;
+		if ($kml->getTitle()) {
+			$title = "'" . $kml->getTitle() . "' ";
+		}
+		echo "alert(\"KML " . $title . ": " . $action . " successful.\");\n";
+		echo "window.close();";
+		echo "</script>";
+	}
+}
+*/
+?>
+</body>
+</html>

Added: trunk/mapbender/http/php/mod_displayKML.php
===================================================================
--- trunk/mapbender/http/php/mod_displayKML.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_displayKML.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,39 @@
+<?php
+# $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $
+# http://www.mapbender.org/index.php/class_wmc.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.
+
+session_start();
+mb_internal_encoding("UTF-8");
+
+require_once("../../conf/mapbender.conf");
+require_once("../classes/class_kml_ows.php");
+
+$kmlId = $_GET["kmlId"];
+
+$kml = new KML();
+
+$kmlDoc = $kml->getKmlDocumentFromDB($kmlId);
+
+if ($kmlDoc) {
+	header("Content-type: application/xhtml+xml; charset=" . CHARSET);
+	echo $kmlDoc;
+}
+else {
+	echo "You may not have the rights to access this document. Check your log file.";
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_updateKmlInDb.php
===================================================================
--- trunk/mapbender/http/php/mod_updateKmlInDb.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_updateKmlInDb.php	2008-01-04 16:32:18 UTC (rev 1949)
@@ -0,0 +1,40 @@
+<?php
+# $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $
+# http://www.mapbender.org/index.php/class_wmc.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.
+
+session_start();
+mb_internal_encoding("UTF-8");
+
+require_once("../../conf/mapbender.conf");
+require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_ows.php");
+
+$kmlId = $_POST["kmlId"];
+$placemarkId = $_POST["placemarkId"];
+$command = $_POST["command"];
+$geoJSON = stripslashes($_POST["geoJSON"]);
+
+$kml = new KML();
+// returns true if the update succeeded, false if not
+if ($kml->updateKml($kmlId, $placemarkId, $geoJSON)) {
+	echo "1";	
+}
+else {
+	echo "0";
+}
+?>



More information about the Mapbender_commits mailing list