Made line_substring() handle corner case of start/end having the same

value. A point is returned in that case.


git-svn-id: http://svn.osgeo.org/postgis/trunk@2290 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Sandro Santilli 2006-01-19 18:26:32 +00:00
parent 615748762b
commit cff08737ef
4 changed files with 13 additions and 9 deletions

View 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);
}

View 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);

View 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));

View 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)