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

Rick Zoolker zoolker at gmail.com
Sun Aug 12 15:00:36 PDT 2007


Is this correct?  As far as I can tell, this will not give the desired
results.  The coordinates are specified in lat/long and therefore the
st_distance function will not return the number you expect (e.g. the
distance between long 88 and long 87 will return 1, which is clearly
incorrect).  Therefore you will need to either project the points using a
SRID into a Cartesian plane (use ST_Transform() ) or else you will have to
use the distance_spheroid function (and specify all the associated spheroid
parameters for the earth).

Now I could be wrong.  I know in Oracle Spatial the distance calculation
seems to automatically project if you've specified all the SRIDs correctly.
Maybe Postgis does this as well, but I don't think so.  Anyone else?????


On 8/11/07, Milo van der Linden <mlinden at zeelandnet.nl> wrote:
>
>  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
> mlinden at zeelandnet.nl
> milovanderlinden at gmail.com
> 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.
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070812/763b1c43/attachment.html>


More information about the postgis-users mailing list