double from = PG_GETARG_FLOAT8(1);
double to = PG_GETARG_FLOAT8(2);
LWLINE *iline;
- LWLINE *oline;
+ LWGEOM *olwgeom;
POINTARRAY *ipa, *opa;
PG_LWGEOM *ret;
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);
}
/*
* '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);
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));
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)