]> granicus.if.org Git - postgis/commitdiff
Made line_substring() handle corner case of start/end having the same
authorSandro Santilli <strk@keybit.net>
Thu, 19 Jan 2006 18:26:32 +0000 (18:26 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 19 Jan 2006 18:26:32 +0000 (18:26 +0000)
value. A point is returned in that case.

git-svn-id: http://svn.osgeo.org/postgis/trunk@2290 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_functions_analytic.c
lwgeom/ptarray.c
regress/regress_lrs.sql
regress/regress_lrs_expected

index 16898d57b8bd2aa0ddde1faf110b47d93af91f2c..7aec30fa6bbdb09e2f17d525c564f05c6beeb304 100644 (file)
@@ -950,7 +950,7 @@ Datum LWGEOM_line_substring(PG_FUNCTION_ARGS)
        double from = PG_GETARG_FLOAT8(1);
        double to = PG_GETARG_FLOAT8(2);
        LWLINE *iline;
-       LWLINE *oline;
+       LWGEOM *olwgeom;
        POINTARRAY *ipa, *opa;
        PG_LWGEOM *ret;
 
@@ -979,10 +979,14 @@ Datum LWGEOM_line_substring(PG_FUNCTION_ARGS)
 
        opa = ptarray_substring(ipa, from, to);
 
-       oline = lwline_construct(iline->SRID, 0, opa);
-       ret = pglwgeom_serialize((LWGEOM *)oline);
+       if ( opa->npoints == 1 ) // Point returned
+               olwgeom = (LWGEOM *)lwpoint_construct(iline->SRID, NULL, opa);
+       else
+               olwgeom = (LWGEOM *)lwline_construct(iline->SRID, NULL, opa);
+
+       ret = pglwgeom_serialize(olwgeom);
        PG_FREE_IF_COPY(geom, 0);
-       lwgeom_release((LWGEOM *)oline);
+       lwgeom_release(olwgeom);
        PG_RETURN_POINTER(ret);
 }
 
index 8a4a88ac0576f540ff60e16d39db44793b90b02a..a6d2a1440816a1e0b357aae284b959b4f70181b9 100644 (file)
@@ -587,17 +587,13 @@ ptarray_substring(POINTARRAY *ipa, double from, double to)
 
                        /*
                         * 'to' point is our first point.
-                        * Weird, should have been handled
-                        * by previous iteration as second point
-                        * unless to==0. Let's warn and handle
-                        * anyway
+                        * (should only happen if 'to' is 0)
                         */
                        else if ( to == tlength )
                        {
 #ifdef PGIS_DEBUG
                                lwnotice(" First point is our end");
 #endif
-                               lwnotice("Is 'to' parameter == 0 ?");
 
                                dynptarray_addPoint4d(dpa, &p1, 0);
 
index 88a00c57ff01c79144ca36b539935e6d6867dc16..c9e7d75238a882e8b92363f268aa2dc7fed438d5 100644 (file)
@@ -44,3 +44,5 @@ select 'line_substring', asewkt(line_substring('LINESTRINGM(0 0 0, 4 4 4)', .25,
 select 'line_substring', asewkt(line_substring('LINESTRINGM(0 0 4, 4 4 0)', .25, 0.5));
 select 'line_substring', asewkt(line_substring('LINESTRING(0 0 4, 4 4 0)', .25, 0.5));
 
+select 'line_substring', asewkt(line_substring('LINESTRING(0 0, 1 1)', 0, 0));
+select 'line_substring', asewkt(line_substring('LINESTRING(0 0 10, 1 1 5)', 0.5, .5));
index 49c26c955ff4b5b50f56dd49a4496cb96c83b5c3..ab89af5cacc16b8e5d3e548f74168d8090c9faaa 100644 (file)
@@ -28,3 +28,5 @@ line_substring|LINESTRING(1 1,2 2)
 line_substring|LINESTRINGM(1 1 1,2 2 2)
 line_substring|LINESTRINGM(1 1 3,2 2 2)
 line_substring|LINESTRING(1 1 3,2 2 2)
+line_substring|POINT(0 0)
+line_substring|POINT(0.5 0.5 7.5)