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).
<br><br>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?????
<br><br><br><div><span class="gmail_quote">On 8/11/07, <b class="gmail_sendername">Milo van der Linden</b> <<a href="mailto:mlinden@zeelandnet.nl">mlinden@zeelandnet.nl</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
Use a function like this one:<br>
<br>
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<br>
<br>
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.<br>
<br>
Good luck!<br>
<br>
<br>
<br>
bdbeames schreef:
<span class="q"><blockquote type="cite">
<pre>I'm completely new to this so I need some help writing a query.<br><br>What I have is two tables with weather station information: id, name,<br>latitude, longitude, extra.<br><br>I am using google map where a user can click on a station from one of the
<br>tables, I obtain the $latitude and $longitude points of that location. I<br>now want to use these to find the nearest weather station in my other table<br>based on the $latitude and $longitude point.<br><br>All that I need back from the query is the id and name of the nearest
<br>station. Could someone help me write a simple query to do this. <br><br>My development environment is Linux/Apache/Postgres/php.<br><br>Thanks.<br> </pre>
</blockquote>
<br>
<br>
</span><div>-- <br>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tbody>
<tr>
<td rowspan="3" align="left" height="0" valign="bottom" width="15"><br>
</td>
<td colspan="2" align="left" height="78" valign="top" width="0">
<p>Milo van der Linden
<br>
<a>skype: milovanderlinden</a><br>
<a href="mailto:mlinden@zeelandnet.nl" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mlinden@zeelandnet.nl</a><br>
<a href="mailto:milovanderlinden@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">milovanderlinden@gmail.com</a><br>
<a href="mailto:milo@3dsite.nl" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">milo@3dsite.nl</a><br>
<a href="http://www.3dsite.nl" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.3dsite.nl</a><br>
</p>
</td>
<td rowspan="3" align="left" height="0" valign="top" width="15"> </td>
<td valign="top" width="300">
<p><span lang="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.</span>
<span lang="EN">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.</span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br>_______________________________________________<br>postgis-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net
</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br><br>
</blockquote></div><br>