[Mapbender-commits] r7089 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Nov 4 10:09:57 EDT 2010


Author: kmq
Date: 2010-11-04 07:09:57 -0700 (Thu, 04 Nov 2010)
New Revision: 7089

Modified:
   trunk/mapbender/http/php/mod_digitize_splitLine.php
Log:
Fixed splitLine script to correctly split lines that selfintersect. The old Method would also split at the points of self-intersection.

Modified: trunk/mapbender/http/php/mod_digitize_splitLine.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_splitLine.php	2010-11-04 10:43:52 UTC (rev 7088)
+++ trunk/mapbender/http/php/mod_digitize_splitLine.php	2010-11-04 14:09:57 UTC (rev 7089)
@@ -29,21 +29,49 @@
 	die();
 }
 
-$sql = sprintf("SELECT astext(multi(geom)) FROM dump ((" . 
-	"SELECT ST_AsText(ST_FORCE_COLLECTION(ST_Difference(" . 
-	"'%s'::geometry,'%s'::geometry)))))", $line1Text, $line2Text);
+// find intersection points
 
-$res = db_query($sql);    
+$intersection_sql =  sprintf("SELECT ST_AsText(multipoint.geom) as point, "
+							." ST_AsText(ST_StartPoint('%s'::geometry)) AS startpoint,"
+							." ST_AsText(ST_EndPoint('%s'::geometry)) AS endpoint "
+							." FROM ST_Dump((SELECT ST_AsText(ST_Intersection('%s'::geometry,'%s'::geometry)))) AS multipoint;",
+							$line1Text,$line1Text,$line1Text,$line2Text);
+$res = db_query($intersection_sql);    
 
-$lineArray = array();
+// add first and last points to the array of intersectionpoints
+$points = array();
 while ($row = db_fetch_array($res)) {
-	array_push($lineArray, $row[0]);
+	$points[0] = $row['startpoint'];
+	$endpoint = $row['endpoint'];
+	$points[] = $row['point'];
+
 }
+$points[] = $endpoint;
 
+// go through the point array in pairs, cut into segment, and add each segment onto resultArray
+$lineArray = array();
+for($i = 0; $i < count($points)-1; $i++){
+
+	$pointStartText = $points[$i];
+	$pointEndText = $points[$i+1];
+	
+	$nthSegment_sql = sprintf("SELECT ST_AsText(ST_multi(geom)) AS substring FROM "
+		." ST_Dump((SELECT ST_AsText(ST_FORCE_COLLECTION(ST_Line_Substring("
+			."'%s'::geometry,"
+			."ST_Line_Locate_Point('%s'::geometry,'%s'::geometry),"
+			."ST_Line_Locate_Point('%s'::geometry,'%s'::geometry)"
+		.")))));",
+		$line1Text,$line1Text,$pointStartText,$line1Text,$pointEndText);
+	$res = db_query($nthSegment_sql);    
+	if($row = db_fetch_array($res)){
+		$lineArray[] = $row['substring'];
+	}
+}
+
 $data = array("geometries" => $lineArray);
 
 $output = $json->encode($data);
 
 header("Content-type:application/x-json; charset=utf-8");
 echo $output;
-?>
\ No newline at end of file
+?>



More information about the Mapbender_commits mailing list