[postgis-users] Spatial query for the Nearest location given a lat and long?

Milo van der Linden mlinden at zeelandnet.nl
Sat Aug 11 17:19:28 PDT 2007


Use a function like this one:

select station_id, station_name, distance(stations_2.geom,(select geom
from stations_1 where station_id = 34)) as dist from stations_2 where
station_id <> 34 order by dist asc

hope this one speaks for itself, it returns a table ordered by distance,
from the nearest to the furthest, process the result in a view or something.

Good luck!



bdbeames schreef:
> I'm completely new to this so I need some help writing a query.
>
> What I have is two tables with weather station information: id, name,
> latitude, longitude, extra.
>
> I am using google map where a user can click on a station from one of the
> tables, I obtain the $latitude and $longitude points of that location.  I
> now want to use these to find the nearest weather station in my other table
> based on the $latitude and $longitude point.
>
> All that I need back from the query is the id and name of the nearest
> station.  Could someone help me write a simple query to do this. 
>
> My development environment is Linux/Apache/Postgres/php.
>
> Thanks.
>   


-- 


	

Milo van der Linden
skype: milovanderlinden <skype:milovanderlinden?add>
mlinden at zeelandnet.nl <mailto:mlinden at zeelandnet.nl>
milovanderlinden at gmail.com <mailto:milovanderlinden at gmail.com>
milo at 3dsite.nl <mailto:milo at 3dsite.nl>
http://www.3dsite.nl

	  	

De informatie in dit bericht reflecteert mijn persoonlijke mening en
niet die van een bedrijf of instantie. Aan de informatie kunnen geen
rechten worden ontleend. Indien dit bericht onderdeel is van een forum,
mailing-list of community dan gelden automatisch de bij het betreffende
medium behorende voorwaarden. The information in this message reflects
my personal opinion and not that of a company or public body. All rights
reserved.If this message is contained in a mailing-list or community,
the rights on the medium are automatically adapted.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070812/46eba4e5/attachment.html>


More information about the postgis-users mailing list