[Mapbender-commits] r1493 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jul 13 06:55:10 EDT 2007
Author: christoph
Date: 2007-07-13 06:55:10 -0400 (Fri, 13 Jul 2007)
New Revision: 1493
Modified:
trunk/mapbender/http/classes/class_gml2.php
Log:
now supports multigeometries, thanks to Christoph Ratke
Modified: trunk/mapbender/http/classes/class_gml2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml2.php 2007-07-13 10:18:50 UTC (rev 1492)
+++ trunk/mapbender/http/classes/class_gml2.php 2007-07-13 10:55:10 UTC (rev 1493)
@@ -1,237 +1,243 @@
-<?php
-# $Id$
-# 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("class_mb_exception.php");
-require_once("class_connector.php");
-require_once("../../conf/mapbender.conf");
-class gml2{
- var $geomtype_point = 'Point';
- var $geomtype_polygon = 'Polygon';
- var $geomtype_line = 'LineString';
- var $geomtype_multipolygon = 'MultiPolygon';
- var $geomtype_multiline = 'MultiLine';
- var $geometries = array();
- var $member = -1;
- var $geomtype = array();
- var $keys = array();
- var $values = array();
- var $geometry = array();
- var $bbox = array();
-
-
- function gml2(){
- $this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
- }
- function getGml($req){
- $x = new connector($req);
- return $x->file;
- }
- function parsegml($req){
- #$data = implode("",file($req));
- $x = new connector($req);
- $data = $this->char_encode($x->file);
- $this->parse_xml($data);
- }
- function parsestring($data){
- $this->parse_xml($data);
- }
- function parse_xml($data){
- $section = false;
- $geom = false;
- $boundedBy = false;
- $coordinates = 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($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
- $boundedBy = true;
- }
- if ($boundedBy) {
- if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")){
- $this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element[value]))));
- $boundedBy=false;
- }
- }
- if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("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(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
- $cnt_geom++;
- $geom = false;
- }
- if($geom == true){
- if (strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")) {
- $this->geometry[$this->member][$cnt_geom] = str_replace(",,","",str_replace(" ",",",trim($element[value])));
- $coordinates = true;
- }
- else if (!$coordinates && trim($element[value])) {
- $coords = str_replace(",,","",str_replace(" ",",",trim($element[value])));
- $tmp_array = explode(",", $coords);
- if (count($tmp_array > 1)) {
- $this->geometry[$this->member][$cnt_geom] = $coords;
- $coordinates = true;
- }
- }
- }
- else if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("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 getXfromMemberAsString($memberCount,$geomCount){
- $t = explode(",",$this->geometry[$memberCount][$geomCount]);
- $x = array();
- for($i=0; $i<(count($t)-1); $i=$i+2){
- array_push($x,$t[$i]);
- }
- return implode(",",$x);
- }
-
- function getYfromMemberAsString($memberCount,$geomCount){
- $t = explode(",",$this->geometry[$memberCount][$geomCount]);
- $y = array();
- for($i=1; $i<=(count($t)-1); $i=$i+2){
- array_push($y,$t[$i]);
- }
- return implode(",",$y);
- }
-
- 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;
- }
-
- function exportGeometriesToJS ($isInFrame) {
- $prefix = "";
- if ($isInFrame == true) {
- $prefix = "parent.";
- }
- $js = "";
- $js .= "var geom = new ".$prefix."GeometryArray();\n";
- for ($i=0; $i<count($this->geometry); $i++) {
- $js .= $this->exportMemberToJS($i, $isInFrame);
- $js .= "geom.addCopy(q);\n";
- }
- return $js;
- }
-
- function exportMemberToJS ($i, $isInFrame) {
- $prefix = "";
- if ($isInFrame == true) {
- $prefix = "parent.";
- }
- $js = "";
- if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
- $js .= "var current_geomtype = ".$prefix."geomType.point;\n";
- }
- elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
- $js .= "var current_geomtype = ".$prefix."geomType.line;\n";
- }
- elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
- $js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
- }
- else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
-
- $js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
-
- for ($j=0; $j<count($this->geometry[$i]); $j++) {
- $js .= "q.addGeometry(current_geomtype);\n";
-
- $x_array = explode(",", $this->getXfromMemberAsString($i, $j));
- $y_array = explode(",", $this->getYfromMemberAsString($i, $j));
-
- for ($k=0; $k<count($x_array); $k++) {
- $js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
- //$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
- }
- $js .= "q.get(-1).close();\n";
- }
-// $js .= "alert(q);\n";
- return $js;
- }
-}
+<?php
+# $Id$
+# 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("class_mb_exception.php");
+require_once("class_connector.php");
+require_once("../../conf/mapbender.conf");
+class gml2{
+ var $geomtype_point = 'Point';
+ var $geomtype_polygon = 'Polygon';
+ var $geomtype_line = 'LineString';
+ var $geomtype_multipolygon = 'MultiPolygon';
+ var $geomtype_multiline = 'MultiLine';
+ var $geometries = array();
+ var $member = -1;
+ var $geomtype = array();
+ var $keys = array();
+ var $values = array();
+ var $geometry = array();
+ var $bbox = array();
+
+
+ function gml2(){
+ $this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
+ }
+ function getGml($req){
+ $x = new connector($req);
+ return $x->file;
+ }
+ function parsegml($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $data = $this->char_encode($x->file);
+ $this->parse_xml($data);
+ }
+ function parsestring($data){
+ $this->parse_xml($data);
+ }
+ function parse_xml($data){
+ $section = false;
+ $geom = false;
+ $boundedBy = false;
+ $coordinates = 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($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
+ $boundedBy = true;
+ }
+ if ($boundedBy) {
+ if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")){
+ $this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element[value]))));
+ $boundedBy=false;
+ }
+ }
+ if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("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(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
+ $cnt_geom++;
+ $geom = false;
+ }
+ if($geom == true){
+ if (strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")) {
+ $this->geometry[$this->member][$cnt_geom] = str_replace(",,","",str_replace(" ",",",trim($element[value])));
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ else if (!$coordinates && trim($element[value])) {
+ $coords = str_replace(",,","",str_replace(" ",",",trim($element[value])));
+ $tmp_array = explode(",", $coords);
+ if (count($tmp_array > 1)) {
+ $this->geometry[$this->member][$cnt_geom] = $coords;
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ }
+ }
+ else if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("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 getXfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $x = array();
+ for($i=0; $i<(count($t)-1); $i=$i+2){
+ array_push($x,$t[$i]);
+ }
+ return implode(",",$x);
+ }
+
+ function getYfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $y = array();
+ for($i=1; $i<=(count($t)-1); $i=$i+2){
+ array_push($y,$t[$i]);
+ }
+ return implode(",",$y);
+ }
+
+ 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;
+ }
+
+ function exportGeometriesToJS ($isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ $js .= "var geom = new ".$prefix."GeometryArray();\n";
+ for ($i=0; $i<count($this->geometry); $i++) {
+ $js .= $this->exportMemberToJS($i, $isInFrame);
+ $js .= "geom.addCopy(q);\n";
+ }
+ return $js;
+ }
+
+ function exportMemberToJS ($i, $isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
+ $js .= "var current_geomtype = ".$prefix."geomType.point;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
+ $js .= "var current_geomtype = ".$prefix."geomType.line;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
+ $js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
+ }
+ else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
+
+ $js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
+
+ for ($j=0; $j<count($this->geometry[$i]); $j++) {
+ $js .= "q.addGeometry(current_geomtype);\n";
+
+ $x_array = explode(",", $this->getXfromMemberAsString($i, $j));
+ $y_array = explode(",", $this->getYfromMemberAsString($i, $j));
+
+ for ($k=0; $k<count($x_array); $k++) {
+ $js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
+ //$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
+ }
+ $js .= "q.get(-1).close();\n";
+ }
+// $js .= "alert(q);\n";
+ return $js;
+ }
+}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list