Opened 14 years ago

Closed 14 years ago

#832 closed defect (invalid)

Wrong line from ST_Difference

Reported by: aperi2007 Owned by: pramsey
Priority: medium Milestone: PostGIS 2.0.0
Component: postgis Version: master
Keywords: Cc:

Description

I notice this strange results:

If I try this sql:

SELECT ST_AsText(
ST_Difference(
ST_GeomFromText('LINESTRING(50 49.9999999999999, 50 200)'),
ST_Intersection(ST_GeomFromText('LINESTRING(50 50, 50 150)'),ST_GeomFromText('POLYGON((30 50, 30 150, 70 150, 70 50, 30 50))')
)
));

the result is: MULTILINESTRING((50 49.9999999999999,50 50),(50 150,50 200))


Instead if I add another digit:

SELECT ST_AsText(
ST_Difference(
ST_GeomFromText('LINESTRING(50 49.99999999999999, 50 200)'),
ST_Intersection(ST_GeomFromText('LINESTRING(50 50, 50 150)'),ST_GeomFromText('POLYGON((30 50, 30 150, 70 150, 70 50, 30 50))')
)
));

the result is: MULTILINESTRING((50 50,50 50),(50 150,50 200))


and if I add another digit again

SELECT ST_AsText(
ST_Difference(
ST_GeomFromText('LINESTRING(50 49.999999999999999, 50 200)'),
ST_Intersection(ST_GeomFromText('LINESTRING(50 50, 50 150)'),ST_GeomFromText('POLYGON((30 50, 30 150, 70 150, 70 50, 30 50))')
)
));

the result is: LINESTRING(50 150,50 200)


I guess the second result is not correct because it return a multiline with a point.

I'm using debian lenny 32 bit with postgres 9.0.1 and Postgis trunk r6824 and geos svn r3222

Change History (2)

comment:1 by strk, 14 years ago

Ask ST_IsValid about the single-point linestring. You might be getting fooled by floating point output.

comment:2 by aperi2007, 14 years ago

Resolution: invalid
Status: newclosed

I try ST_IsValid(..) MULTILINESTRING((50 50,50 50),(50 150,50 200))

gasp, Is valid !

I wrong guess because I know these other was invalid:

ST_IsValid(ST_GeomFromText('LINESTRING(50 50,50 50)')) ⇒ false and also ST_IsValid(ST_GeomFromText('MULTILINESTRING((50 50,50 50))')) ⇒ false

so ST_IsValid() give that MULTILINESTRING((50 50,50 50),(50 150,50 200)) is valid meanwhile MULTILINESTRING((50 50,50 50)) is not valid

ok, because "De gustibus non disputandum est"

I return to the ticket :)

Perhaps is better I explain better because I think this is a problem.

Infact running this complex query on a windows machine with postgres 9.0.3 and postgis 2.0.0 trunk

select
 id,
 st_intersection(b.geom,st_exteriorring(a.geom)),
 b.geom
from
 table_polygons as a,
 table_linestrings as b
where
 a.id = b.id
 and
 st_containsproperly(a.geom,b.geom)=false
 and
 st_crosses(b.geom,a.geom)=true
;

I'm having this error:

ERROR: lwcollection_construct: mixed dimension geometries: 2/0

analyzing the data I guess the problem was generated from st_intersection(b.geom,st_exteriorring(a.geom))

when encounter a linestring that return a point exactly on the boundary of a polygon. So I see these problem and perhaps wrongly open a ticket on the problem of MULTILINESTRING((50 50,50 50),(50 150,50 200))

I think is preferrable to close this ticket and open a specific ticket.

Note: See TracTickets for help on using tickets.