couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <>
Subject Re: Retrieving documents that have a latitude and longitude intersection
Date Sun, 14 Jun 2009 20:34:43 GMT
On Sun, Jun 14, 2009 at 12:26 PM, Seth Falcon<> wrote:
> Hi Tim,
> On Sun, Jun 14, 2009 at 1:12 AM, Tim Burgess<> wrote:
>> Essentially the client-side requests points that fall within a given
>> latitude and longitude boundary i.e. a southwest lat, long and a northeast
>> lat,long.
>> These are my first steps with map/reduce but I've determined how I can use
>> startkey and endkey to pull documents within a latitude. I'm
>> a bit stumped on a URL query that can do both however.
>> A simple view such as;
>> function(doc) {
>>  if ( && doc.lng) {
>>    emit([, doc.lng], [doc._id, doc.rating,,
>> doc.description]);
>>  }
>> }
> I suspect I may be misunderstanding what you are trying to do.  If you
> want to query for keys from the above view such that: a < < b
> and x < doc.lng < y, then I think you can do just that:
> startkey = [a, x]
> endkey = [b, y]

This will also bring back rows with eg the key [b, w] which is outside
the wanted range.

The simple answer is to have two maps: one by lat and one by long, and
query them both, intersecting to find the rows in both queries (or
more simply to just query for a longitude range and filter the results
by lattitude.) This is not very efficient and hence there are
dedicated strategies for geo indexing.

GeoCouch is probably the best solution, or you could do the work to
integrate another geographic indexer. Adding alternate indexers to
CouchDB is about as simple as can be, so don't be put off by the idea.

> Is that what you want?
> + seth

Chris Anderson

View raw message