You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by robert <ro...@gmx.de> on 2009/12/01 22:24:02 UTC

Range query for more than one dimension (coordinates)

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"

Re: Range query for more than one dimension (coordinates)

Posted by Christopher O'Connell <jw...@gmail.com>.
I also have externalj for this

http://compu.terlicio.us/code/externalj

~ Christopher

Sent from my iPhone

On Dec 1, 2009, at 14:42, "Michael McCaffrey" <mm...@ittvis.com>  
wrote:

> And this one describing how to use using _lists
>
> http://vmx.cx/cgi-bin/blog/index.cgi/poor-mans-bounding-box-queries-with-couchdb:2009-07-19:en,CouchDB,JavaScript,geo
>
>
>
> -----Original Message-----
> From: Paul Davis [mailto:paul.joseph.davis@gmail.com]
> Sent: Tuesday, December 01, 2009 2:30 PM
> To: user@couchdb.apache.org
> Subject: Re: Range query for more than one dimension (coordinates)
>
> On Tue, Dec 1, 2009 at 4:24 PM, robert <ro...@gmx.de> wrote:
>> 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"
>>
>
> Have you seen GeoCouch?
>
> http://vmx.cx/cgi-bin/blog/index.cgi/geocouch-geospatial-queries-with-couchdb:2008-10-26:en,CouchDB,Python,geo
>
> HTH,
> Paul Davis

RE: Range query for more than one dimension (coordinates)

Posted by Michael McCaffrey <mm...@ittvis.com>.
And this one describing how to use using _lists

http://vmx.cx/cgi-bin/blog/index.cgi/poor-mans-bounding-box-queries-with-couchdb:2009-07-19:en,CouchDB,JavaScript,geo



-----Original Message-----
From: Paul Davis [mailto:paul.joseph.davis@gmail.com] 
Sent: Tuesday, December 01, 2009 2:30 PM
To: user@couchdb.apache.org
Subject: Re: Range query for more than one dimension (coordinates)

On Tue, Dec 1, 2009 at 4:24 PM, robert <ro...@gmx.de> wrote:
> 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"
>

Have you seen GeoCouch?

http://vmx.cx/cgi-bin/blog/index.cgi/geocouch-geospatial-queries-with-couchdb:2008-10-26:en,CouchDB,Python,geo

HTH,
Paul Davis

Re: Range query for more than one dimension (coordinates)

Posted by Paul Davis <pa...@gmail.com>.
On Tue, Dec 1, 2009 at 4:24 PM, robert <ro...@gmx.de> wrote:
> 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"
>

Have you seen GeoCouch?

http://vmx.cx/cgi-bin/blog/index.cgi/geocouch-geospatial-queries-with-couchdb:2008-10-26:en,CouchDB,Python,geo

HTH,
Paul Davis