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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Feb 18 12:36:04 EST 2009


Author: christoph
Date: 2009-02-18 12:36:04 -0500 (Wed, 18 Feb 2009)
New Revision: 3573

Added:
   trunk/mapbender/http/classes/class_gml_geometry.php
   trunk/mapbender/http/classes/class_wfs_configuration.php
Modified:
   trunk/mapbender/http/classes/class_gml.php
   trunk/mapbender/http/classes/class_gml_2.php
   trunk/mapbender/http/classes/class_gml_2_factory.php
   trunk/mapbender/http/classes/class_gml_3.php
   trunk/mapbender/http/classes/class_gml_3_factory.php
   trunk/mapbender/http/classes/class_gml_factory.php
   trunk/mapbender/http/classes/class_gml_line.php
   trunk/mapbender/http/classes/class_gml_multiline.php
   trunk/mapbender/http/classes/class_gml_multipolygon.php
   trunk/mapbender/http/classes/class_gml_point.php
   trunk/mapbender/http/classes/class_gml_polygon.php
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/classes/class_ows.php
   trunk/mapbender/http/classes/class_universal_gml_factory.php
   trunk/mapbender/http/classes/class_wfs.php
Log:
bug fixes and wfs-t redesign

Modified: trunk/mapbender/http/classes/class_gml.php
===================================================================
--- trunk/mapbender/http/classes/class_gml.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -22,17 +22,31 @@
 require_once(dirname(__FILE__)."/../classes/class_json.php");
 require_once(dirname(__FILE__)."/../classes/class_gml_feature_collection.php");
 
