]> granicus.if.org Git - postgis/commitdiff
*always* return a collection from ST_SplitGeometry
authorSandro Santilli <strk@keybit.net>
Thu, 11 Mar 2010 20:28:24 +0000 (20:28 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 11 Mar 2010 20:28:24 +0000 (20:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5413 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_geos_split.c
regress/split_expected

index 150b1362eee02c70b7e7cb281a2f019e137edbac..a890396662b81c13d1afc96b294f05132b245c48 100644 (file)
@@ -42,15 +42,13 @@ static LWGEOM* lwline_split_by_point(LWLINE* lwgeom_in, LWPOINT* blade_in);
 static LWGEOM*
 lwline_split_by_point(LWLINE* lwline_in, LWPOINT* blade_in)
 {
-       GEOSGeometry* line;
-       GEOSGeometry* point;
        double loc, dist;
-       int intersects;
        POINT2D pt;
        POINTARRAY* pa1;
        POINTARRAY* pa2;
        LWGEOM** components;
        LWCOLLECTION* out;
+       int ncomponents;
 
        /* Possible outcomes:
         *
@@ -65,30 +63,39 @@ lwline_split_by_point(LWLINE* lwline_in, LWPOINT* blade_in)
 
        /* lwnotice("Location: %g -- Distance: %g", loc, dist); */
 
-       if ( dist > 0 ) { /* TODO: accept a tolerance ? */
-               /* No intersection */
-               return (LWGEOM*)lwline_clone(lwline_in);
-       }
-
-       /* There is an intersection, let's get two substrings */
-
-       if ( loc == 0 || loc == 1 )
+       do
        {
-               /* Intersection is on the boundary or outside */
-               return (LWGEOM*)lwline_clone(lwline_in);
-       }
-
-       pa1 = ptarray_substring(lwline_in->points, 0, loc);
-       pa2 = ptarray_substring(lwline_in->points, loc, 1);
-
-       /* TODO: check if either pa1 or pa2 are empty ? */
-
-       components = lwalloc(sizeof(LWGEOM*)*2);
-       components[0] = (LWGEOM*)lwline_construct(-1, NULL, pa1);
-       components[1] = (LWGEOM*)lwline_construct(-1, NULL, pa2);
+               components = lwalloc(sizeof(LWGEOM*)*2);
+               ncomponents = 1;
+
+               if ( dist > 0 ) { /* TODO: accept a tolerance ? */
+                       /* No intersection */
+                       components[0] = (LWGEOM*)lwline_clone(lwline_in);
+                       components[0]->SRID = -1;
+                       break;
+               }
+
+               /* There is an intersection, let's get two substrings */
+               if ( loc == 0 || loc == 1 )
+               {
+                       /* Intersection is on the boundary or outside */
+                       components[0] = (LWGEOM*)lwline_clone(lwline_in);
+                       components[0]->SRID = -1;
+                       break;
+               }
+
+               pa1 = ptarray_substring(lwline_in->points, 0, loc);
+               pa2 = ptarray_substring(lwline_in->points, loc, 1);
+
+               /* TODO: check if either pa1 or pa2 are empty ? */
+
+               components[0] = (LWGEOM*)lwline_construct(-1, NULL, pa1);
+               components[1] = (LWGEOM*)lwline_construct(-1, NULL, pa2);
+               ++ncomponents;
+       } while (0);
 
        out = lwcollection_construct(COLLECTIONTYPE, lwline_in->SRID,
-               NULL, 2, components);
+               NULL, ncomponents, components);
 
        /* That's all folks */
 
index b5f1a0d73909d0d1e9d83cfee2817aa5524448e4..8e40501aacbb0a18a6b60e3694a67af99988e21b 100644 (file)
@@ -1,3 +1,3 @@
 1|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,5 0),LINESTRING(5 0,10 0))
-2|SRID=10;LINESTRING(0 0,10 0)
-3|SRID=10;LINESTRING(0 0,10 0)
+2|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))
+3|SRID=10;GEOMETRYCOLLECTION(LINESTRING(0 0,10 0))