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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Nov 9 05:40:03 EST 2010


Author: kmq
Date: 2010-11-09 02:40:03 -0800 (Tue, 09 Nov 2010)
New Revision: 7101

Modified:
   trunk/mapbender/http/php/mod_digitize_splitLine.php
Log:
behave properly if the lines to be split, don't intersect

Modified: trunk/mapbender/http/php/mod_digitize_splitLine.php
===================================================================
--- trunk/mapbender/http/php/mod_digitize_splitLine.php	2010-11-09 10:39:42 UTC (rev 7100)
+++ trunk/mapbender/http/php/mod_digitize_splitLine.php	2010-11-09 10:40:03 UTC (rev 7101)
@@ -38,40 +38,44 @@
 							$line1Text,$line1Text,$line1Text,$line2Text);
 $res = db_query($intersection_sql);    
 
+
 // add first and last points to the array of intersectionpoints
 $points = array();
+$lineArray = array();
+
 while ($row = db_fetch_array($res)) {
 	$points[0] = $row['startpoint'];
 	$endpoint = $row['endpoint'];
 	$points[] = $row['point'];
-
 }
-$points[] = $endpoint;
+// if the two lines don't intersect, we just do nothing, and return the lines we were given
+if(count($points) == 0){
+	$lineArray[] = $line1Text;
+	$lineArray[] = $line2Text;
+}else{
+	$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++){
+	// go through the point array in pairs, cut into segment, and add each segment onto resultArray
+	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'];
+		$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;
 ?>



More information about the Mapbender_commits mailing list