svn commit: r48 - trunk/mapbender/http/classes/class_gml2.php

uli at osgeo.org uli at osgeo.org
Thu Apr 13 16:58:56 EDT 2006


Author: uli
Date: 2006-04-13 20:58:56+0000
New Revision: 48

Added:
   trunk/mapbender/http/classes/class_gml2.php

Log:
import Mapbender source without history

Added: trunk/mapbender/http/classes/class_gml2.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_gml2.php?view=auto&rev=48
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/classes/class_gml2.php	2006-04-13 20:58:56+0000
@@ -0,0 +1,134 @@
+<?php
+# $Id: class_gml2.php,v 1.5 2006/03/22 16:34:15 uli_rothstein Exp $
+# $Header: /cvsroot/mapbender/mapbender/http/classes/class_gml2.php,v 1.5 2006/03/22 16:34:15 uli_rothstein Exp $
+# 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("class_mb_exception.php");
+require_once("class_connector.php");
+require_once("../../conf/mapbender.conf");
+class gml2{
+	var $geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');	
+	var $member = -1;
+	var $geomtype = array();	
+	var $keys = array();
+	var $values = array();
+	var $geometry = array();
+	
+	
+	
+	function gml2(){
+		
+	}
+	function parsegml($req){
+		#$data = implode("",file($req));
+		$x = new connector($req);
+		$data = $this->char_encode($x->file);
+		$this->parse_xml($data);		 		
+	}
+	function parsestring($req){
+		$data = $req;
+		$this->parse_xml($data);		 		
+	}
+	function parse_xml($data){
+		$section = false;
+		$geom = false;
+		$el = -1;
+
+		$parser = xml_parser_create(CHARSET);
+		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+		xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+		xml_parse_into_struct($parser,$data,$values,$tags);
+		$code = xml_get_error_code ($parser);
+		if ($code) {
+			$line = xml_get_current_line_number($parser); 
+			$mb_exception = new mb_exception(xml_error_string($code) .  " in line " . $line);
+		}
+		xml_parser_free($parser);
+		
+		foreach ($values as $element) {
+			if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "open"){
+				$this->member++;
+				$this->keys[$this->member] = array();
+				$this->value[$this->member] = array();
+				$this->geometry[$this->member] = array();
+				$section = true;
+				$cnt_geom = 0;
+			}
+			if($section == true){
+				if( in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "open"){
+					$geom = true;
+					$this->geomtype[$this->member] = $this->sepNameSpace($element[tag]);
+				}
+				else if(strtoupper($element[tag]) == strtoupper("gml:coordinates") && $geom == true){
+					$this->geometry[$this->member][$cnt_geom] =  str_replace(",,","",str_replace(" ",",",trim($element[value])));
+				}
+				else if(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
+					$cnt_geom++;
+					$geom = false;
+				}
+				else if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "close"){
+					$section = false;	
+					$el = -1;
+				}
+				else{
+					$el++;
+					$this->values[$this->member][$el] = $element[value];
+					$this->keys[$this->member][$el] = $element[tag];	
+				}
+			}
+		}
+	}	
+	function sepNameSpace($s){
+		$c = strpos($s,":"); 
+		if($c>0){
+			return substr($s,$c+1);
+		}
+		else{
+			return $s;
+		}		
+	}
+	function getMemberCount(){
+		return ($this->member+1);	
+	}
+	function getValueBySeparatedKey($memberCount,$keyName){
+		for($i=0; $i<count($this->keys[$memberCount]); $i++){
+			if($this->sepNameSpace($this->keys[$memberCount][$i]) == $keyName){
+				return $this->values[$memberCount][$i];
+			}	
+		}
+	}
+	function getValueByKey($memberCount,$keyName){
+		for($i=0; $i<count($this->keys[$memberCount]); $i++){
+			if($this->keys[$memberCount][$i] == $keyName){
+				return $this->values[$memberCount][$i];
+			}	
+		}
+	}
+	function getGeometriesFromMember($memberCount){
+		return $this->geometry[$memberCount];	
+	}
+	function getGeometryTypeFromMember($memberCount){
+		return 	$this->geomtype[$memberCount];
+	}
+	function char_encode($s){
+		if(CHARSET == 'UTF-8'){
+			$s = utf8_encode($s);	
+		}
+		return $s;
+	}
+}
+?>
\ No newline at end of file




More information about the Mapbender_commits mailing list