Get most left|right|top|bottom point contained in box
Posted
by skyman
on Stack Overflow
See other posts from Stack Overflow
or by skyman
Published on 2010-04-03T00:17:47Z
Indexed on
2010/04/03
0:23 UTC
Read the original article
Hit count: 546
I'm storing Points Of Interest (POI) in PostgreSQL database, and retrieve them via PHP script to Android application. To reduce internet usage I want my mobile app to know if there are any points in the neighborhood of currently displayed area.
My idea is to store bounds of the rectangle containing all points already retrieved (in other words: nearest point on the left (West) of most west already retrieved, nearest point above (North) of most north already retrieved etc.) and I will make next query when any edge of screen goes outside of this bounds.
Currently I can retrieve points which are in "single screen" (in the area covered by currently displayed map) using:
SELECT * FROM ch WHERE loc <@ (box '((".-$latSpan.", ".$lonSpan."),(".$latSpan.", ".-$lonSpan."))' + point '".$loc."')
Now I need to know four most remote points in each direction, than I will be able to retrieve next four "more remote" points.
Is there any possibility to get those points (or box) directly from PostgreSQL (maybe using some "aggregate points to box" function)?
© Stack Overflow or respective owner