On 04/06/2010, at 6:20 AM, angus wrote:
The advantage of postgis is you don't query every record in your db
and calc the distance. You use one of those handy db tricks called
indexes.

It's not quite as bad as "every record in the db". You "square the circle"
by multiplying your radius by 1.4, then query every record in a vertical
strip and a horizontal stripe of double that width, and join those. At
worst, that's a full index scan, but will often instead be two (very) partial
scans and an in-memory join, like a hash-join. Not as good as using a
proper spatial index, but not too bad.

There are a lot of other postGIS query types for which there aren't
such good one-dimensional solutions however.

Clifford Heath.


Angus

On Jun 3, 4:31 pm, Nathan de Vries <nat...@atnan.com> wrote:
On 03/06/2010, at 1:45 PM, Keith Pitt wrote:

We wrote a plpgsql function that made it easier for us to find locations within a certain radius.

This functionality is available via the PostgreSQL "earthdistance" module. Your "km_between_lat_long" function can be replaced with:

    earth_distance(ll_to_earth(lat1, lon1), ll_to_earth(lat2, lon2))

I'm unsure whether that would be faster or more accurate than what you're doing, so you'd need to test it.

Cheers,

Nathan

--
You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.
To post to this group, send email to rails-ocea...@googlegroups.com.
To unsubscribe from this group, send email to rails-oceania+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby or 
Rails Oceania" group.
To post to this group, send email to rails-ocea...@googlegroups.com.
To unsubscribe from this group, send email to 
rails-oceania+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to