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:
*
/* 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 */
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))