[Mapbender-commits] r6066 - in trunk/mapbender: conf http/javascripts http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue May 4 03:55:37 EDT 2010


Author: verenadiewald
Date: 2010-05-04 03:55:36 -0400 (Tue, 04 May 2010)
New Revision: 6066

Added:
   trunk/mapbender/http/php/mod_digitize_mergeLines.php
Modified:
   trunk/mapbender/conf/digitize_default.conf
   trunk/mapbender/http/javascripts/mod_digitize_tab.php
   trunk/mapbender/http/php/mod_digitize_messages.php
Log:
new digitize functionality to merge 2 lines into a single line

Modified: trunk/mapbender/conf/digitize_default.conf
===================================================================
--- trunk/mapbender/conf/digitize_default.conf	2010-05-03 14:21:18 UTC (rev 6065)
+++ trunk/mapbender/conf/digitize_default.conf	2010-05-04 07:55:36 UTC (rev 6066)
@@ -14,6 +14,7 @@
 addButtonDig("digitizeDifference", 1, "punchPolygon_off.png", "", "", 28, 28);
 addButtonDig("digitizeMerge", 1, "mergePolygons_off.png", "", "", 56, 28);
 addButtonDig("lineContinue", 1, "line_continue_off.png", "", "", 85, 28);
+addButtonDig("mergeLine", 1, "mergeLines_off.png", "", "", 114, 28);
 
 //definition of directory of digitize buttons
 buttonDig_imgdir = "../img/button_digitize/";

Modified: trunk/mapbender/http/javascripts/mod_digitize_tab.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-05-03 14:21:18 UTC (rev 6065)
+++ trunk/mapbender/http/javascripts/mod_digitize_tab.php	2010-05-04 07:55:36 UTC (rev 6066)
@@ -307,6 +307,7 @@
 var button_split = "digitizeSplit";
 var button_merge = "digitizeMerge";
 var button_difference = "digitizeDifference";
+var button_line_merge = "mergeLine";
 var _currentGeomIndex = -1;
 
 var digitizeDivTag;
@@ -1165,6 +1166,14 @@
 						currentTitle = msgObj.buttonLabelDifferenceOff;
 					}
 					break;
+				case "mergeLine":
+					if (currentStatus == 1) {
+						currentTitle = msgObj.buttonLabelMergeLineOn;
+					}
+					else {
+						currentTitle = msgObj.buttonLabelMergeLineOff;
+					}
+					break;	
 			}
 			currentButton.title = currentTitle;
 		}
@@ -1193,7 +1202,8 @@
 	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 ||
-			obj.id == button_difference || obj.id == button_line_continue){
+			obj.id == button_difference || obj.id == button_line_continue ||
+			obj.id == button_line_merge){
 					
 		var el = mapDomElement;
 		$(el).mousemove(function (e) {
@@ -1407,6 +1417,59 @@
 				parent.mb_disableThisButton(mod_digitizeEvent);
 			});
 		}
