diff --git a/lwgeom/lwgeom_functions_analytic.c b/lwgeom/lwgeom_functions_analytic.c index 16898d57b..7aec30fa6 100644 --- a/lwgeom/lwgeom_functions_analytic.c +++ b/lwgeom/lwgeom_functions_analytic.c @@ -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); } diff --git a/lwgeom/ptarray.c b/lwgeom/ptarray.c index 8a4a88ac0..a6d2a1440 100644 --- a/lwgeom/ptarray.c +++ b/lwgeom/ptarray.c @@ -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); diff --git a/regress/regress_lrs.sql b/regress/regress_lrs.sql index 88a00c57f..c9e7d7523 100644 --- a/regress/regress_lrs.sql +++ b/regress/regress_lrs.sql @@ -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)); diff --git a/regress/regress_lrs_expected b/regress/regress_lrs_expected index 49c26c955..ab89af5ca 100644 --- a/regress/regress_lrs_expected +++ b/regress/regress_lrs_expected @@ -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)