From: Sandro Santilli Date: Thu, 11 Mar 2010 20:28:24 +0000 (+0000) Subject: *always* return a collection from ST_SplitGeometry X-Git-Tag: 2.0.0alpha1~3123 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9a589d65b123a027e71cf796d1f093643863f03;p=postgis *always* return a collection from ST_SplitGeometry git-svn-id: http://svn.osgeo.org/postgis/trunk@5413 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_geos_split.c b/postgis/lwgeom_geos_split.c index 150b1362e..a89039666 100644 --- a/postgis/lwgeom_geos_split.c +++ b/postgis/lwgeom_geos_split.c @@ -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 */ diff --git a/regress/split_expected b/regress/split_expected index b5f1a0d73..8e40501aa 100644 --- a/regress/split_expected +++ b/regress/split_expected @@ -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))