--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Isn't it necessary to lookup for 9 different prefixes instead of 4?
I mean: if the problem is with "tree limits" (different branches in
the algorithm binary comparison for lat/lon), what is being constructed
by the geohash algorithm is a grid. Given a search point (lat,lon), if
you want to find "nearby" points, the simple "hash(p1) = hash(p2)" is
not enough, since the "equator problem" can prevent you from getting
geographically nearby points that fall in another branch of the quadtree.
But "near" points can be -without further investigation about the
position of the search point inside its quadrant- in any of the 8 bounding
boxes that surrond the search quadrant.
So, if you want to assure that, given a certain zoom (precission)
in the hash, you get all nearby points to a given point, you have to
search the quadrant holding the search point plus the 8 surrounding
quadrants (up,down,left,right...and... up-left, up-right, down-left,
down-right).
Well, at least that is what I assume by reading the description of
geohashes...
Please, correct me if I'm wrong.
Jose
Ok, I think I see the difference in our reasonings. First of
all, I think I'm refering to "prefixes" when I should talk about
"quadrants" (actually, up to three four quadrants can fall into the
same prefix). The second point is also important; you are talking
about finding four prefixes ("cells overlapping the query window"), I
didn't take into consideration the "query window", but only "nearby
points" given a geohash (a "starting point", no explicit bounding box,
but the one defined by the geohash and assuming the "limit" is, maybe,
the outer zoom level -that is, a convention of mine, sorry- and that
the "zoom level" is implictely defined by the precission of the hash).
I'm working with a simplified version of geohashes. Basically,
the only difference is using characters [a-d] instead of bits, I
think, which leads to a less compact but much easier to "understand"
(for me) naming of quadrants. For example, for precission=1, you'll
split the space into four cells:
a|b
----
c|d
and with precission=2, again, split the space:
aa|ab|ba|bb
----------------
ac|ad|bc|bd
-----------------
ca|cb|da|db
-----------------
cc|cd|dc|dd
Now, if you want to find points near the hash "da" (without a explicit
query window), you have to look for points in da, but also in db, dc,
dd, bc, bd, ad, cb and cd (that is, 9 quadrants). Of course, talking
about prefixes, that list can be reducet to d, bc, bd, ad, db and cd
(6 prefixes, since 4 of the original 9 quadrants get assumed by the
"d" prefix)
As I told, it's just a matter of "my" decission that "nearby points"
given a geohash are those points that fall into the same hash and also
the 8 neighbours. Of course, if you have a "bounding box" things are
easier, since you can obtain the four hashes for each one of the four
corners and just perform a search for those 4 prefixes (that also map
to 4 quadrants, as long as you select the appropriate precission).
Don't know; maybe this is a little bit more complicated than it should
be (I mean, I'm making it more complicated myself), but it's tricky to
try to take into consideration all the variations that can occur when
you use geohashes and, on the other side, the user can use just
"google maps points" and nothing assures you that the "bounding boxes"
of those maps map exactly to the geohash bounding boxes (for example,
what happens if you want to show all point that are inside a given
area, defined by a Google Map instance in a webpage which occurs not
to be a perfect square? that can break the "four cells overlapping the
query window" assumption, I believe)
As I said... a little bit trick. It could be, of course, much more
easier if the datastore had support for GeoPt comparisons (filter
>,<), but at that point you'll get another problem if, for some
reason, you want to also filter by another property (for example,
rating), as long as the datastore api only allows one inequality per
query...
Best,
Jose