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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Dec 15 08:27:27 EST 2008


Author: christoph
Date: 2008-12-15 08:27:27 -0500 (Mon, 15 Dec 2008)
New Revision: 3317

Modified:
   trunk/mapbender/http/classes/class_gml2.php
   trunk/mapbender/http/classes/class_wfs_conf.php
   trunk/mapbender/http/php/mod_wfs_result.php
Log:
http://trac.osgeo.org/mapbender/ticket/347

Modified: trunk/mapbender/http/classes/class_gml2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml2.php	2008-12-15 13:25:44 UTC (rev 3316)
+++ trunk/mapbender/http/classes/class_gml2.php	2008-12-15 13:27:27 UTC (rev 3317)
@@ -17,10 +17,10 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-require_once(dirname(__FILE__)."/../../core/globalSettings.php");
-require_once(dirname(__FILE__)."/../classes/class_connector.php");
-require_once(dirname(__FILE__)."/../classes/class_json.php");
-
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
 class gml2 {
 	var $geomtype_point = 'Point';					
 	var $geomtype_polygon = 'Polygon';
@@ -35,6 +35,7 @@
 	var $geometry = array();
 	var $bbox = array();
 	var $doc;
+	var $geomFeaturetypeElement = null;
 	
 	
 	function gml2(){
@@ -55,7 +56,9 @@
 	}
 	
 	function parseXML($data) {
-		
+		if (func_num_args() == 2) {
+			$this->geomFeaturetypeElement = func_get_arg(1);
+		}
 		$this->doc = $this->removeWhiteSpace($data);
 		return $this->toGeoJSON();
 	}
@@ -93,7 +96,12 @@
 				$featureMember_dom = dom_import_simplexml($gmlFeatureMember);
 				
 				$feature = new Feature();
-				$feature->parse($featureMember_dom);
+				if ($this->geomFeaturetypeElement != null) {
+					$feature->parse($featureMember_dom, $this->geomFeaturetypeElement);
+				}
+				else {
+					$feature->parse($featureMember_dom);
+				}
 				if (isset($feature->geometry)) {
 					$featureCollection->addFeature($feature);
 				}
@@ -198,7 +206,7 @@
 		xml_parser_free($parser);
 		
 		foreach ($values as $element) {
-			#$e = new mb_exception($element[tag]);
+			#$e = new mb_exception($element[tag]);
 			if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
 				$boundedBy = true;
 			}
@@ -360,10 +368,10 @@
 		elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
 			$js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
 		}
