« Return to Thread: Spatial query for the Nearest location given a lat and long?

Re: Spatial query for the Nearest location given a lat and long?

by Milo van der Linden :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
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.
  


--
3DSite

Milo van der Linden
skype: milovanderlinden
mlinden@...
milovanderlinden@...
milo@...
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.


_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

 « Return to Thread: Spatial query for the Nearest location given a lat and long?