[Mapbender-commits] r2905 - in trunk/mapbender: conf
http/img/button_digitize http/javascripts http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Sep 3 08:40:39 EDT 2008
Author: christoph
Date: 2008-09-03 08:40:37 -0400 (Wed, 03 Sep 2008)
New Revision: 2905
Added:
trunk/mapbender/http/img/button_digitize/mergePolygons_off.png
trunk/mapbender/http/img/button_digitize/mergePolygons_on.png
trunk/mapbender/http/img/button_digitize/mergePolygons_over.png
trunk/mapbender/http/img/button_digitize/splitPolygon_off.png
trunk/mapbender/http/img/button_digitize/splitPolygon_on.png
trunk/mapbender/http/img/button_digitize/splitPolygon_over.png
trunk/mapbender/http/php/mod_digitize_mergePolygon.php
trunk/mapbender/http/php/mod_digitize_splitPolygon.php
Modified:
trunk/mapbender/conf/digitize_default.conf
trunk/mapbender/http/javascripts/geometry.js
trunk/mapbender/http/javascripts/mod_digitize_tab.php
trunk/mapbender/http/php/mod_digitize_messages.php
Log:
http://trac.osgeo.org/mapbender/ticket/287
Modified: trunk/mapbender/conf/digitize_default.conf
===================================================================
--- trunk/mapbender/conf/digitize_default.conf 2008-09-01 15:41:46 UTC (rev 2904)
+++ trunk/mapbender/conf/digitize_default.conf 2008-09-03 12:40:37 UTC (rev 2905)
@@ -10,6 +10,8 @@
addButtonDig("setBasePoint", 1, "new_node_off.png", "", "", 100, 0);
addButtonDig("delBasePoint", 1, "delete_node_off.png", "", "", 125, 0);
addButtonDig("clear", 1, "del_off.png", "", "", 150, 0);
+addButtonDig("digitizeSplit", 1, "splitPolygon_off.png", "", "", 175, 0);
+addButtonDig("digitizeMerge", 1, "mergePolygons_off.png", "", "", 200, 0);
//definition of directory of digitize buttons
buttonDig_imgdir = "../img/button_digitize/";
Added: trunk/mapbender/http/img/button_digitize/mergePolygons_off.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/mergePolygons_off.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/img/button_digitize/mergePolygons_on.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/mergePolygons_on.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/img/button_digitize/mergePolygons_over.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/mergePolygons_over.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/img/button_digitize/splitPolygon_off.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/splitPolygon_off.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/img/button_digitize/splitPolygon_on.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/splitPolygon_on.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/mapbender/http/img/button_digitize/splitPolygon_over.png
===================================================================
(Binary files differ)
Property changes on: trunk/mapbender/http/img/button_digitize/splitPolygon_over.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js 2008-09-01 15:41:46 UTC (rev 2904)
+++ trunk/mapbender/http/javascripts/geometry.js 2008-09-03 12:40:37 UTC (rev 2905)
@@ -241,7 +241,46 @@
return [min, max];
};
+GeometryArray.prototype.importGeometryFromText = function (text) {
+ var tmpArray = text.split("(");
+ var geometryType = tmpArray[0];
+
+ switch (geometryType) {
+ case "POLYGON":
+ var text = text.replace(/\)/, "");
+ text = text.replace(/\(\(/, "(");
+ var tmpArray = text.split("(");
+
+ var coordinatesArray = tmpArray[1].split(",");
+
+ this.addMember(geomType.polygon);
+ this.get(-1).addGeometry();
+ for (var m = 0; m < -1 + coordinatesArray.length; m++) {
+ var currentPoint = coordinatesArray[m].split(" ");
+ this.getGeometry(-1, -1).addPointByCoordinates(parseFloat(currentPoint[0]), parseFloat(currentPoint[1]));
+ }
+ this.close();
+ break;
+ case "MULTIPOLYGON":
+ var text = text.replace(/\)/, "");
+ text = text.replace(/\(\(\(/, "(");
+
+ var tmpArray = text.split("(");
+
+ var coordinatesArray = tmpArray[1].split(",");
+
+ this.addMember(geomType.polygon);
+ this.get(-1).addGeometry();
+ for (var m = 0; m < -1 + coordinatesArray.length; m++) {
+ var currentPoint = coordinatesArray[m].split(" ");
+ this.getGeometry(-1, -1).addPointByCoordinates(parseFloat(currentPoint[0]), parseFloat(currentPoint[1]));
+ }
+ this.close();
+ break;
+ }
+};
+
GeometryArray.prototype.importGeoJSON = function (geoJSON) {
var isFeatureCollection = false;
var featureCollectionEpsg = 4326;
@@ -635,6 +674,53 @@
return false;
};
+MultiGeometry.prototype.toText = function () {
+ var text = "";
+ var numOfGeom = this.count();
+ if (numOfGeom >= 1) {
+ if (this.geomType == geomType.polygon) {
+ text += "POLYGON (";
+
+ for (var i = 0; i < this.count(); i++) {
+ if (i > 0) {
+ text += ", ";
+ }
+ text += "(";
+
+ var currentPolygon = this.get(i);
+ for (var j = 0; j < currentPolygon.count(); j++) {
+ if (j > 0) {
+ text += ", ";
+ }
+
+ var currentPoint = currentPolygon.get(j);
+ text += currentPoint.x + " " + currentPoint.y
+ }
+
+ text += ")";
+ }
+ text += ")";
+ }
+ else if (this.geomType == geomType.line) {
+ text += "LINESTRING (";
+
+ var currentLine = this.get(0);
+ for (var j = 0; j < currentLine.count(); j++) {
+ if (j > 0) {
+ text += ", ";
+ }
+
+ var currentPoint = currentLine.get(j);
+ text += currentPoint.x + " " + currentPoint.y
+ }
+
+ text += ")";
+ }
+
+ }
+ return text;
+};
+
MultiGeometry.prototype.toString = function () {
var str = this.toStringWithoutProperties();
Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php 2008-09-01 15:41:46 UTC (rev 2904)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php 2008-09-03 12:40:37 UTC (rev 2905)
@@ -84,7 +84,8 @@
var button_insert = "setBasePoint";
var button_delete = "delBasePoint";
var button_clear = "clear";
-var button_combine = "combine";
+var button_split = "digitizeSplit";
+var button_merge = "digitizeMerge";
var digitizeDivTag;
@@ -583,7 +584,10 @@
mod_digitizeEvent = obj.id;
executeDigitizePreFunctions();
}
- else if (obj.id == button_point || obj.id == button_line || obj.id == button_polygon || obj.id == button_clear || obj.id == button_combine){
+ else if (obj.id == button_point || obj.id == button_line ||
+ obj.id == button_polygon || obj.id == button_clear ||
+ obj.id == button_split || obj.id == button_merge){
+
var el = parent.frames[mod_digitize_target].document;
el.onmousemove = mod_digitize_go;
@@ -695,14 +699,54 @@
parent.mb_disableThisButton(button_clear);
}
}
- else if (obj.id == button_combine) {
-// d.combineToMultiGeometry();
-// prompt('', d.toJSONString());
-// parent.mb_ajax_post("../php/jsonTest.php", {json:d.toJSONString()}, function(test, status) {
-// alert(test);
-// });
- parent.mb_disableThisButton(button_combine);
+ else if (obj.id == button_merge) {
+ var applicable = (d.count() > 1);
+
+ var polygonTextArray = [];
+ for (var i = 0; i < d.count(); i++) {
+ if (d.get(i).geomType != parent.geomType.polygon) {
+ applicable = false;
+ polygonTextArray = [];
+ break;
+ }
+ polygonTextArray.push(d.get(i).toText());
+ }
+
+ if (!applicable) {
+ alert(msgObj.messageErrorMergeNotApplicable);
+ parent.mb_disableThisButton(button_merge);
+ return false;
+ }
+
+ parent.mb_ajax_post("../php/mod_digitize_mergePolygon.php", {polygons: polygonTextArray.join(";")}, function(json, status) {
+ var response = eval('(' + json + ')');
+ var polygon = response.polygon;
+ d.importGeometryFromText(polygon);
+ parent.mb_disableThisButton(button_merge);
+ });
}
+ else if (obj.id == button_split) {
+ var applicable = (d.count() == 2) &&
+ (d.get(0).geomType == parent.geomType.polygon) &&
+ (d.get(1).geomType == parent.geomType.line);
+ if (!applicable) {
+ alert(msgObj.messageErrorSplitNotApplicable);
+ parent.mb_disableThisButton(button_split);
+ return false;
+ }
+
+ var polygonText = d.get(0).toText();
+ var lineText = d.get(1).toText();
+
+ parent.mb_ajax_post("../php/mod_digitize_splitPolygon.php", {polygon: polygonText, line: lineText}, function(json, status) {
+ var response = eval('(' + json + ')');
+ var polygonArray = response.polygons;
+ for (var i in polygonArray) {
+ d.importGeometryFromText(polygonArray[i]);
+ }
+ parent.mb_disableThisButton(button_split);
+ });
+ }
}
}
@@ -719,6 +763,14 @@
mod_digitize_timeout();
executeDigitizeSubFunctions();
}
+ else if (obj.id == button_merge) {
+ mod_digitize_timeout();
+ executeDigitizeSubFunctions();
+ }
+ else if (obj.id == button_split) {
+ mod_digitize_timeout();
+ executeDigitizeSubFunctions();
+ }
mod_digitizeEvent = false;
}
// --- button handling (end) ----------------------------------------------------------------------------------------------
Added: trunk/mapbender/http/php/mod_digitize_mergePolygon.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_mergePolygon.php (rev 0)
+++ trunk/mapbender/http/php/mod_digitize_mergePolygon.php 2008-09-03 12:40:37 UTC (rev 2905)
@@ -0,0 +1,60 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/DeleteWMS
+# 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(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
+
+$json = new Mapbender_JSON();
+
+$polygonList = stripslashes($_REQUEST["polygons"]);
+
+$floatPattern = "-?\d+(\.\d+)?";
+$pointPattern = $floatPattern . " " . $floatPattern;
+$polygonPattern = "POLYGON \(\(" . $pointPattern . "(, " . $pointPattern . ")*\)\)";
+$pattern = "/" . $polygonPattern . "(;" . $polygonPattern . ")+/";
+if (!preg_match($pattern, $polygonList)) {
+ echo "not a polygon.";
+ die();
+}
+
+$polygonArray = explode(";", $polygonList);
+
+$sql = "SELECT astext(multi(geomunion(geom))) FROM (";
+
+for ($i = 0; $i < count($polygonArray); $i++) {
+ if ($i > 0) {
+ $sql .= " UNION ";
+ }
+ $sql .= "(SELECT '" . $polygonArray[$i] . "'::geometry AS geom) ";
+}
+
+$sql .= ") as a";
+
+$res = db_query($sql);
+
+$polygonArray = array();
+$row = db_fetch_array($res);
+
+$data = array("polygon" => $row[0]);
+
+$output = $json->encode($data);
+
+header("Content-type:application/x-json; charset=utf-8");
+echo $output;
+?>
\ No newline at end of file
Property changes on: trunk/mapbender/http/php/mod_digitize_mergePolygon.php
___________________________________________________________________
Name: svn:keywords
+ HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Modified: trunk/mapbender/http/php/mod_digitize_messages.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_messages.php 2008-09-01 15:41:46 UTC (rev 2904)
+++ trunk/mapbender/http/php/mod_digitize_messages.php 2008-09-03 12:40:37 UTC (rev 2905)
@@ -35,6 +35,8 @@
$msg_obj["messageErrorFieldIsEmpty"] = _mb("This field may not be empty.");
$msg_obj["messageErrorFormEvaluation"] = _mb("Failure during form evaluation.");
$msg_obj["messageErrorWfsWrite"] = _mb("An error occured.");
+$msg_obj["messageErrorMergeNotApplicable"] = _mb("At least two geometries must be available. Only polygons are allowed in the geometry list.");
+$msg_obj["messageErrorSplitNotApplicable"] = _mb("Exactly two geometries must be available. The first geometry shall be a polygon, the second geometry shall be a line.");
$msg_obj["messageSuccessWfsWrite"] = _mb("Success.");
$msg_obj["messageConfirmDeleteGeomFromDb"] = _mb("Delete geometry from database?");
$msg_obj["messageConfirmDeleteAllGeomFromList"] = _mb("Clear list of geometries?");
@@ -59,6 +61,10 @@
$msg_obj["buttonLabelDeleteBasepointOn"] = _mb("Delete basepoint");
$msg_obj["buttonLabelClearListOff"] = _mb("clear list of geometries");
$msg_obj["buttonLabelClearListOn"] = _mb("clear list of geometries");
+$msg_obj["buttonLabelMergeOff"] = _mb("Merge geometries");
+$msg_obj["buttonLabelMergeOn"] = _mb("Merge geometries");
+$msg_obj["buttonLabelSplitOff"] = _mb("Split geometries");
+$msg_obj["buttonLabelSplitOn"] = _mb("Split geometries");
$msg_obj["buttonDig_wfs_title"] = _mb("save / update / delete");
$msg_obj["buttonDig_remove_title"] = _mb("remove from workspace");
$msg_obj["buttonDig_removeDb_title"] = _mb("remove from database");
Added: trunk/mapbender/http/php/mod_digitize_splitPolygon.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_splitPolygon.php (rev 0)
+++ trunk/mapbender/http/php/mod_digitize_splitPolygon.php 2008-09-03 12:40:37 UTC (rev 2905)
@@ -0,0 +1,69 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/DeleteWMS
+# 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(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
+
+$json = new Mapbender_JSON();
+
+$lineText = $_REQUEST["line"];
+$polygonText = $_REQUEST["polygon"];
+
+
+$floatPattern = "-?\d+(\.\d+)?";
+$pointPattern = $floatPattern . " " . $floatPattern;
+$polygonPattern = "POLYGON \(\(" . $pointPattern . "(, " . $pointPattern . ")*\)\)";
+$linePattern = "LINESTRING \(" . $pointPattern . ", " . $pointPattern . "\)";
+
+$pattern = "/" . $polygonPattern . "/";
+if (!preg_match($pattern, $polygonText)) {
+ echo "not a polygon.";
+ die();
+}
+
+$pattern = "/" . $linePattern . "/";
+if (!preg_match($pattern, $lineText)) {
+ echo "not a line.";
+ die();
+}
+
+
+$sql = "SELECT astext(geom) FROM dump ((" .
+ "SELECT polygonize(geomunion(boundary('" .
+ $polygonText . "'::geometry),'" .
+ $lineText . "'::geometry))" .
+ "))" .
+ "WHERE contains('" .
+ $polygonText . "'::geometry, pointonsurface(geom)" .
+ ")";
+
+$res = db_query($sql);
+
+$polygonArray = array();
+while ($row = db_fetch_array($res)) {
+ array_push($polygonArray, $row[0]);
+}
+
+$data = array("polygons" => $polygonArray);
+
+$output = $json->encode($data);
+
+header("Content-type:application/x-json; charset=utf-8");
+echo $output;
+?>
\ No newline at end of file
Property changes on: trunk/mapbender/http/php/mod_digitize_splitPolygon.php
___________________________________________________________________
Name: svn:keywords
+ HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
More information about the Mapbender_commits
mailing list