Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#3511 closed defect (invalid)

ST_Intersects returns false positives at equator and anti/prime meridian

Reported by: jgm1972 Owned by: pramsey
Priority: medium Milestone: PostGIS 2.4.0
Component: postgis Version: 2.2.x
Keywords: ST_Intersects Cc:

Description

Using PGAdmin3 v1.22.0 and the Postres App version 9.5.0.0 on a MacBook running OSX 10.11.3, ST_Intersects returns false positives when intersecting two lines.

When running an intersection with the anitmeridian, if the second line contains a vertex at longitude 0 and any vertex > longitude 90 or < -90, the intersection returns true. For example,

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90.1 1, 0 0.1, -90 -1)') as line2;

and

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 1, 0 0.1, -90.1 -1)') as line2;

return true, but

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 1, 0 0.1, -90 -1)') as line2;

and

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 1, 0 0, -90 -1)') as line2;

return false.

Additionally, if the end vertices of the line are on the equator and > longitude 90 or < -90 ST_intersects returns true if the line has another vertex with latitude or longitude 0 .

For example,

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 0, 0.1 0, -90.1 0)') as line2;

and

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 0, 0 0.1, -90.1 0)') as line2;

return true, but

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 0, 0.1 0, -90 0)') as line2;

and

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 0, 0 0.1, -90 0)') as line2;

and

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString (90 0, 0 0, -90 0)') as line2;

return false.

Change History (5)

comment:1 by jgm1972, 8 years ago

After the fourth example, I meant to include

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString? (90.1 1, 0.1 0, -90 -1)') as line2;

returns false.

Last edited 8 years ago by jgm1972 (previous) (diff)

comment:2 by robe, 8 years ago

Milestone: PostGIS PostgreSQLPostGIS 2.2.3

comment:3 by robe, 8 years ago

Milestone: PostGIS 2.2.3PostGIS 2.4.0

comment:4 by pramsey, 7 years ago

Resolution: invalid
Status: newclosed

Great circles between antipodes do not have a deterministic path. What is the shortest paths between the north and south pole? It's any line you wish, they are all the shortest/longest paths. As you found, adding mid-points to lines allows you to direct the line where you "want", because each segment in the line is now shorter than an antipodal segment and has a deterministic path. Moral of the story: use segments of < 180 degrees.

comment:5 by jgm1972, 7 years ago

Can you elaborate on why

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString? (90 1, 0 0.1, -90.1 -1)') as line2;

returns true

but

SELECT ST_Intersects(line, line2) as inter from ST_GeogFromText('LINESTRING(180 -90, 180 0, 180 90)') As line, ST_GeogFromText('LineString? (90 1, 0 0, -90 -1)') as line2;

returns false?

The segments are <180 deg.

Note: See TracTickets for help on using tickets.