-		else{
-			$e = new mb_notice("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."' or no geometry existing");
-			return "";
-		}	
+		else{
+			$e = new mb_notice("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."' or no geometry existing");
+			return "";
+		}	
 		
 		$js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
 		
@@ -422,6 +430,7 @@
 	var $fid;
 	var $geometry = false;
 	var $properties = array();
+	var $geomFeaturetypeElement = null;
 	
 	public function __construct() {
 	}
@@ -432,50 +441,54 @@
 		return $nodeName;
 	}
 	
-	/**
-	 * Parses the feature segment of a GML and stores the geometry in the
-	 * $geometry variable of the class.
-	 * 	
-	 * Example of a feature segment of a GML. 
-	 * 	<gml:featureMember>
-	 * 		<ms:ROUTE fid="ROUTE.228168">
-	 * 			<gml:boundedBy>
-	 * 				<gml:Box srsName="EPSG:31466">
-	 * 					<gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
-	 * 				</gml:Box>
-	 * 			</gml:boundedBy>
-	 * 			<ms:geometry>
-	 * 				<gml:LineString>
-	 * 					<gml:coordinates>
-	 * 						2557380.97,5562526 2557390.96,
-	 * 						5562523.22 2557404.03,5562518.2 2557422.31,
-	 * 						5562512 2557437.16,5562508.37 2557441.79,
-	 * 						5562507.49 2557454.31,5562505.1 2557464.27,
-	 * 						5562503.97 2557473.24,5562502.97 2557491.67,
-	 * 						5562502.12 2557505.65,5562502.43 2557513.78,
-	 * 						5562501.12 2557520.89,5562498.79 2557528.5,
-	 * 						5562495.07 2557538.9,5562488.91 2557549.5,
-	 * 						5562483.83 2557558.55,5562476.61 2557569.07,
-	 * 						5562469.82 2557576.61,5562462.72 2557582.75,
-	 * 						5562457.92 2557588.57,5562452.56 2557590.38,
-	 * 						5562449.69 2557593.57,5562445.07 2557596.17,
-	 * 						5562441.31 2557601.71,5562433.93 2557612.97,
-	 * 						5562421.03 2557626,5562405.33 2557639.66,
-	 * 						5562389.75 2557653.69,5562371.12 
-	 * 					</gml:coordinates>
-	 * 				</gml:LineString>
-	 * 			</ms:geometry>
-	 * 			<code>354</code>
-	 * 			<Verkehr>0</Verkehr>
-	 * 			<rlp>t</rlp>
-	 * 		</ms:ROUTE>
-	 * 	</gml:featureMember>
-	 * 
-	 * @return void
-	 * @param $domNode DOMNodeObject the feature tag of the GML 
-	 * 								(<gml:featureMember> in the above example)
-	 */
+	/**
+	 * Parses the feature segment of a GML and stores the geometry in the
+	 * $geometry variable of the class.
+	 * 	
+	 * Example of a feature segment of a GML. 
+	 * 	<gml:featureMember>
+	 * 		<ms:ROUTE fid="ROUTE.228168">
+	 * 			<gml:boundedBy>
+	 * 				<gml:Box srsName="EPSG:31466">
+	 * 					<gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
+	 * 				</gml:Box>
+	 * 			</gml:boundedBy>
+	 * 			<ms:geometry>
+	 * 				<gml:LineString>
+	 * 					<gml:coordinates>
+	 * 						2557380.97,5562526 2557390.96,
+	 * 						5562523.22 2557404.03,5562518.2 2557422.31,
+	 * 						5562512 2557437.16,5562508.37 2557441.79,
+	 * 						5562507.49 2557454.31,5562505.1 2557464.27,
+	 * 						5562503.97 2557473.24,5562502.97 2557491.67,
+	 * 						5562502.12 2557505.65,5562502.43 2557513.78,
+	 * 						5562501.12 2557520.89,5562498.79 2557528.5,
+	 * 						5562495.07 2557538.9,5562488.91 2557549.5,
+	 * 						5562483.83 2557558.55,5562476.61 2557569.07,
+	 * 						5562469.82 2557576.61,5562462.72 2557582.75,
+	 * 						5562457.92 2557588.57,5562452.56 2557590.38,
+	 * 						5562449.69 2557593.57,5562445.07 2557596.17,
+	 * 						5562441.31 2557601.71,5562433.93 2557612.97,
+	 * 						5562421.03 2557626,5562405.33 2557639.66,
+	 * 						5562389.75 2557653.69,5562371.12 
+	 * 					</gml:coordinates>
+	 * 				</gml:LineString>
+	 * 			</ms:geometry>
+	 * 			<code>354</code>
+	 * 			<Verkehr>0</Verkehr>
+	 * 			<rlp>t</rlp>
+	 * 		</ms:ROUTE>
+	 * 	</gml:featureMember>
+	 * 
+	 * @return void
+	 * @param $domNode DOMNodeObject the feature tag of the GML 
+	 * 								(<gml:featureMember> in the above example)
+	 */
 	public function parse($domNode) {
+		if (func_num_args() == 2) {
+			$this->geomFeaturetypeElement = func_get_arg(1);
+		}
+
 		$currentSibling = $domNode->firstChild;
 		
 		$this->fid = $currentSibling->getAttribute("fid");
@@ -490,13 +503,14 @@
 			$namespace = $this->sepNameSpace($name);
 			$ns = $namespace['ns'];
 			$columnName = $namespace['value'];
+			$isGeomColumn = ($this->geomFeaturetypeElement == null || $columnName == $this->geomFeaturetypeElement);
 			
-			// check if this node is a geometry node.
-			// however, even if it is a property node, 
-			// it has a child node, the text node!
-			// So we might need to do something more 
-			// sophisticated here...
-			if ($currentSibling->hasChildNodes()){
+			// check if this node is a geometry node.
+			// however, even if it is a property node, 
+			// it has a child node, the text node!
+			// So we might need to do something more 
+			// sophisticated here...
+			if ($currentSibling->hasChildNodes() && $isGeomColumn){
 				$geomNode = $currentSibling->firstChild; 
 					$geomType = $geomNode->nodeName;
 					switch ($geomType) {
@@ -523,12 +537,12 @@
 						case "gml:Envelope" :
 							$this->geometry = new GMLEnvelope();
 							$this->geometry->parseEnvelope($geomNode);
-						default:
-							$this->properties[$columnName] = $value;
-							break;
+						default:
+							$this->properties[$columnName] = $value;
+							break;
 					}
-			} 
-			else {
+			} 
+			else {
 					$this->properties[$columnName] = $value;
 			}
 			
@@ -556,7 +570,7 @@
 				$cnt ++;
 		}
 
-		$json = new Mapbender_JSON();
+		$json = new Mapbender_JSON();
 		$str .= $json->encode($prop); 
 		$str .= "}";
 		
@@ -948,4 +962,4 @@
 		return $str;
 	}
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/http/classes/class_wfs_conf.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_conf.php	2008-12-15 13:25:44 UTC (rev 3316)
+++ trunk/mapbender/http/classes/class_wfs_conf.php	2008-12-15 13:27:27 UTC (rev 3317)
@@ -49,7 +49,7 @@
 			
 			// parameter is a number	
 			if (!is_array($idOrIdArray) && is_numeric($idOrIdArray)) {
-				$idArray = array(intval($idOrIdArray));
+				$idOrIdArray = array(intval($idOrIdArray));
 			}
 
 			// parameter is an array of numbers
@@ -69,7 +69,7 @@
 					$idArray = array_intersect($idArray, $user->getWfsConfByPermission());
 				}
 
