svn commit: r773 - trunk/mapbender/http/classes/class_gml2.php
christoph at osgeo.org
christoph at osgeo.org
Fri Sep 29 04:07:03 EDT 2006
Author: christoph
Date: 2006-09-29 08:07:03+0000
New Revision: 773
Modified:
trunk/mapbender/http/classes/class_gml2.php
Log:
added parsing for bbox and js export of geometries
Modified: trunk/mapbender/http/classes/class_gml2.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_gml2.php?view=diff&rev=773&p1=trunk/mapbender/http/classes/class_gml2.php&p2=trunk/mapbender/http/classes/class_gml2.php&r1=772&r2=773
==============================================================================
--- trunk/mapbender/http/classes/class_gml2.php (original)
+++ trunk/mapbender/http/classes/class_gml2.php 2006-09-29 08:07:03+0000
@@ -20,17 +20,22 @@
require_once("class_connector.php");
require_once("../../conf/mapbender.conf");
class gml2{
- var $geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
+ 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 parsegml($req){
#$data = implode("",file($req));
@@ -45,8 +50,8 @@
function parse_xml($data){
$section = false;
$geom = false;
+ $boundedBy = 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);
@@ -60,6 +65,15 @@
xml_parser_free($parser);
foreach ($values as $element) {
+ if(strtoupper($element[tag]) == strtoupper("gml:boundedBy") && $element[type] == "open"){
+ $boundedBy = true;
+ }
+ if ($boundedBy) {
+ if(strtoupper($element[tag]) == strtoupper("gml:coordinates")){
+ $this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element[value]))));
+ $boundedBy=false;
+ }
+ }
if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "open"){
$this->member++;
$this->keys[$this->member] = array();
@@ -92,6 +106,7 @@
}
}
}
+
function sepNameSpace($s){
$c = strpos($s,":");
if($c>0){
@@ -101,9 +116,11 @@
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){
@@ -111,6 +128,7 @@
}
}
}
+
function getValueByKey($memberCount,$keyName){
for($i=0; $i<count($this->keys[$memberCount]); $i++){
if($this->keys[$memberCount][$i] == $keyName){
@@ -118,6 +136,7 @@
}
}
}
+
function getXfromMemberAsString($memberCount,$geomCount){
$t = explode(",",$this->geometry[$memberCount][$geomCount]);
$x = array();
@@ -126,6 +145,7 @@
}
return implode(",",$x);
}
+
function getYfromMemberAsString($memberCount,$geomCount){
$t = explode(",",$this->geometry[$memberCount][$geomCount]);
$y = array();
@@ -134,17 +154,58 @@
}
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 () {
+ $js = "";
+ $js .= "var geom = new GeometryArray();\n";
+ for ($i=0; $i<count($this->geometry); $i++) {
+ $js .= $this->exportMember($i);
+ $js .= "geom.appendMember(q);\n";
+ }
+ }
+
+ function exportMemberToJS ($i) {
+ $js = "";
+ if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
+ $js .= "var current_geomtype = geomTypePoint;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
+ $js .= "var current_geomtype = geomTypeLine;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
+ $js .= "var current_geomtype = geomTypePolygon;\n";
+ }
+ else die("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."'");
+
+ $js .= "var q = new 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 .= "q.get(-1).close();\n";
+ }
+ return $js;
+ }
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list