[postgis-users] RE: Spatial query for the Nearest location given alat and long?

Milo van der Linden mlinden at zeelandnet.nl
Mon Aug 13 16:34:29 PDT 2007


I agree.

In preparing my sample nearest function for this post, I assumed that
the points mentioned where in spatial_columns, hence making best use of
indices and all.
My advice would be to create a geometry column for this table and
convert the lat/lon columns to one spatial column. That's where postGIS
will be at it's best, not in storing doubles in two columns.

Rick Zoolker schreef:
> Looks like you got it.  FYI, ST_Point($longitude, $latitude) will work
> slightly faster than using the GeomFromText().  Also, as Regina
> mentioned, you won't be making use of any spatial indicies here, so
> the query will run slower than what would be possible.
>
> On 8/13/07, bdbeames <bdbeames at cc.usu.edu> wrote:
>   
>> Results
>>
>> Ok, I think it is working.
>>
>> Here what I got for future reference
>>
>> Given a $latitude and $longitude point I query table_1 to find the
>> closest/nearest location points.
>>
>> SELECT id, name,
>>    distance_sphere(GeomFromText('POINT('|| $longitude ||' '|| $latitude
>> ||')'),
>>    GeomFromText('POINT('|| table_1.longitude ||' '|| table_1.latitude
>> ||')')) as dist
>> FROM table_1
>> WHERE active = 't'
>> ORDER BY dist LIMIT 5;
>>
>> Thanks again for all the help
>> --
>> View this message in context: http://www.nabble.com/Spatial-query-for-the-Nearest-location-given-a-lat-and-long--tf4253824.html#a12133535
>> Sent from the PostGIS - User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>     
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>   


-- 


	

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/20070814/5c508310/attachment.html>


More information about the postgis-users mailing list