You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Tim Burgess <ti...@mac.com> on 2009/06/14 10:12:41 UTC
Retrieving documents that have a latitude and longitude intersection
I've run up couchdb and am trying to use it to serve JSON requests
from a browser javascript application (using google maps).
I've been doing this with MySQL and RoR but the replication and the
ability to simply add image attachments is very appealing to me.
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.lat && doc.lng) {
emit([doc.lat, doc.lng], [doc._id, doc.rating, doc.name,
doc.description]);
}
}
I'm fortunate in that I'm only having to deal with an area that
doesn't cross the equator or prime meridian so essentially I just need
to query
two floats that fall within ranges provided by startkey and endkey.
I'd be very grateful if someone had some idea as to how to do this..
Cheers!
Tim Burgess
timburgess@mac.com
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Seth Falcon <se...@gmail.com>.
On Sun, Jun 14, 2009 at 1:36 PM, Dmitry Unkovsky<oi...@gmail.com> wrote:
> 2009/6/14 Seth Falcon <se...@gmail.com>:
>> startkey = [a, x]
>> endkey = [b, y]
>
> will give [almost] all points that have a<doc.lat<b
Doh! The comparison of complex keys is element by element. I think I
get it now.
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Dmitry Unkovsky <oi...@gmail.com>.
2009/6/14 Seth Falcon <se...@gmail.com>:
> startkey = [a, x]
> endkey = [b, y]
will give [almost] all points that have a<doc.lat<b
Re: Retrieving documents that have a latitude and longitude intersection
Posted by Volker Mische <vo...@gmail.com>.
GeoCouch 0.0.1 doesn't solve your problem, only the current code base I
have does. I'll to put some basic documentation together asap, and drop
you a mail with these instructions (off-list).
Cheers,
Volker
Tim Burgess wrote:
>>>
>>> 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 < doc.lat < b
>>> and x < doc.lng < y, then I think you can do just that:
>>>
>>> startkey = [a, x]
>>> endkey = [b, y]
>>>
>
> Thanks guys. Yes, using arrays clearly wasn't doing the job after a little
> bit of experimentation - I thought there might have been some 'trick' I was
> missing.
>
> Volker, if you could point me to your code I would like to try it out. This
> is a 'must have' thing for me as without it, it's pretty much impossible to
> use couchdb for my app. Yes, I could do two queries from the browser but
> paying for unwanted data across the wire and putting extra load on the
> browser is not a solution for me.
>
> Bounding box is all I need and I could scrape by without anything else
> for the time being so I'd be happy to try GeoCouch. The link to Paul Davis'
> external2 couchdb branch from the link you provided
> goes nowhere on github by the way.
>
> Cheers, Tim
>
>
>
>> 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
>> http://jchrisa.net
>> http://couch.io
>
> Tim Burgess
> timburgess@mac.com <ma...@mac.com>
>
> Kyoto Podcast - Glimpses of Japan
> www.kyotopodcast.jp <http://www.kyotopodcast.jp>
>
>
>
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Tim Burgess <ti...@mac.com>.
>>
>> 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 < doc.lat < b
>> and x < doc.lng < y, then I think you can do just that:
>>
>> startkey = [a, x]
>> endkey = [b, y]
>>
Thanks guys. Yes, using arrays clearly wasn't doing the job after a
little
bit of experimentation - I thought there might have been some 'trick'
I was
missing.
Volker, if you could point me to your code I would like to try it out.
This
is a 'must have' thing for me as without it, it's pretty much
impossible to
use couchdb for my app. Yes, I could do two queries from the browser but
paying for unwanted data across the wire and putting extra load on the
browser is not a solution for me.
Bounding box is all I need and I could scrape by without anything else
for the time being so I'd be happy to try GeoCouch. The link to Paul
Davis'
external2 couchdb branch from the link you provided goes nowhere on
github by the way.
Cheers, Tim
> 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
> http://jchrisa.net
> http://couch.io
Tim Burgess
timburgess@mac.com
Kyoto Podcast - Glimpses of Japan
www.kyotopodcast.jp
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Chris Anderson <jc...@apache.org>.
On Sun, Jun 14, 2009 at 12:26 PM, Seth Falcon<se...@gmail.com> wrote:
> Hi Tim,
>
> On Sun, Jun 14, 2009 at 1:12 AM, Tim Burgess<ti...@mac.com> 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.lat && doc.lng) {
>> emit([doc.lat, doc.lng], [doc._id, doc.rating, doc.name,
>> 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 < doc.lat < 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
http://jchrisa.net
http://couch.io
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Seth Falcon <se...@gmail.com>.
Hi Tim,
On Sun, Jun 14, 2009 at 1:12 AM, Tim Burgess<ti...@mac.com> 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.lat && doc.lng) {
> emit([doc.lat, doc.lng], [doc._id, doc.rating, doc.name,
> 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 < doc.lat < b
and x < doc.lng < y, then I think you can do just that:
startkey = [a, x]
endkey = [b, y]
Is that what you want?
+ seth
Re: Retrieving documents that have a latitude and longitude intersection
Posted by Volker Mische <vo...@gmail.com>.
Hi Tim,
that's a problem GeoCouch [1] tries to solve. The current version that
is online wouldn't work, but I've a version that makes such reuqests
possible (it actually works!).
If you need it immediately, just drop a mail, if you can wait a week or
two, I'll make an new release by then.
Cheers,
Volker
[1]
http://vmx.cx/cgi-bin/blog/index.cgi/geocouch-geospatial-queries-with-couchdb:2008-10-26:en,CouchDB,Python,geo
Tim Burgess wrote:
> I've run up couchdb and am trying to use it to serve JSON requests from
> a browser javascript application (using google maps).
> I've been doing this with MySQL and RoR but the replication and the
> ability to simply add image attachments is very appealing to me.
>
> 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.lat && doc.lng) {
> emit([doc.lat, doc.lng], [doc._id, doc.rating, doc.name,
> doc.description]);
> }
> }
>
> I'm fortunate in that I'm only having to deal with an area that doesn't
> cross the equator or prime meridian so essentially I just need to query
> two floats that fall within ranges provided by startkey and endkey. I'd
> be very grateful if someone had some idea as to how to do this..
>
> Cheers!
>
> Tim Burgess
> timburgess@mac.com
>
Re: Retrieving documents that have a latitude and longitude
intersection
Posted by Manolo Padron Martinez <ma...@gmail.com>.
I've been trying to do complex searchs (like two ranged variables) and
the solution for me was to use couch-lucene
(http://rnewson.github.com/couchdb-lucene/) to index the documents. If
anyone has a better solution that could be done only with chouch would
be great to hear about it.
Regards from Canary Islands
Manuel Padrón Martínez
On Sun, Jun 14, 2009 at 9:12 AM, Tim Burgess<ti...@mac.com> wrote:
> I've run up couchdb and am trying to use it to serve JSON requests from a
> browser javascript application (using google maps).
> I've been doing this with MySQL and RoR but the replication and the ability
> to simply add image attachments is very appealing to me.
>
> 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.lat && doc.lng) {
> emit([doc.lat, doc.lng], [doc._id, doc.rating, doc.name,
> doc.description]);
> }
> }
>
> I'm fortunate in that I'm only having to deal with an area that doesn't
> cross the equator or prime meridian so essentially I just need to query
> two floats that fall within ranges provided by startkey and endkey. I'd be
> very grateful if someone had some idea as to how to do this..
>
> Cheers!
>
> Tim Burgess
> timburgess@mac.com
>