[Mapbender-commits] r3235 - in trunk/mapbender/http: classes
javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Nov 12 09:24:30 EST 2008
Author: christoph
Date: 2008-11-12 09:24:29 -0500 (Wed, 12 Nov 2008)
New Revision: 3235
Modified:
trunk/mapbender/http/classes/class_gml2.php
trunk/mapbender/http/javascripts/geometry.js
trunk/mapbender/http/javascripts/mod_digitize_tab.php
trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
trunk/mapbender/http/javascripts/wfs.js
trunk/mapbender/http/php/mod_wfs_result.php
Log:
http://trac.osgeo.org/mapbender/ticket/305
Modified: trunk/mapbender/http/classes/class_gml2.php
===================================================================
--- trunk/mapbender/http/classes/class_gml2.php 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/classes/class_gml2.php 2008-11-12 14:24:29 UTC (rev 3235)
@@ -16,8 +16,8 @@
# 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");
@@ -56,7 +56,7 @@
function parseXML($data) {
- $this->doc = $data;
+ $this->doc = $this->removeWhiteSpace($data);
return $this->toGeoJSON();
}
@@ -78,6 +78,7 @@
$gmlDoc = new SimpleXMLElement($this->doc);
$gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+ $gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
$gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
// build feature collection
@@ -102,7 +103,7 @@
return $featureCollection->toGeoJSON();
}
else{
- return "{'errorMessage':'Kein Ergebnis'}";
+ return "{}";
}
}
@@ -646,6 +647,7 @@
class GMLPolygon {
var $pointArray = array();
+ var $innerRingArray = array();
public function __construct() {
@@ -675,13 +677,38 @@
$cnt++;
}
+ $innerRingNodeArray = $simpleXMLNode->xpath("gml:innerBoundaryIs/gml:LinearRing");
+ if ($innerRingNodeArray) {
+ $ringCount = 0;
+ foreach ($innerRingNodeArray as $ringNode) {
+ $coordinates = $ringNode->xpath("gml:coordinates");
+ foreach ($coordinates as $coordinate) {
+ $coordsDom = dom_import_simplexml($coordinate);
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPointToRing($ringCount, $x, $y);
+ }
+ }
+ $ringCount++;
+ }
+ }
}
protected function addPoint ($x, $y) {
array_push($this->pointArray, array("x" => $x, "y" => $y));
}
+ protected function addPointToRing ($i, $x, $y) {
+ if (count($this->innerRingArray) <= $i) {
+ array_push($this->innerRingArray, array());
+ }
+ $index = count($this->innerRingIndex);
+ $currentIndex = ($i < $index ? $i : $index);
+ array_push($this->innerRingArray[$currentIndex], array("x" => $x, "y" => $y));
+ }
+
public function toGeoJSON () {
$numberOfPoints = count($this->pointArray);
$str = "";
@@ -693,7 +720,19 @@
}
$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
}
- $str .= "]]}";
+ $str .= "]";
+
+ for ($i=0; $i < count($this->innerRingArray); $i++) {
+ $str .= ",[";
+ for ($j=0; $j < count($this->innerRingArray[$i]); $j++) {
+ if ($j > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+ }
+ $str .= "]";
+ }
+ $str .= "]}";
}
else {
$e = new mb_exception("GMLPolygon: toGeoJSON: this point is null.");
@@ -762,7 +801,6 @@
}
protected function addPoint ($x, $y, $i) {
-
array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
}
@@ -799,38 +837,68 @@
class GMLMultiPolygon {
var $polygonArray = array();
+ var $innerRingArray = array();
public function __construct() {
}
+ protected function addPointToRing ($i, $j, $x, $y) {
+ if (count($this->innerRingArray[$i]) <= $j) {
+ array_push($this->innerRingArray[$i], array());
+ }
+ array_push($this->innerRingArray[$i][$j], array("x" => $x, "y" => $y));
+ }
+
+
public function parseMultiPolygon ($domNode) {
// echo $domNode->nodeName."<br>";
$simpleXMLNode = simplexml_import_dom($domNode);
$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
- $allCoords = $simpleXMLNode->xpath("gml:polygonMember/gml:Polygon/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
-
+ $allPolygons = $simpleXMLNode->xpath("gml:polygonMember/gml:Polygon");
+
$cnt=0;
- foreach ($allCoords as $Coords) {
-
+ foreach ($allPolygons as $polygon) {
+ $allCoords = $polygon->xpath("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
+
$this->polygonArray[$cnt] = array();
+ foreach ($allCoords as $Coords) {
+
+ $coordsDom = dom_import_simplexml($Coords);
+
+ foreach (explode(' ',$coordsDom->nodeValue) as $pointCoords) {
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPoint($x, $y, $cnt);
+ }
+ }
- $coordsDom = dom_import_simplexml($Coords);
+ $this->innerRingArray[$cnt] = array();
+ $innerRingNodeArray = $polygon->xpath("gml:innerBoundaryIs");
+ if ($innerRingNodeArray) {
+ $ringCount = 0;
+ foreach ($innerRingNodeArray as $ringNode) {
+ $currentRingNode = $ringNode->xpath("gml:LinearRing");
+ foreach ($currentRingNode as $node) {
+ $coordinates = $node->xpath("gml:coordinates");
+ foreach ($coordinates as $coordinate) {
+ $coordsDom = dom_import_simplexml($coordinate);
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
-// $name = $coordsDom->nodeName;
-// $value = $coordsDom->nodeValue;
-// echo "===> name: ".$name. ", Value: ".$value."<br>";
-
- foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
- list($x,$y,$z) = explode(',',$pointCoords);
- $this->addPoint($x, $y, $cnt);
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPointToRing($cnt, $ringCount, $x, $y);
+ }
+ }
+ $ringCount++;
+
+ }
}
-
+ }
$cnt++;
- }
-
+ new mb_exception("create multipolygon " . serialize($this->innerRingArray));
+ }
}
protected function addPoint ($x, $y, $i) {
@@ -846,17 +914,30 @@
for ($cnt =0; $cnt < $numberPolygonArray; $cnt++){
if ($cnt > 0) {
- $str .= ",";
- }
- $str .="[";
-
+ $str .= ",";
+ }
+ $str .= "[";
+
+ $str .= "[";
for ($i=0; $i < count($this->polygonArray[$cnt]); $i++) {
if ($i > 0) {
$str .= ",";
}
$str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
}
- $str .="]";
+ $str .= "]";
+
+ for ($i=0; $i < count($this->innerRingArray[$cnt]); $i++) {
+ $str .= ",[";
+ for ($j=0; $j < count($this->innerRingArray[$cnt][$i]); $j++) {
+ if ($j > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+ }
+ $str .= "]";
+ }
+ $str .= "]";
}
$str .= "]}";
Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/javascripts/geometry.js 2008-11-12 14:24:29 UTC (rev 3235)
@@ -310,171 +310,153 @@
};
GeometryArray.prototype.importGeoJSON = function (geoJSON) {
- var isFeatureCollection = false;
- var featureCollectionEpsg = 4326;
- var featureEpsg = 4326;
+ // you can pass either geoJSON or the evaluated geoJSON string
+ // for backwards compatibility
+ if (typeof(geoJSON) == 'string') {
+ var geoJSON = eval('(' + geoJSON + ')');
+ }
+
+ var featureCollectionEpsg = (geoJSON.crs && geoJSON.crs.type == "EPSG") ? geoJSON.crs.properties.code : 4326;
+ var featureEpsg = (geoJSON.crs && geoJSON.crs.type == "EPSG") ? geoJSON.crs.properties.code : 4326;
+
//
// FEATURE COLLECTION
//
- for (var i in geoJSON) {
- if (typeof(geoJSON[i]) != "function") {
- switch (i) {
- case "type":
- isFeatureCollection = (geoJSON[i] == "FeatureCollection") ? true : false;
- break;
- case "crs":
- if (geoJSON[i].type == "EPSG") {
- featureCollectionEpsg = geoJSON[i].properties.code;
- featureEpsg = geoJSON[i].properties.code;
- }
- break;
- case "features":
- if (isFeatureCollection) {
+ var isFeatureCollection = (geoJSON.type == "FeatureCollection") ? true : false;
+ if (isFeatureCollection) {
+ //
+ // FEATURE
+ //
+ var featureArray = geoJSON.features;
+ for (var j = 0; j < featureArray.length; j++) {
+ featureEpsg = featureCollectionEpsg;
+ var currentFeature = featureArray[j];
+ var isFeature = (currentFeature.type == "Feature") ? true : false;
+
+ // add geometry ...
+ if (currentFeature.geometry && isFeature) {
+ //
+ // GEOMETRY
+ //
+ var currentGeometry = currentFeature.geometry;
+ var geometrytype = currentGeometry.type;
+ var coordinates = currentGeometry.coordinates;
+ switch (geometrytype) {
+ case "Point":
//
- // FEATURE
+ // POINT
//
- var featureArray = geoJSON[i];
- for (var j = 0; j < featureArray.length; j++) {
- featureEpsg = featureCollectionEpsg;
- var currentFeature = featureArray[j];
- var isFeature = false;
-
- for (var k in currentFeature) {
- if (typeof(currentFeature[k]) != "function") {
- var geometrytype;
-
- switch(k) {
- case "type":
- isFeature = (currentFeature[k] == "Feature") ? true : false;
- break;
-
- case "properties":
- var properties = currentFeature[k];
-
- // GeometryCollections are NOT YET IMPLEMENTED
- if (geometrytype != "GeometryCollection") {
- for (var l in properties) {
- if (typeof(properties[l]) != "function") {
- this.get(-1).e.setElement(l, properties[l]);
- }
- }
- }
- break;
-
- case "crs":
- if (currentFeature[k].type == "EPSG") {
- featureEpsg = currentFeature[k].properties.code;
- }
- break;
-
- case "geometry":
- if (isFeature) {
-
- //
- // GEOMETRY
- //
- var currentGeometry = currentFeature[k];
- for (var l in currentGeometry) {
-
- if (typeof(currentGeometry[l]) != "function") {
- switch (l) {
- case "type":
- geometrytype = currentGeometry[l];
- break;
- case "coordinates":
- var coordinates = currentGeometry[l];
- switch (geometrytype) {
- case "Point":
- //
- // POINT
- //
- this.addMember(geomType.point);
-
- this.get(-1).addGeometry();
- this.getGeometry(-1,-1).addPointByCoordinates(coordinates[0], coordinates[1], coordinates[2]);
- this.getGeometry(-1,-1).setEpsg(featureEpsg);
- this.close();
- break;
-
- case "LineString":
- //
- // LINESTRING
- //
- this.addMember(geomType.line);
- this.get(-1).addGeometry();
- for (var m = 0; m < coordinates.length; m++) {
- var currentPoint = coordinates[m];
- this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
- }
- this.getGeometry(-1,-1).setEpsg(featureEpsg);
- this.close();
- break;
-
- case "MultiLineString":
- //
- // MULTILINESTRING
- //
- this.addMember(geomType.line);
- for (var m = 0; m < coordinates.length; m++) {
- this.get(-1).addGeometry();
- var currentLine = coordinates[m];
- for (var n = 0; n < currentLine.length; n++) {
- var currentPoint = currentLine[n];
- this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
- }
- this.getGeometry(-1,-1).setEpsg(featureEpsg);
- }
- this.close();
- break;
-
- case "Polygon":
- //
- // POLYGON
- //
- this.addMember(geomType.polygon);
- for (var m = 0; m < coordinates.length; m++) {
- this.get(-1).addGeometry();
- var currentPolygon = coordinates[m];
- for (var n = 0; n < currentPolygon.length; n++) {
- var currentPoint = currentPolygon[n];
- this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
- }
- this.getGeometry(-1,-1).setEpsg(featureEpsg);
- }
- this.close();
- break;
-
- case "MultiPolygon":
- //
- // MULTIPOLYGON
- //
- this.addMember(geomType.polygon);
- for (var m = 0; m < coordinates.length; m++) {
- this.get(-1).addGeometry();
- var currentPolygon = coordinates[m];
- for (var n = 0; n < currentPolygon.length; n++) {
- var currentPoint = currentPolygon[n];
- this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
- }
- this.getGeometry(-1,-1).setEpsg(featureEpsg);
- }
- this.close();
- break;
-
- case "GeometryCollection":
- var exc = new Mb_exception("Geometry: GeometryCollections are not yet supported");
- break;
- }
- }
- }
- }
- }
+ this.addMember(geomType.point);
+
+ this.get(-1).addGeometry();
+ this.getGeometry(-1,-1).addPointByCoordinates(coordinates[0], coordinates[1], coordinates[2]);
+ this.getGeometry(-1,-1).setEpsg(featureEpsg);
+ this.close();
+ break;
+
+ case "LineString":
+ //
+ // LINESTRING
+ //
+ this.addMember(geomType.line);
+ this.get(-1).addGeometry();
+ for (var m = 0; m < coordinates.length; m++) {
+ var currentPoint = coordinates[m];
+ this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+ }
+ this.getGeometry(-1,-1).setEpsg(featureEpsg);
+ this.close();
+ break;
+
+ case "MultiLineString":
+ //
+ // MULTILINESTRING
+ //
+ this.addMember(geomType.line);
+ for (var m = 0; m < coordinates.length; m++) {
+ this.get(-1).addGeometry();
+ var currentLine = coordinates[m];
+ for (var n = 0; n < currentLine.length; n++) {
+ var currentPoint = currentLine[n];
+ this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+ }
+ this.getGeometry(-1,-1).setEpsg(featureEpsg);
+ }
+ this.close();
+ break;
+
+ case "Polygon":
+ //
+ // POLYGON
+ //
+ this.addMember(geomType.polygon);
+ for (var m = 0; m < coordinates.length; m++) {
+ this.get(-1).addGeometry();
+ var currentPolygon = coordinates[m];
+ for (var n = 0; n < currentPolygon.length; n++) {
+ var currentPoint = currentPolygon[n];
+ this.getGeometry(-1,-1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+ }
+ this.getGeometry(-1,-1).setEpsg(featureEpsg);
+ }
+ this.close();
+ break;
+
+ case "MultiPolygon":
+ //
+ // MULTIPOLYGON
+ //
+ this.addMember(geomType.polygon);
+ for (var m = 0; m < coordinates.length; m++) {
+ this.get(-1).addGeometry();
+ var currentPolygon = coordinates[m];
+ for (var n = 0; n < currentPolygon.length; n++) {
+ var currentRing = currentPolygon[n];
+ if (n == 0) {
+ for (var p = 0; p < currentRing.length; p++) {
+ var currentPoint = currentRing[p];
+ this.getGeometry(-1, -1).addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
}
}
+ else {
+ var ring = new Geometry(geomType.polygon);
+ for (var p = 0; p < currentRing.length; p++) {
+ var currentPoint = currentRing[p];
+ ring.addPointByCoordinates(currentPoint[0], currentPoint[1], currentPoint[2]);
+ }
+ ring.close();
+ this.getGeometry(-1,-1).addInnerRing(ring);
+ }
}
+ this.getGeometry(-1,-1).setEpsg(featureEpsg);
}
+ this.close();
+ break;
+
+ case "GeometryCollection":
+ var exc = new Mb_exception("Geometry: GeometryCollections are not yet supported");
+ break;
+ }
+ }
+
+ if (currentFeature.properties) {
+ var properties = currentFeature.properties;
+ // GeometryCollections are NOT YET IMPLEMENTED
+ if (geometrytype != "GeometryCollection") {
+ for (var l in properties) {
+ if (typeof(properties[l]) != "function") {
+ this.get(-1).e.setElement(l, properties[l]);
+ }
}
+ this.get(-1).e.setElement("fid", currentFeature.id);
+ }
}
+ if (currentFeature.crs) {
+ if (currentFeature.crs.type == "EPSG") {
+ featureEpsg = currentFeature.crs.properties.code;
+ }
+
+ }
}
}
}
Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php 2008-11-12 14:24:29 UTC (rev 3235)
@@ -802,8 +802,10 @@
parent.mb_ajax_post("../php/mod_digitize_splitPolygon.php", {polygon: polygonText, line: lineText}, function(json, status) {
var response = eval('(' + json + ')');
var polygonArray = response.polygons;
+ var wfsConfId = d.get(0).wfs_conf;
for (var i in polygonArray) {
d.importGeometryFromText(polygonArray[i]);
+ d.get(-1).wfs_conf = wfsConfId;
}
parent.mb_disableThisButton(button_split);
});
@@ -824,8 +826,12 @@
parent.mb_ajax_post("../php/mod_digitize_differencePolygon.php", {polygon1: polygon1Text, polygon2: polygon2Text}, function(json, status) {
var response = eval('(' + json + ')');
var polygonArray = response.polygons;
+ var wfsConfId = d.get(0).wfs_conf;
+ var wfsProperties = d.get(0).e;
for (var i in polygonArray) {
d.importGeometryFromText(polygonArray[i]);
+ d.get(-1).wfs_conf = wfsConfId;
+ d.get(-1).e = wfsProperties;
}
parent.mb_disableThisButton(button_difference);
});
Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php 2008-11-12 14:24:29 UTC (rev 3235)
@@ -603,15 +603,14 @@
function mb_get_geom(url, filter, index, typename, js_wfs_conf_id, db_wfs_conf_id) {
- mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,{'url':url,'filter':filter,'typename':typename,'js_wfs_conf_id':js_wfs_conf_id, 'db_wfs_conf_id':db_wfs_conf_id},function(js_code,status){
- if (js_code) {
- eval(js_code);
+ mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,{'url':url,'filter':filter,'typename':typename,'js_wfs_conf_id':js_wfs_conf_id, 'db_wfs_conf_id':db_wfs_conf_id},function(json,status){
+ var geom = new GeometryArray();
+ geom.importGeoJSON(json);
+ for (var i = 0; i < geom.count(); i++) {
+ geom.get(i).wfs_conf = js_wfs_conf_id;
}
- if (typeof(geom) == "undefined") {
- var geom = new GeometryArray();
- }
+
checkIfAllAjaxCallsFinished(geom);
-// prompt('', js_code);
});
}
@@ -623,7 +622,6 @@
if (numberOfFinishedAjaxCalls == numberOfAjaxCalls) {
numberOfFinishedAjaxCalls = 0;
mb_execWfsReadSubFunctions(_geomArray);
-
}
}
Modified: trunk/mapbender/http/javascripts/wfs.js
===================================================================
--- trunk/mapbender/http/javascripts/wfs.js 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/javascripts/wfs.js 2008-11-12 14:24:29 UTC (rev 3235)
@@ -341,7 +341,6 @@
function get_wfs_str(myconf, d, m, type, fid) {
- <!-- Getting the Namspace for the FeautureType -->
var featureTypeArray = myconf['featuretype_name'].split(':')
var featureNS = featureTypeArray[0];
@@ -420,13 +419,34 @@
}
if(d.get(m).geomType == geomType.polygon){
str += '<gml:MultiPolygon srsName="' + myconf['featuretype_srs'] + '">';
- str += '<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>';
+ for (var k = 0; k < d.get(m).count(); k++) {
+ str += '<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>';
+
+ for(var l = 0; l < d.getGeometry(m, k).count(); l++){
+ if (l > 0) {
+ str += " ";
+ }
+ str += d.getPoint(m,k,l).x + "," + d.getPoint(m,k,l).y;
+ }
- for(var k=0; k<d.getGeometry(m,0).count(); k++){
- if(k>0) str += " ";
- str += d.getPoint(m,0,k).x + "," + d.getPoint(m,0,k).y;
+ str += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>';
+
+ if (d.getGeometry(m, k).innerRings) {
+ for(var ii = 0; ii < d.getGeometry(m, k).innerRings.count(); ii++){
+ str += '<gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>';
+ for(var l = 0; l < d.getGeometry(m, k).innerRings.get(ii).count(); l++){
+ if (l > 0) {
+ str += " ";
+ }
+ str += d.getPoint(m,k,ii,l).x + "," + d.getPoint(m,k,ii,l).y;
+ }
+ str += '</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs>';
+ }
+ }
+
+ str += '</gml:Polygon></gml:polygonMember>';
}
- str += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>';
+ str += '</gml:MultiPolygon>';
}
str += '</' + el_geom + '></'+ myconf['featuretype_name']+'></wfs:Insert>';
}
@@ -466,13 +486,29 @@
}
if(d.get(m).geomType == geomType.polygon){
str += '<gml:MultiPolygon srsName="' + myconf['featuretype_srs'] + '">';
- str += '<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>';
- for(var k=0; k<d.getGeometry(m,0).count(); k++){
- if(k>0) str += " ";
- str += d.getPoint(m,0,k).x + "," + d.getPoint(m,0,k).y;
+ for (var l = 0; l < d.get(m).count(); l++) {
+ str += '<gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>';
+ for(var k=0; k<d.getGeometry(m,l).count(); k++){
+ if(k>0) str += " ";
+ str += d.getPoint(m,l,k).x + "," + d.getPoint(m,l,k).y;
+ }
+ str += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>';
+ if (d.getGeometry(m, l).innerRings) {
+ for(var ii = 0; ii < d.getGeometry(m, l).innerRings.count(); ii++){
+ str += '<gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>';
+ for(var p = 0; p < d.getGeometry(m, l).innerRings.get(ii).count(); p++){
+ if (p > 0) {
+ str += " ";
+ }
+ str += d.getPoint(m,l,ii,p).x + "," + d.getPoint(m,l,ii,p).y;
+ }
+ str += '</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs>';
+ }
+ }
+ str += '</gml:Polygon></gml:polygonMember>';
}
- str += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>';
}
+ str += '</gml:MultiPolygon>';
str += '</wfs:Value></wfs:Property>';
str += '<ogc:Filter><ogc:FeatureId fid="'+fid+'"/></ogc:Filter>';
str += '</wfs:Update>';
@@ -493,4 +529,4 @@
str += '</wfs:Transaction>';
return str;
-}
\ No newline at end of file
+}
Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php 2008-11-12 14:14:56 UTC (rev 3234)
+++ trunk/mapbender/http/php/mod_wfs_result.php 2008-11-12 14:24:29 UTC (rev 3235)
@@ -20,10 +20,10 @@
require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
require_once(dirname(__FILE__) . "/../classes/class_stripRequest.php");
require_once(dirname(__FILE__) . "/../classes/class_connector.php");
+require_once(dirname(__FILE__) . "/../classes/class_gml2.php");
$filter = stripslashes($_REQUEST["filter"]);
$url = stripslashes($_REQUEST["url"]);
-$js_wfs_conf_id = $_REQUEST["js_wfs_conf_id"];
$db_wfs_conf_id = $_REQUEST["db_wfs_conf_id"];
$typename = $_REQUEST["typename"];
@@ -86,105 +86,11 @@
$wfsRequest = $url . urlencode($filter);
$connection = new connector($wfsRequest);
$data = $connection->file;
-if (!$data) die('wfs not available');
+if (!$data) die('{}');
-$geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
+$wfsResult = new gml2 ();
+$geoJson = $wfsResult->parseXML($data);
-
-//TODO:
-// parsing via class_gml
-// add method toJSON to classGML
-$parser = xml_parser_create();
-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);
-xml_parser_free($parser);
-$member = -1;
-$section = false;
-$geom = false;
-$memberHasBeenCreated = false;
-$str = array();
-$geomtype = array();
-$el = -1;
-$fid = -1;
-
-$element_str = "";
-$geom_str = "";
-foreach ($values as $element) {
- if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "open"){
- $member++;
- $section = true;
- $cnt_geom = 0;
- }
- else if(mb_strtoupper($element[tag]) == mb_strtoupper($typename) && $element[type] == "open") {
- $fid = $element[attributes][fid];
- }
- else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "open" && $section == true){
- $geom = true;
- if (sepNameSpace($element[tag]) == "MultiLineString") {
- $geom_str .= "geom.addMember(geomType.line);\n";
- $memberHasBeenCreated = true;
- }
- else if (sepNameSpace($element[tag]) == "MultiPolygon" ) {
- $geom_str .= "geom.addMember(geomType.polygon);\n";
- $memberHasBeenCreated = true;
- }
- elseif (sepNameSpace($element[tag]) == "Point") {
- $geom_str .= "geom.addMember(geomType.point);\n";
- $memberHasBeenCreated = true;
- $geom_str .= "geom.get(-1).addGeometry();\n";
- }
- elseif (sepNameSpace($element[tag]) == "LineString") {
- if (!$memberHasBeenCreated) {
- $geom_str .= "geom.addMember(geomType.line);\n";
- $memberHasBeenCreated = true;
- }
- $geom_str .= "geom.get(-1).addGeometry();\n";
- }
- else if (sepNameSpace($element[tag]) == "Polygon" ) {
- if (!$memberHasBeenCreated) {
- $geom_str .= "geom.addMember(geomType.polygon);\n";
- $memberHasBeenCreated = true;
- }
- $geom_str .= "geom.get(-1).addGeometry();\n";
- }
- else {
- $geom_str .= "alert('unknown geomtype ".sepNameSpace($element[tag])."');";
- }
- // TO DO: the following is added twice! Once suffices.
- $element_str .= "geom.get(" . $member . ").e.setElement('fid', '".$fid."');\n";
- $element_str .= "geom.get(" . $member . ").wfs_conf = ".$js_wfs_conf_id.";\n";
- }
- else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:coordinates") && $geom == true){
- $tmp = preg_replace("/,,/","",preg_replace("/ /",",",trim($element[value])));
- $geom_str .= "var tmp1 = '".$tmp."';\n";
- $geom_str .= "var tmp = tmp1.split(',');\n";
- $geom_str .= "for (var i = 0 ; i < tmp.length ; i+=2) {\n";
- $geom_str .= "\tgeom.getGeometry(-1,-1).addPointByCoordinates(parseFloat(tmp[i]), parseFloat(tmp[i+1]));\n";
- $geom_str .= "}\n";
- $geom_str .= "geom.close();\n";
- $cnt_geom++;
-
- }
- else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "close"){
- $geom = false;
- $memberHasBeenCreated = false;
- }
- else if($section == true && $geom == false && $element[value]){
- $el++;
- $str = $element[value];
- $element_str .= "geom.get(" . $member . ").e.setElement('".sepNameSpace($element[tag])."', '".addslashes($str)."');\n";
- }
- else if(mb_strtoupper($element[tag]) == mb_strtoupper("gml:featureMember") && $element[type] == "close"){
- $section = false;
- $el = -1;
- }
-}
-if ($geom_str != "") {
- $geom_str = "var geom = new GeometryArray();\n" . $geom_str;
-}
header('Content-type: text/html');
-echo $geom_str;
-echo $element_str;
+echo $geoJson;
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list