I have a database where cities (villes in french) are stored, with longitude
and latitude values. I'm trying to get some of them, inside a square.
Here is one request:
/sofitex/_design/all/_view/getVillesByLatAndLong?startkey=%5B6.84505190241%2C47.6459660001%5D&endkey=%5B8.64494809759%2C49.4624339999%5D&include_docs=true
Here is the view code:
"getVillesByLatAndLong": {
"map": "function(doc) {if (doc.type=='ville')
{emit([doc.lat,doc.long], doc);};}"
}
The result is empty, but I know I have some cities that match. Could anyone
tell what's wrong?
Best regards,
Stephane Mourey
2010/3/15 Stéphane Mourey <stephan...@gmail.com>
{"total_rows":73751,"offset":0,"rows":[
{"id":"2ab960eb967f8d14f5b6bc1837c2c7fa","key":["",""],"value":{"_id":"2ab960eb967f8d14f5b6bc1837c2c7fa","_rev":"1-bbd075701f8fb02ec7578c71dd631113","type":"ville","id":"142787","nom":"Monaco","cp":"98000","long":"","lat":"","country":"fr"}},
{"id":"6f27cc15079e4317cb6488741abfdec1","key":["-0.015","48.1033"],"value":{"_id":"6f27cc15079e4317cb6488741abfdec1","_rev":"1-435bccb2ad1a150099dd4dd2c0f412c0","type":"ville","id":"133962","nom":"La
Chapelle St Fray","cp":"72240","long":"48.1033","lat":"-0.015","country":"fr"}},
Here is the output, given startkey and endkey (i.e.
/sofitex/_design/all/_view/getVillesByLatAndLong?startkey=%5B6.84505190241%2C47.6459660001%5D&endkey=%5B8.64494809759%2C49.4624339999%5D&include_docs=true):
{"total_rows":73751,"offset":0,"rows":[]}
I get the same when startkey is [0,0] and endkey is [999,999] (i.e.
/sofitex/_design/all/_view/getVillesByLatAndLong?startkey=[0%2C0]&endkey=[999%2C999]&include_docs=true),
but what is expected is all the cities.
2010/3/15 Alex P <aped...@kolosy.com>
2010/3/15 Stéphane Mourey <stephan...@gmail.com>
Cheers
Jan
--
?q=pizza AND lat<double>:[51.4707 TO 51.5224] AND
long<double>:[-0.6622 TO -0.5775]
0.5 isn't released (yet) but it's fairly stable at this point.
B.
the problem is that CouchDB views sort by first part of the key, then by
the second. So the keys of your view might look like:
[1.45,2.45]
[20.96,19.75]
[38.58,3.18]
[45.09,60.30]
[45.09,72.20]
[47.92,23.78]
If you use startkey/endkey only once slice will be cut out. For
startkey=[35.0,1.0],endkey=[46.0,65.0] you'll only get
[38.58,3.18]
[45.09,60.30]
back (and not all the other ones where the second part of the key would
match.
As the others already proposed you need to use an geo-index solution
like geocouch, couchdb-lucene or a geohash.
Cheers,
Volker