-class Gml {
+abstract class Gml {
 	var $featureCollection = null;
 	var $geomFeaturetypeElement;
 	var $doc;
 	
+	abstract public function toGml ();
+	
 	public function toGeoJSON () {
 		if ($this->featureCollection === null) {
 			return null;
 		}
 		return $this->featureCollection->toGeoJSON();
 	}	
+	
+	/**
+	 * Shortcut for GeoJSON conversion
+	 * 
+	 * @return String
+	 * @param $geoJson String
+	 */
+	public static function geoJsonToGml ($geoJson) {
+		$gmlFactory = new UniversalGmlFactory();
+		$myGmlObj = $gmlFactory->createFromGeoJson($geoJson);
+		return $myGmlObj->toGml();
+	}
 }
 
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml_2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_2.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -23,5 +23,18 @@
 require_once(dirname(__FILE__)."/../classes/class_gml.php");
 
 class Gml_2 extends Gml {
+	public function toGml () {
+		
+		$str = "";
+		foreach ($this->featureCollection->featureArray as $feature) {
+			if (!$feature->geometry) {
+				$e = new mb_exception("Feature doesn't have a geometry.");
+				return null;
+			}
+			$geometry = $feature->geometry;
+			$str .= $geometry->toGml2();
+		}
+		return $str;
+	}
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml_2_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_2_factory.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_2_factory.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -30,6 +30,18 @@
  */
 class Gml_2_Factory extends GmlFactory {
 
+	/**
+	 * Creates a GML object from a GeoJSON (http://www.geojson.org) String
+	 * 
+	 * @return Gml_3
+	 * @param $geoJson String
+	 */
+	public function createFromGeoJson ($geoJson) {
+		$gml2 = new Gml_2();
+		
+		return parent::createFromGeoJson($geoJson, $gml2);
+	}
+
 	function findNameSpace($s){
 		list($ns,$FeaturePropertyName) = split(":",$s);
 		$nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName);

Modified: trunk/mapbender/http/classes/class_gml_3.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_3.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -23,5 +23,10 @@
 require_once(dirname(__FILE__)."/../classes/class_gml.php");
 
 class Gml_3 extends Gml {
+
+	public function toGml () {
+		
+	}
+
 }
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml_3_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_3_factory.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_3_factory.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -31,6 +31,18 @@
 class Gml_3_Factory extends GmlFactory {
 
 	/**
+	 * Creates a GML object from a GeoJSON (http://www.geojson.org) String
+	 * 
+	 * @return Gml_3
+	 * @param $geoJson String
+	 */
+	public function createFromGeoJson ($geoJson) {
+		$gml3 = new Gml_3();
+		
+		return parent::createFromGeoJson($geoJson, $gml3);
+	}
+
+	/**
 	 * Creates GML 3 objects from GML documents.
 	 * 
 	 * @return Gml_3

Modified: trunk/mapbender/http/classes/class_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_factory.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_factory.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -20,6 +20,7 @@
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_connector.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
 
 /**
  * Creates GML objects from GML documents.
@@ -33,6 +34,142 @@
 	}
 	
 	/**
+	 * Creates a GML object from a GeoJSON (http://www.geojson.org) String
+	 * 
+	 * @return Gml
+	 * @param $geoJson String
+	 */
+	public function createFromGeoJson ($geoJson, $gml) {
+		$json = new Mapbender_JSON ();
+		$jsonObj = $json->decode($geoJson);
+
+		// check if valid feature collection
+		new mb_exception("Is Array? " . is_array($jsonObj->features));
+		new mb_exception("Type? " . strtoupper($jsonObj->type));
+		if (strtoupper($jsonObj->type) != "FEATURECOLLECTION" || !is_array($jsonObj->features)) {
+			$e = new mb_exception("Not a valid GeoJSON Feature Collection.");
+			return null;
+		}
+
+		$gml->featureCollection = new FeatureCollection();
+		foreach ($jsonObj->features as $currentFeature) {
+			$feature = new Feature();
+			if (!is_object($currentFeature->crs) || $currentFeature->crs->type !== "name") {
+				$e = new mb_exception("Feature doesn't have a SRS.");
+				return null;
+			}
+			$srs = $currentFeature->crs->properties->name;
+
+			// set geometry
+			if (is_object($currentFeature->geometry)) {
+				$currentGeometry = $currentFeature->geometry;
+				switch (strtoupper($currentGeometry->type)) {
+					case "POLYGON":
+						$geometry = new GMLPolygon();
+						for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
+							$currentRing = $currentGeometry->coordinates[$i];
+							
+							foreach ($currentRing as $coords) {
+								list($x, $y) = $coords;
+	
+								// exterior ring							
+								if (0 == $i) {
+									$geometry->addPoint($x, $y);
+								}
+								// interior ring
+								else {
+									$geometry->addPointToRing($i, $x, $y);
+								}
+							}
+						}
+						break;
+					case "POINT":
+						$geometry = new GMLPoint();
+						list($x, $y) = $currentGeometry->coordinates;
+						$geometry->setPoint($x, $y);
+						break;
+					case "LINESTRING":
+						$geometry = new GMLLine();
+						for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
+							$currentLinePoint = $currentGeometry->coordinates[$i];
+							list($x, $y) = $currentLinePoint;
+							$geometry->addPoint($x, $y);
+						}
+						break;
+					case "MULTIPOLYGON":
+						$geometry = new GMLMultiPolygon();
+						for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
+							$currentPolygon = $currentGeometry->coordinates[$i];
+								
+							for ($j = 0; $j < count($currentPolygon); $j++) {
+								$currentRing = $currentPolygon[$j];
+								
+								foreach ($currentRing as $coords) {
+									list($x, $y) = $coords;
+		
+									// exterior ring							
+									if (0 == $j) {
+										$geometry->addPoint($x, $y, $i);
+									}
+									// interior ring
+									else {
+										$geometry->addPointToRing($i, $j-1, $x, $y);
+									}
+								}
+							}
+						}
+						break;
+					case "MULTIPOINT":
+						$e = new mb_exception($currentGeometry->type . " are not supported!");
+						return null;
+						break;
+					case "MULTILINESTRING": // not tested!
+						$geometry = new GMLMultiLine();
+						for ($i = 0; $i < count($currentGeometry->coordinates); $i++) {
+							$currentLine = $currentGeometry->coordinates[$i];
+							foreach ($currentLine as $currentLinePoint) {
+								list($x, $y) = $currentLinePoint;
+								$geometry->addPoint($x, $y, $i);
+							}
+						}
+						break;
+					case "GEOMETRYCOLLECTION":
+						$e = new mb_exception($currentGeometry->type . " are not supported!");
+						return null;
+						break;
+					default:
+						$e = new mb_exception($currentGeometry->type . " is not a valid geometry type");
+						return null;
+						break;
+				}
+				// add the geometry to the feature
+				$geometry->srs = $srs;
+				$feature->geometry = $geometry;
+			}
+			else {
+				$e = new mb_exception("This feature does not have a geometry.");
+				return null;
+			}
+			
+
+			// set fid and properties
+			if (is_object($currentFeature->properties)) {
+				foreach ($currentFeature->properties as $pName => $pValue) {
+					if ("fid" == $pName) {
+						$feature->fid = $pValue;
+					}
+					else {
+						$feature->properties[$pName] = $pValue;
+					}
+				}
+			}
+
+			$gml->featureCollection->addFeature($feature);
+		}
+		return $gml;
+	}
+
+	/**
 	 * Creates GML objects from GML documents.
 	 * 
 	 * @return Gml

Added: trunk/mapbender/http/classes/class_gml_geometry.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_geometry.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_gml_geometry.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -0,0 +1,35 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_feature_collection.php");
+
+abstract class GmlGeometry {
+
+	abstract public function toGml2 ();
+
+	abstract public function toGml3 ();
+	
+	abstract public function toGeoJSON ();
+	
+	public $srs;
+}
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/classes/class_gml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_line.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_line.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -19,9 +19,10 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
 
 
-class GMLLine {
+class GMLLine extends GmlGeometry {
 
 	var $pointArray = array();
 
@@ -33,6 +34,25 @@
 		array_push($this->pointArray, array("x" => $x, "y" => $y));
 	}
 	
+	public function toGml2 () {
+		$str = "<gml:MultiLineString srsName=\"$this->srs\">" . 
+			"<gml:lineStringMember><gml:LineString><gml:coordinates>";
+
+		$ptArray = array();
+		foreach ($this->pointArray as $point) {
+			$ptArray[] = $point["x"] . "," . $point["y"];
+		}
+		$str .= implode(" ", $ptArray);
+
+		$str .= "</gml:coordinates></gml:LineString></gml:lineStringMember>";
+		$str .= "</gml:MultiLineString>";		
+		return $str;
+	}
+	
+	public function toGml3 () {
+		
+	}
+
 	public function toGeoJSON () {
 		$numberOfPoints = count($this->pointArray);
 		$str = "";

Modified: trunk/mapbender/http/classes/class_gml_multiline.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multiline.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_multiline.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -19,9 +19,10 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
 
 
-class GMLMultiLine {
+class GMLMultiLine extends GmlGeometry {
 
 	var $lineArray = array();
 
@@ -33,6 +34,25 @@
 		array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
 	}
 	
+	public function toGml2 () {
+		$str = "<gml:MultiLineString srsName='$srsName'>";
+		foreach ($this->lineArray as $line) {
+			$str .=	"<gml:lineStringMember><gml:LineString><gml:coordinates>";
+			$ptArray = array();
+			foreach ($line as $point) {
+				$ptArray[] = $point["x"] . "," . $point["y"];
+			}
+			$str .= implode(" ", $ptArray);
+			$str .= "</gml:coordinates></gml:LineString>";
+		}
+		$str .=	"<gml:lineStringMember><gml:MultiLineString>";
+		return $str;		
+	}
+	
+	public function toGml3 () {
+		
+	}
+
 	public function toGeoJSON () {
 		$numberlineArray = count($this->lineArray);
 		$str = "";

Modified: trunk/mapbender/http/classes/class_gml_multipolygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_multipolygon.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_multipolygon.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -19,8 +19,9 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
 
-class GMLMultiPolygon {
+class GMLMultiPolygon extends GmlGeometry {
 
 	var $polygonArray = array();
 	var $innerRingArray = array();
@@ -30,17 +31,65 @@
 	}
 
 	public function addPointToRing ($i, $j, $x, $y) {
-		if (count($this->innerRingArray[$i]) <= $j) {
+		while (count($this->innerRingArray) <= $i) {
+			array_push($this->innerRingArray, array());
+		}
+		while (count($this->innerRingArray[$i]) <= $j) {
 			array_push($this->innerRingArray[$i], array());
 		}
 		array_push($this->innerRingArray[$i][$j], array("x" => $x, "y" => $y));
 	}
 	
 	public function addPoint ($x, $y, $i) {
-
+		while (count($this->polygonArray) <= $i) {
+			array_push($this->polygonArray, array());
+		}
 		array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
 	}
+
+	public function toGml2 () {
+		$str .= "<gml:MultiPolygon srsName='$srsName'>";
+		for ($i = 0; $i < count($this->polygonArray); $i++) {
+			$str .= "<gml:polygonMember><gml:Polygon>" . 
+				"<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+
+			$currentExteriorRing = $this->polygonArray[$i];
+			
+			$ptArray = array();
+			for ($j = 0; $j < count($currentExteriorRing); $j++) {
+				$point = $currentExteriorRing[$j];
+				$ptArray[] = $point["x"] . "," . $point["y"];
+			}
+			$str .= implode(" ", $ptArray);
+			$str .= "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+			
+			// interior rings exist
+			if (count($this->innerRingArray) > $i && count($this->innerRingArray[$i]) > 0) {
+
+				for ($j = 0; $j < count($this->innerRingArray[$i]); $j++) {
+					$currentInteriorRing = $this->innerRingArray[$i][$j];
+					$str .= "<gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>";
+					$ptArray = array();
+					for ($k = 0; $k < count($currentInteriorRing); $k++) {
+						$point = $currentInteriorRing[$k];
+						$ptArray[] = $point["x"] . "," . $point["y"];
+					}
+					$str .= implode(" ", $ptArray);
+					$str .= "</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs>";
+				}
+
+			}
+			$str .= "</gml:Polygon></gml:polygonMember>";
+		}
+		$str .= "</gml:MultiPolygon>";
+
+		return $str;		
+	}
 	
+	public function toGml3 () {
+		
+	}
+	
 	public function toGeoJSON () {
 		$numberPolygonArray = count($this->polygonArray);
 		$str = "";

Modified: trunk/mapbender/http/classes/class_gml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_point.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_point.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -19,8 +19,9 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
 
-class GMLPoint {
+class GMLPoint extends GmlGeometry {
 
 	var $point;
 
@@ -33,6 +34,17 @@
 		$this->point = array("x" => $x, "y" => $y);
 	}
 	
+	public function toGml2 () {
+		$str = "<gml:Point srsName='$this->srs'><gml:coordinates>";
+		$str .= $this->point["x"] . "," . $this->point["y"];
+		$str .= "</gml:coordinates></gml:Point>";
+		return $str;		
+	}
+	
+	public function toGml3 () {
+		
+	}
+
 	public function toGeoJSON () {
 		$str = "";
 		if ($this->point) {

Modified: trunk/mapbender/http/classes/class_gml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_gml_polygon.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_gml_polygon.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -19,9 +19,10 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml_geometry.php");
 
 
-class GMLPolygon {
+class GMLPolygon extends GmlGeometry {
 
 	var $pointArray = array();
 	var $innerRingArray = array();
@@ -44,6 +45,37 @@
 		array_push($this->innerRingArray[$currentIndex], array("x" => $x, "y" => $y));
 	}
 	
+	public function toGml2 () {
+		$str = "<gml:MultiPolygon srsName=\"$this->srs\">" . 
+			"<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs>" . 
+			"<gml:LinearRing><gml:coordinates>";
+
+		$ptArray = array();
+		foreach ($this->pointArray as $point) {
+			$ptArray[] = $point["x"] . "," . $point["y"];
+		}
+		$str .= implode(" ", $ptArray);
+
+		$str .= '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>';
+				
+		foreach ($this->innerRingArray as $ring) {
+			$str .= "<gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>";
+			$ptArray = array();
+			foreach ($ring as $point) {
+				$ptArray[] = $point["x"] . "," . $point["y"];
+			}
+			$str .= implode(" ", $ptArray);
+			
+			$str .= "</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs>";
+		}
+		$str .= "</gml:Polygon></gml:polygonMember></gml:MultiPolygon>";
+		return $str;
+	}
+	
+	public function toGml3 () {
+		
+	}
+	
 	public function toGeoJSON () {
 		$numberOfPoints = count($this->pointArray);
 		$str = "";

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_map.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -106,8 +106,39 @@
 	public function getExtent () {
 		return $this->extent;	
 	}
+
+	/**
+	 * 
+	 * @return Mapbender_bbox extent information
+	 */
+	public function getExtentInfo () {
+		return array($this->extent->min->x, $this->extent->min->y, $this->extent->max->x, $this->extent->max->y);	
+	}	
 	
 	/**
+	 * converts the extent of the map so that the maximum	extent will be displayed
+	 *
+	 */
+	public function calculateExtent($aMapbenderBbox) {
+		$relation_px_x = $this->getWidth() / $this->getHeight();
+		$relation_px_y = $this->getHeight() / $this->getWidth();
+		$extentx = ($aMapbenderBbox->max->x - $aMapbenderBbox->min->x);
+		$extenty = ($aMapbenderBbox->max->y - $aMapbenderBbox->min->y);
+		$centerx = $aMapbenderBbox->min->x + $extentx/2;
+		$centery = $aMapbenderBbox->min->y + $extenty/2;
+		$relation_bbox_x = $extentx / $extenty;     
+		if($relation_bbox_x <= $relation_px_x){                
+			$aMapbenderBbox->min->x = $centerx - $relation_px_x * $extenty / 2;
+			$aMapbenderBbox->max->x = $centerx + $relation_px_x * $extenty / 2;
+		}
+		if($relation_bbox_x > $relation_px_x){                
+			$aMapbenderBbox->min->y = $centery - $relation_px_y * $extentx / 2;
+			$aMapbenderBbox->max->y = $centery + $relation_px_y * $extentx / 2;
+		}
+		$this->setExtent($aMapbenderBbox);
+	}
+		
+	/**
 	 * 
 	 * @return String EPSG code of the map.
 	 */

Modified: trunk/mapbender/http/classes/class_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_ows.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_ows.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -56,7 +56,7 @@
 	 */
 	final protected function getNameSpace($s) {
 		$c = strpos($s, ":"); 
-		if ($c > 0) {
+		if ($c !== false) {
 			return substr($s, 0, $c);
 		}
 		return $s;

Modified: trunk/mapbender/http/classes/class_universal_gml_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_universal_gml_factory.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_universal_gml_factory.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -56,6 +56,17 @@
 	}
 
 	/**
+	 * Creates a GML object from a GeoJSON (http://www.geojson.org) String
+	 * 
+	 * @return Gml
+	 * @param $geoJson String
+	 */
+	public function createFromGeoJson ($geoJson) {
+		$gml2Factory = new Gml_2_Factory();
+		return $gml2Factory->createFromGeoJson($geoJson);
+	}
+	
+	/**
 	 * Creates a GML object by parsing its XML representation. 
 	 * 
 	 * The GML version is determined by parsing 

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2009-02-18 17:33:40 UTC (rev 3572)
+++ trunk/mapbender/http/classes/class_wfs.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -20,8 +20,10 @@
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/class_connector.php");
 require_once(dirname(__FILE__)."/class_administration.php");
+require_once(dirname(__FILE__)."/class_gml.php");
 require_once(dirname(__FILE__)."/class_ows.php");
 require_once(dirname(__FILE__)."/class_wfsToDb.php");
+require_once(dirname(__FILE__)."/class_wfs_configuration.php");
 
 /**
  * An abstract Web Feature Service (WFS) class, modelling for example
@@ -52,9 +54,20 @@
 				return $ft;
 			}
 		}
+		new mb_exception("This WFS doesn't have a featuretype with name " . $name);
 		return null;
 	}
 	
+	protected function findFeatureTypeById ($id) {
+		foreach ($this->featureTypeArray as $ft) {
+			if ($ft->id == $id) {
+				return $ft;
+			}
+		}
+		new mb_exception("This WFS doesn't have a featuretype with ID " . $id);
+		return null;
+	}
+	
 	protected function getFeatureGet ($featureTypeName, $filter) {
 		$url = $this->getFeature .
 				$this->getConjunctionCharacter($this->getFeature) . 
@@ -72,6 +85,20 @@
 		return $data;
 	}
 	
+	protected function post ($url, $postData) {
+		$connection = new connector();
+		$connection->set("httpType", "post");
+		$connection->set("httpContentType", "xml");
+		$connection->set("httpPostData", $postData);
+		
+		$data = $connection->load($url);
+		if (!$data) {
+			$e = new mb_exception("WFS request returned no result: " . $url . "\n" . $postData);
+			return null;
+		}
+		return $data;
+	}
+	
 	protected function getFeaturePost ($featureTypeName, $filter) {
 		$postData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 
 			"<wfs:GetFeature version=\"" . $this->getVersion() . "\" " . 
@@ -89,18 +116,7 @@
 		$postData .= "typeName=\"" . $featureTypeName . "\"/>" . 
 			"</wfs:GetFeature>";		
 
-		$connection = new connector();
-		$connection->set("httpType", "post");
-		$connection->set("httpContentType", "xml");
-		$connection->set("httpPostData", $postData);
-		
-		$data = $connection->load($this->getFeature);
-		
-		if (!$data) {
-			$e = new mb_exception("WFS request returned no result: " . $url . "\n" . $postData);
-			return null;
-		}
-		return $data;
+		return $this->post($this->getFeature, $postData);
 	}
 	
 	public function getFeature ($featureTypeName, $filter) {
@@ -110,7 +126,194 @@
 		return $this->getFeatureGet($featureTypeName, $filter);
 	}
 	
+	/**
+	 * Performs a WFS transaction (delete, update or insert).
+	 * 
+	 * @return String the WFS reply
+	 * @param $method String "delete", "update" or "insert"
+	 * @param $wfsConf WfsConfiguration
+	 * @param $gmlObj Gml
+	 */
+	public function transaction ($method, $wfsConf, $gmlObj) {
+		
+		//
+		// get feature type and geometry column from WFS configuration
+		//
+		if (!($wfsConf instanceof WfsConfiguration)) {
+			$e = new mb_exception("Invalid WFS configuration.");
+			return null;
+		}
+		$featureType = $this->findFeatureTypeById($wfsConf->featureTypeId);
+		$featureTypeName = $featureType->name;
+		$geomColumnName = $wfsConf->getGeometryColumnName();
+
+		//
+		// GML string
+		//
+		if (!($gmlObj instanceof Gml)) {
+			$e = new mb_exception("Not a GML object.");
+			return null;
+		}
+		$gml = $gmlObj->toGml();
+		if (is_null($gml)) {
+			$e = new mb_exception("GML is not set.");
+			return null;
+		}
+		
+		// I assume that only one feature is contained in the GeoJSON,
+		// so I just take the first from the collection.
+		$feature = $gmlObj->featureCollection->featureArray[0];
+
+
+		switch ($method) {
+			case "delete":
+				$requestData = $this->transactionDelete($feature, $featureTypeName);
+				break;
+			case "update":
+				$requestData = $this->transactionUpdate($feature, $featureTypeName, $gml, $geomColumnName);
+				break;
+			case "insert":
+				$requestData = $this->transactionInsert($feature, $featureTypeName, $gml, $geomColumnName);
+				break;
+			default:
+				$e = new mb_exception("Invalid transaction method: " . $method);
+				return null;
+		}		
+
+		$postData = $this->wrapTransaction($featureType, $requestData);
+		return $this->post($this->transaction, $postData);
+	}
 	
+	protected function transactionInsert ($feature, $featureTypeName, $gml, $geomColumnName) {
+		// add properties
+		$propertiesSegment = "";
+		foreach ($feature->properties as $key => $value) {
+			if (isset($value)) {
+				$propertiesSegment .= "<$key><![CDATA[$value]]></$key>";
+			}
+		}
+
+		// add spatial data
+		$geomSegment = "<$geomColumnName>" . $gml . "</$geomColumnName>";
+
+		return "<wfs:Insert><$featureTypeName>" . $propertiesSegment . 
+					$geomSegment . "</$featureTypeName></wfs:Insert>";
+	}
+	
+	protected function transactionUpdate ($feature, $featureTypeName, $gml, $geomColumnName) {
+		// add properties
+		$propertiesSegment = "";
+		foreach ($feature->properties as $key => $value) {
+			if (isset($value)) {
+				$propertiesSegment .= "<wfs:Property><wfs:Name>$key</wfs:Name>" . 
+					"<wfs:Value><![CDATA[$value]]></wfs:Value></wfs:Property>";
+			}
+		}
+
+		// filter
+		if (!isset($feature->fid)) {
+			$e = new mb_exception("Feature ID not set.");
+			return null;
+		}
+		$filterSegment = "<ogc:Filter><ogc:FeatureId fid=\"$feature->fid\"/></ogc:Filter>";
+
+		// add geometry
+		$geomSegment = "<wfs:Property><wfs:Name>$geomColumnName</wfs:Name>" . 
+			"<wfs:Value>" . $gml . "</wfs:Value></wfs:Property>";
+					
+
+		return "<wfs:Update typeName=\"$featureTypeName\">" . 
+				$propertiesSegment . 
+				$geomSegment . 
+				$filterSegment . 
+				"</wfs:Update>";
+	}
+	
+	protected function transactionDelete ($feature, $featureTypeName) {
+		// filter
+		if (!isset($feature->fid)) {
+			$e = new mb_exception("Feature ID not set.");
+			return null;
+		}
+
+		return "<wfs:Delete typeName=\"$featureTypeName\">" . 
+			"<ogc:Filter><ogc:FeatureId fid=\"$feature->fid\"/></ogc:Filter>" . 
+			"</wfs:Delete>";
+	}
+	
+	protected function wrapTransaction ($featureType, $wfsRequest) {
+		$featureNS = $this->getNameSpace($featureType->name);
+		
+		$str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . 
+			"<wfs:Transaction version=\"" . $this->getVersion() . 
+			"\" service=\"WFS\" ";
+
+		$ns_gml = false;
+		$ns_ogc = false;
+		$ns_xsi = false;
+		$ns_wfs = false;
+		$ns_featureNS = false;
+
+		foreach ($featureType->namespaceArray as $namespace) {
+
+			if ($namespace->name == "gml"){
+				 $ns_gml = true;
+				 $str .= "xmlns:" . $namespace->name . 
+				 	"=\"" . $namespace->value . "\" ";
+			} 
+			else if ($namespace->name == "ogc") {
+				$ns_ogc = true;
+				$str .= "xmlns:" . $namespace->name . 
+					"=\"" . $namespace->value . "\" ";
+			} 
+			else if ($namespace->name == "xsi") {
+				$ns_xsi = true;
+				$str .= "xmlns:" . $namespace->name . 
+					"=\"" . $namespace->value . "\" ";
+			} 
+			else if ($namespace->name == "wfs") {
+				$ns_wfs = true;
+				$str .= "xmlns:" . $namespace->name . 
+					"=\"" . $namespace->value . "\" ";
+			} 
+			else if ($namespace->name == $featureNS) {
+				$ns_featureNS = true;
+				$str .= "xmlns:" . $namespace->name .
+					"=\"" . $namespace->value . "\" ";
+				$strForSchemaLocation = $namespace->value;
+			}
+		}
+
+		if (!$ns_gml) {
+			$str .= 'xmlns:gml="http://www.opengis.net/gml" ';	
+		}
+		if (!$ns_ogc) {
+			$str .= 'xmlns:ogc="http://www.opengis.net/ogc" ';	
+		}
+		if (!$ns_xsi) {
+			$str .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
+		} 
+		if (!ns_featureNS) {
+			$str .= "xmlns:" . $featureNS . "=\"http://www.someserver.com/" . $featureNS . "\" ";	
+		}
+		if (!$ns_wfs) {
+			$str .= "xmlns:wfs=\"http://www.opengis.net/wfs\" ";	
+		}
+
+		$str .= "xsi:schemaLocation=\"http://www.opengis.net/wfs";
+		$str .= " http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd";
+		$str .= " " . $strForSchemaLocation;
+		$str .= " " . $this->describeFeatureType;
+		//$str .= mb_getConjunctionCharacter(myconf['wfs_describefeaturetype']);
+		//$str .= 'typename=' + myconf['featuretype_name'];
+		$str .= "\">";		
+		
+		$str .= $wfsRequest;
+		
+		$str .= "</wfs:Transaction>";
+		return $str;
+	}
+	
 	// -----------------------------------------------------------------------
 	//
 	// Output formats

Added: trunk/mapbender/http/classes/class_wfs_configuration.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_configuration.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_wfs_configuration.php	2009-02-18 17:36:04 UTC (rev 3573)
@@ -0,0 +1,170 @@
+<?php
+# $Id: class_wfs_conf.php 3510 2009-02-03 10:36:01Z christoph $
+# http://www.mapbender.org/index.php/class_wfs_conf.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_user.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+class WfsConfigurationElement {
+	var $name;
+	var $type;
+	var $search;
+	var $styleId;
+	var $toUpper;
+	var $label;
+	var $labelId;
+	var $geom;
+	var $show;
+	var $mandatory;
+	var $respos;
+	var $minInput;
+	var $formElementHtml;
+	var $authVarname;
+	var $detailPos;
+	var $operator;
+	var $showDetail;
+}	
+
+
+class WfsConfiguration {
+	
+	var $id;
+	var $wfsId;
+	var $featureTypeId;
+	var $label; 
+	var $labelId;
+	var $style;
+	var $button;
+	var $buttonId;
+	var $buffer;
+	var $resStyle;
+	var $elementArray = array();
+
+	function __construct () {
+	}
+	
+	public function getGeometryColumnName () {
+		foreach ($this->elementArray as $element) {
+			if ($element->geom) {
+				return $element->name;
+			}
+		}
+		$e = new mb_warning("This WFS conf doesn't have a geometry column.");
+		return null;
+	}
+	
+	/**
+	 * Checks if the user currently logged in is allowed to access
+	 * the WFS configuration
+	 * 
+	 * @return Boolean
+	 */
+	private function accessAllowed () {
+		if ($_SESSION["mb_user_id"]) {
+			$user = new User($_SESSION["mb_user_id"]);
+
+			$allowedWfsConfIds = $user->getWfsConfByPermission();
+
+			$idArray = array_intersect(array($this->id), $allowedWfsConfIds);
+
+			if (count($idArray) === 1) {
+				return true;
+			}
+		}
+		return false;
+	}
+	
+	/**
+	 * Creates an object from the database.
+	 * Maybe we could have a factory for this later...let's
+	 * keep it simple for now
+	 * 
+	 * @return WfsConfiguration
+	 * @param $id Integer
+	 */
+	public static function createFromDb ($id) {
+		if (!is_numeric($id)) {
+			return null;	
+		}
+		$wfsConf = new WfsConfiguration();
+		$wfsConf->id = intval($id);
+		
+		if (!$wfsConf->accessAllowed()) {
+			return null;
+		}
+		
+		$sql = <<<SQL
+SELECT * FROM wfs_conf JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id 
+WHERE wfs_conf.wfs_conf_id = $1 LIMIT 1
+SQL;
+
+        $v = array($wfsConf->id);
+        $t = array("i");
+        $res = db_prep_query($sql, $v, $t);
+        $row = db_fetch_array($res);
+		
+		$wfsConf->label = $row["g_label"];
+		$wfsConf->labelId = $row["g_label_id"];
+		$wfsConf->style = $row["g_style"];
+		$wfsConf->button = $row["g_button"];
+		$wfsConf->buttonId = $row["g_button_id"];
+		$wfsConf->buffer = $row["g_buffer"];
+		$wfsConf->resStyle = $row["g_res_style"];
+		$wfsConf->wfsId = $row["fkey_wfs_id"];
+		$wfsConf->featureTypeId = $row["fkey_featuretype_id"];
+
+		$sql = <<<SQL
+SELECT * FROM wfs_conf_element JOIN wfs_element 
+ON wfs_conf_element.f_id = wfs_element.element_id 
+WHERE wfs_conf_element.fkey_wfs_conf_id = $1
+SQL;
+		$v = array($wfsConf->id);
+		$t = array('i');
+		$res = db_prep_query($sql, $v, $t);
+	
+		
+		while ($row = db_fetch_array($res)) {
+			$element = new WfsConfigurationElement();
+
+			$element->name = $row["element_name"];
+			$element->type = $row["element_type"];
+			$element->search = $row["f_search"];
+			$element->styleId = $row["f_style_id"];
+			$element->toUpper = $row["f_toupper"];
+			$element->label = $row["f_label"];
+			$element->labelId = $row["f_label_id"];
+			$element->geom = $row["f_geom"];
+			$element->show = $row["f_show"];
+			$element->mandatory = $row["f_mandatory"];
+			$element->respos = $row["f_respos"];
+			$element->minInput = $row["f_min_input"];
+			$element->formElementHtml = $row["f_form_element_html"];
+			$element->authVarname = $row["f_auth_varname"];
+			$element->detailpos = $row["f_detailpos"];
+			$element->operator = $row["f_operator"];
+			$element->showDetail = $row["f_show_detail"];
+
+			array_push($wfsConf->elementArray, $element);
+		}
+		
+		return $wfsConf;
+	}
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list