Opened 8 years ago

Closed 8 years ago

#3357 closed defect (invalid)

Polygon intersection with line fails for geography

Reported by: radu123 Owned by: pramsey
Priority: high Milestone: PostGIS 2.2.1
Component: postgis Version: 2.2.x
Keywords: Cc:

Description

The polygon and line should intersect, but ST_Intersects fails:

select ST_intersects(ST_GeogFromText('POLYGON((-107.61362 40.589806,-106.89783 40.278473,-106.37725 39.967155,-106.31217 39.240715,-106.76768 37.528435,-107.35333 36.12747,-108.329414 35.764263,-109.04517 36.075596,-109.24042 36.750122,-109.24042 37.89165,-108.78492 40.122803,-107.93898 40.434128,-107.61362 40.589806))'), ST_GeogFromText('LINESTRING(-120 40, -96.6 40)'));

st_intersects


f

I attach PNG which shows the shapes.

Attachments (1)

feature_collection.png (744.9 KB ) - added by radu123 8 years ago.
Line and Polygon should intersect

Download all attachments as: .zip

Change History (5)

by radu123, 8 years ago

Attachment: feature_collection.png added

Line and Polygon should intersect

comment:1 by radu123, 8 years ago

We noticed that it works if we change the line a bit:

select ST_intersects(ST_GeogFromText('POLYGON((-107.61362 40.589806,-106.89783 40.278473,-106.37725 39.967155,-106.31217 39.240715,-106.76768 37.528435,-107.35333 36.12747,-108.329414 35.764263,-109.04517 36.075596,-109.24042 36.750122,-109.24042 37.89165,-108.78492 40.122803,-107.93898 40.434128,-107.61362 40.589806))'), ST_GeogFromText('LINESTRING(-120 40, -96.7 40)'));

st_intersects


t

comment:2 by radu123, 8 years ago

It also works if we cast the objects to geometry, so it seems to be something related to geography.

select ST_intersects(ST_GeogFromText('POLYGON((-107.61362 40.589806,-106.89783 40.278473,-106.37725 39.967155,-106.31217 39.240715,-106.76768 37.528435,-107.35333 36.12747,-108.329414 35.764263,-109.04517 36.075596,-109.24042 36.750122,-109.24042 37.89165,-108.78492 40.122803,-107.93898 40.434128,-107.61362 40.589806))')::geometry, ST_GeogFromText('LINESTRING(-120 40, -96.6 40)')::geometry);

st_intersects


t

(1 row)

comment:3 by pramsey, 8 years ago

Your line isn't straight like in your picture, it's actually straight in a different way, as a great circle arc (which, in your picture would be a northerly curve). Think about how an airplane would get between the ends of your line. Reasoning about geography on flat maps leads to mistakes like this.

comment:4 by pramsey, 8 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.