[postgis-users] Problem with a zero length line

Bruce Rindahl rindahl at lrcwe.com
Fri Sep 22 15:43:14 PDT 2006


I am having a problem with the intersection function in PostGIS.  This is
apparently done in GEOS so this may be the wrong list.  I create a query to
obtain all polylines that intersect a bounding box and they are clipped to
that box using the intersection function.  The query functions as I expected
except when a line just touches the bounding box.  The query then returns a
point instead of a line.  Here is an example where the bounding box is from
0,0 to 1,1 and a line from 0.5,0.5 to 1.5,1.5:

select AsText(Intersection(
LineFromText('LINESTRING(0.5 0.5,1.5 0.5)'),
PolyFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))')
))

Result:
"LINESTRING(0.5 0.5,1 0.5)"

This is as expected - the line from 0.5,0.5 to 1,0.5.

However, if the line just touches the box, the result is a point.

select AsText(Intersection(
LineFromText('LINESTRING(1 0.5,2 0.5)'),
PolyFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))')
))

Result:
"POINT(1 0.5)"

While this is technically correct, I think the result should be:
"LINESTRING(1 0.5,1 0.5)" 

Note this result is a valid geometry and returns a length of 0.

There are two issues.  It you are using this kind of query to update a
geometry column you will get two different types and an error.
Second is if you are expecting a line type a secondary application may
crash.  This is the problem I am having.  I am converting the geometry to
SVG and if I get to a point the rendering will stop because the asSVG
function will give "M ....." for a line and x=".." y=".." for a point.

Any ideas or comments??

Thanks
Bruce Rindahl





More information about the postgis-users mailing list