开发者

PostGIS: Finding LineStrings that overlap a box

I want to specify a box (i.e. 2 points) and select all the linestrings that are either within or intersect the box.

SELECT * FROM pub_trail_segment WHERE st_force_2d(pub_trail_segment.geometry) && ST_SetSRID(ST_MakeBox2D(ST_GeomFromEWKT('SRID=4326;POINT(48.25077560316286 -124.46710205078124)'), ST_GeomFromEWKT('SRID=4326;POINT(50.4743709029765 -120.73239135742186)')), 4326);

However it's returning 0 rows. I've tried expanding the size of the box and forcing the geometry column to 2D but I can't see what I'm missing.

The test data follows - (DBTestCase format but you get the idea):

<pub_trail_segment id="1" pub_trail_id="1" geometry="SRID=4326;LINESTRING(-123.258275 7 49.3607281 123.666748, -123.2583172 49.3607195 120.302124)"/>   
<pub_trail_segment id="2" pub_trail_id="3" geometry="SRID=4326;LINESTRING(-123.2582757 49.3607281 123.666748, -123.2583172 49.3607195 120.302124, -123.3583172 49.3607195 120.402124)"/>
<pub_trail_segment id="3" pub_trail_id="1" geometry="SRID=4326;LINESTRING(-123.3582757 49.4607281 123.666748, -123.3583172 49.4607195 120.302124)"/>
<pub_trail_segment id="4" pub_trail_id="开发者_如何学Go4" geometry="SRID=4326;LINESTRING(-123.3582757 50.4607281 123.666748, -123.3583172 50.4607195 120.302124)"/>

Thanks for your help!


I worked it out. I had the latitude and longitude round the wrong way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