+		else if (obj.id == button_line_merge) {
+			//var applicable = (d.count() > 1);
+			
+/*			var lineTextArray = [];
+			for (var i = 0; i < d.count(); i++) {
+				if (d.get(i).geomType != parent.geomType.line) {
+					applicable = false;
+					lineTextArray = [];
+					break;
+				}
+				lineTextArray.push(d.get(i).toText());
+			}
+*/
+			var applicable = (d.count() == 2) && 
+							(d.get(0).geomType == parent.geomType.line) &&
+							(d.get(1).geomType == parent.geomType.line);
+
+			if (!applicable) {
+				alert(msgObj.messageErrorMergeLineNotApplicable);
+				parent.mb_disableThisButton(mod_digitizeEvent);
+				return false;
+			}
+
+			var line1Text = d.get(0).toText();
+			var line2Text = d.get(1).toText();
+				
+			parent.mb_ajax_post("../php/mod_digitize_mergeLines.php", {line1: line1Text, line2: line2Text}, function(json, status) {
+				var response = eval('(' + json + ')');
+				var line = response.line;
+				if(line == "") {
+					alert(msgObj.errorMessageInvalidLineGeometries);
+					parent.mb_disableThisButton(mod_digitizeEvent);
+					return false;
+				}
+				var wfsConfId = d.get(0).wfs_conf;
+				var wfsProperties = d.get(0).e;
+				var mapIndex = parent.getMapObjIndexByName(mod_digitize_target);
+				
+				d.importGeometryFromText(line, parent.mb_mapObj[mapIndex].epsg);
+				d.get(-1).wfs_conf = wfsConfId;
+				for (var i = 0; i < wfsProperties.count(); i++) {
+					d.get(-1).e.setElement(wfsProperties.getName(i), wfsProperties.getValue(i));
+				}
+				
+				// remove the original lines
+				var len = d.count();
+				for (var i = 0; i < len-1; i++) {
+					d.del(0);
+				}
+				parent.mb_disableThisButton(mod_digitizeEvent);
+				
+			});
+		}	
 	}
 	else {
 		alert("unknown type: " + obj.id);

Added: trunk/mapbender/http/php/mod_digitize_mergeLines.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_mergeLines.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_digitize_mergeLines.php	2010-05-04 07:55:36 UTC (rev 6066)
@@ -0,0 +1,92 @@
+<?php
+# $Id: mod_digitize_mergePolygon.php 4691 2009-09-25 10:39:48Z christoph $
+# 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();
+
+$line1 = $_REQUEST["line1"];
+$line2 = $_REQUEST["line2"];
+
+#$lineList = $_REQUEST["lines"];
+
+$floatPattern = "-?\d+(\.\d+)?";
+$pointPattern = $floatPattern . " " . $floatPattern;
+$linePattern = "LINESTRING \(" . $pointPattern . ",( )*" . $pointPattern . "(,( )*" . $pointPattern . ")*\)";
+
+$pattern = "/" . $linePattern . "/";
+
+#if (!preg_match($pattern, $lineList)) {
+#	echo "not a line.";
+#	die();
+#}
+
+if (!preg_match($pattern, $line1)) {
+	echo "Line 1 not a line.";
+	die();
+}
+
+if (!preg_match($pattern, $line2)) {
+	echo "Line 2 not a line.";
+	die();
+}
+
+#$lineArray = explode(";", $lineList);
+
+//check for valid lines for merging (2 lines)
+$sql = "SELECT "; 
+$sql .= "ST_StartPoint(ST_GeomFromText('" . $line1 . "')) = ST_StartPoint(ST_GeomFromText('" . $line2 . "')) as a, ";
+$sql .= "ST_StartPoint(ST_GeomFromText('" . $line1 . "')) = ST_EndPoint(ST_GeomFromText('" . $line2 . "')) as b, ";
+$sql .= "ST_EndPoint(ST_GeomFromText('" . $line1 . "')) = ST_StartPoint(ST_GeomFromText('" . $line2 . "')) as c, ";
+$sql .= "ST_EndPoint(ST_GeomFromText('" . $line1 . "')) = ST_EndPoint(ST_GeomFromText('" . $line2 . "')) as d";
+
+$res = db_query($sql); 
+$row = db_fetch_array($res);
+
+if($row['a'] == 't' || $row['b'] == 't' || $row['c'] == 't' || $row['d'] == 't') {
+	$sql = "SELECT ST_AsText(multi(st_linemerge(st_collect_garray(ARRAY[";
+	$sql .= "ST_GeomFromText('" . $line1 . "'), ST_GeomFromText('" . $line2 . "')";
+/*	for ($i = 0; $i < count($lineArray); $i++) {
+		if ($i > 0) {
+			$sql .= ", ";
+		}
+		$sql .= "ST_GeomFromText('" . $lineArray[$i] . "')";
+	}
+*/		
+	$sql .= "])))) as a";
+	
+	#echo $sql;
+	$res = db_query($sql);    
+	
+	$lineArray = array();
+	$row = db_fetch_array($res);
+	
+	$data = array("line" => $row[0]);
+	
+}
+else {
+	$data = array("line" => "");
+}
+
+$output = $json->encode($data);
+
+header("Content-type:application/x-json; charset=utf-8");
+echo $output;
+?>
\ No newline at end of file

Modified: trunk/mapbender/http/php/mod_digitize_messages.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_messages.php	2010-05-03 14:21:18 UTC (rev 6065)
+++ trunk/mapbender/http/php/mod_digitize_messages.php	2010-05-04 07:55:36 UTC (rev 6066)
@@ -26,6 +26,7 @@
 $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 or a line, the second geometry shall be a line.");
 $msg_obj["messageErrorDifferenceNotApplicable"] = _mb("Exactly two polygons must be available.");
+$msg_obj["messageErrorMergeLineNotApplicable"] = _mb("Exactly two lines must be available.");
 $msg_obj["messageSuccessWfsWrite"] = _mb("Success.");
 $msg_obj["messageConfirmDeleteGeomFromDb"] = _mb("Delete geometry from database?");
 $msg_obj["messageConfirmDeleteAllGeomFromList"] = _mb("Clear list of geometries?");
@@ -36,6 +37,7 @@
 $msg_obj["buttonLabelAbort"] = _mb("Abort");
 $msg_obj["errorMessageEpsgMismatch"] = _mb("Fatal error: EPSG mismatch. ");
 $msg_obj["errorMessageNoGeometrySelected"] = _mb("No geometry selected!");
+$msg_obj["errorMessageInvalidLineGeometries"] = _mb("No valid line geometries for merging! Please check start and end points of your lines.");
 $msg_obj["buttonLabelPointOff"] = _mb("add point");
 $msg_obj["buttonLabelPointOn"] = _mb("cancel editing");
 $msg_obj["buttonLabelLineOff"] = _mb("add line");
@@ -58,6 +60,8 @@
 $msg_obj["buttonLabelSplitOn"] = _mb("Split a polygon/line by a line (the new polygons/lines will be added to the geometry list)");
 $msg_obj["buttonLabelDifferenceOff"] = _mb("Combine two polygons (to create en- and exclave or to compute the difference)");
 $msg_obj["buttonLabelDifferenceOn"] = _mb("Split geometries");
+$msg_obj["buttonLabelMergeLineOff"] = _mb("Merge two lines into a single line");
+$msg_obj["buttonLabelMergeLineOn"] = _mb("Merge two lines into a single line");
 $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");



More information about the Mapbender_commits mailing list