[Mapbender-commits] r8482 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 4 02:23:03 PDT 2012


Author: verenadiewald
Date: 2012-09-04 02:23:02 -0700 (Tue, 04 Sep 2012)
New Revision: 8482

Modified:
   trunk/mapbender/http/classes/class_kml_geometry.php
   trunk/mapbender/http/classes/class_kml_linearring.php
   trunk/mapbender/http/classes/class_kml_ows.php
   trunk/mapbender/http/classes/class_kml_parser_ows.php
   trunk/mapbender/http/classes/class_kml_placemark.php
   trunk/mapbender/http/classes/class_kml_polygon.php
   trunk/mapbender/http/classes/class_point.php
Log:
transformation of polygons in kml

Modified: trunk/mapbender/http/classes/class_kml_geometry.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_geometry.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_geometry.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -48,7 +48,7 @@
 		}
 		
 		//TODO: not sure if this type determination works
-		$type = get_class($obj) || gettype($obj);
+		$type = get_class($obj) ? get_class($obj) : gettype($obj);
 		$e = new mb_warning("class_kml_geometry.php: isGeometry: not a geometry, but " . $type);
 		return false;
 	}

Modified: trunk/mapbender/http/classes/class_kml_linearring.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_linearring.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_linearring.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -55,5 +55,18 @@
 		$e = new mb_exception("KMLLinearRing: toGeoJSON: no points in this linear ring.");
 		return "";
 	}
+	
+    public function transform($targetEpsg){
+        $numberOfPoints = count($this->pointArray);
+		if ($numberOfPoints > 0) {
+		    for ($i=0; $i < $numberOfPoints; $i++) {
+			    $pt = new Mapbender_point($this->pointArray[$i]["x"], $this->pointArray[$i]["y"], $this->pointArray[$i]["z"], 4326);
+				$pt->transform($targetEpsg);
+				$this->pointArray[$i]["x"] = $pt->x;
+				$this->pointArray[$i]["y"] = $pt->y;
+				$this->pointArray[$i]["z"] = $pt->z;
+	        }
+		}
+    }
 }
 ?>

Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_ows.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -293,7 +293,7 @@
 	    $numberOfPlacemarks = count($this->placemarkArray);
 		if ($numberOfPlacemarks > 0) {
 			for ($i=0; $i < $numberOfPlacemarks; $i++) {
-				$this->placemarkArray[$i]->transform($targetEpsg);
+			    $this->placemarkArray[$i]->transform($targetEpsg);
 			}
 		}
 		else {
@@ -320,7 +320,7 @@
 		$e = new mb_notice("parsing finished...#placemarks: " . count($this->placemarkArray) . " (" . count($parser->placemarkArray) . ")");
 		$this->placemarkArray = $parser->placemarkArray; 
 
-//		print_r($this);
+//		new mb_exception(print_r($this, true));
 		
 //		$this->kml = $this->__toString();
 
@@ -332,7 +332,7 @@
 	 * @return string the geoJSON representation of the KML.
 	 */
 	public function toGeoJSON() {
-		$str = "";
+	    $str = "";
 		$numberOfPlacemarks = count($this->placemarkArray);
 		if ($numberOfPlacemarks > 0) {
 			$str .= "{\"type\": \"FeatureCollection\", \"features\": [";

Modified: trunk/mapbender/http/classes/class_kml_parser_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_ows.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_parser_ows.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -282,7 +282,7 @@
 	    
 	    $children = $node->childNodes;
 		foreach($children as $child) {
-			if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POINT") {
+		    if (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POINT") {
 				array_push($geometryArray, $this->getGeometryFromPointNode($child));
 			}
 			elseif (mb_strtoupper($this->sepNameSpace($child->nodeName)) == "POLYGON") {

Modified: trunk/mapbender/http/classes/class_kml_placemark.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_placemark.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_placemark.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -72,8 +72,8 @@
 	 * @return string a geoJSON string representation of the object.
 	 */
 	public function toGeoJSON () {
-		$str = "";
-		if ($this->geometry !== null) {
+	    $str = "";
+	    if ($this->geometry !== null) {
 			$str .= "{\"type\":\"Feature\", ";
 //			$str .= "\"sid\":\"id". time() ."\", ";
 			$str .= "\"geometry\": ";

Modified: trunk/mapbender/http/classes/class_kml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_polygon.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_kml_polygon.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -89,6 +89,20 @@
 		$e = new mb_exception("class_kml_polygon.php: appendInnerBoundary: parameter not a linear ring.");
 		return false;
 	}
+	
+    public function transform($targetEpsg){
+        if ($this->outerBoundary !== null) {
+			$str = $this->outerBoundary->transform($targetEpsg);
+			
+			$numberOfInnerBoundaries = count($this->innerBoundaryArray);
+			if ($numberOfInnerBoundaries > 0) {
+				for ($i=0; $i < $numberOfInnerBoundaries; $i++) {
+					$this->innerBoundaryArray[$i]->transform($targetEpsg);
+				}
+			}
+			
+		}
+	}
 
 	/**
 	 * @var	KMLLinearRing	The outer boundary of the polygon

Modified: trunk/mapbender/http/classes/class_point.php
===================================================================
--- trunk/mapbender/http/classes/class_point.php	2012-09-04 09:11:56 UTC (rev 8481)
+++ trunk/mapbender/http/classes/class_point.php	2012-09-04 09:23:02 UTC (rev 8482)
@@ -165,9 +165,9 @@
 			$targetEpsg = preg_replace("/EPSG:/", "", $toEpsg);
 			db_begin();
 			$sql = "SELECT X(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as x, ";
-			$sql .= "Y(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as y, ";
+			$sql .= "Y(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as y";
 			if (isset($this->z)) {
-				$sql .= "Z(transform(GeometryFromText('POINT(".$this->x." ".$this->y." ".$this->z.")',".$currentEpsg."),".$targetEpsg.")) as z";
+				$sql .= ", Z(transform(GeometryFromText('POINT(".$this->x." ".$this->y." ".$this->z.")',".$currentEpsg."),".$targetEpsg.")) as z";
 			}
 			$res = db_query($sql);
 			db_commit();



More information about the Mapbender_commits mailing list