incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert <robb...@gmx.de>
Subject Range query for more than one dimension (coordinates)
Date Tue, 01 Dec 2009 21:24:02 GMT
Hi list,

I'm currently building a db of documents with locations. Each document 
has a latitude and longitude (in decimal degrees, so it's basically two 
floats).

Now I need a way to select documents within a "rectangle area" defined 
by two coordinates. I tried mapping documents to [doc.lat, doc.lon] and 
doing a range query on that, but after reading the view documentation 
again, it seems that this is not the way to go. (Because I will always 
get all docs with matching latitude first, even if longitude is out of 
range)

I could always do two separate range queries (one for lat, one for lon) 
and then intersect in client code, but that seems inelegant to me.

Is there a better way to do this?

TIA,
robert

p.s. simple example just in case:

I have docs like
[{"_id": "a", "lat": 10, "lon": 10},
  {"_id": "b", "lat": 15, "lon": 15},
  {"_id": "c", "lat": 20, "lon": 11}]

and need to query e.g. for documents between lat 9, lon 9 and lat 25, 
lon 12 returning "a" and "c" but not "b"

Mime
View raw message