-				return $this->getWfsConfFromDB($idArray);
+				return $this->getWfsConfFromDbByArray($idArray);
 			}
 			// parameter is invalid
 			else {
@@ -108,6 +108,16 @@
         return $rowArray;
 	}
 	
+	public static function getGeomColumnNameByConfId ($confId) {
+		$elArray = self::getWfsConfElementFromDb($confId);
+		foreach ($elArray as $element) {
+			if ($element["f_geom"] == "1") {
+				return $element["element_name"];
+			}
+		}
+		return null;
+	}
+	
 	/**
 	 * Gets the database content of a WFS conf element given by a WFS conf ID.
 	 * 

Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php	2008-12-15 13:25:44 UTC (rev 3316)
+++ trunk/mapbender/http/php/mod_wfs_result.php	2008-12-15 13:27:27 UTC (rev 3317)
@@ -21,6 +21,7 @@
 require_once(dirname(__FILE__) . "/../classes/class_stripRequest.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_gml2.php");
+require_once(dirname(__FILE__)."/../classes/class_wfs_conf.php");
 
 $filter = stripslashes($_REQUEST["filter"]);
 $url = stripslashes($_REQUEST["url"]);
@@ -88,8 +89,10 @@
 $data = $connection->file;
 if (!$data) die('{}');
 
+$geomColumn = WfsConf::getGeomColumnNameByConfId($db_wfs_conf_id);
+
 $wfsResult = new gml2 ();
-$geoJson = $wfsResult->parseXML($data);
+$geoJson = $wfsResult->parseXML($data, $geomColumn);
 
 header('Content-type: text/html');
 echo $geoJson;



More information about the Mapbender_commits mailing list