Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Multiple geohashes decode to same lat/lon #63

Open
dasjo opened this issue Dec 19, 2012 · 6 comments
Open

Multiple geohashes decode to same lat/lon #63

dasjo opened this issue Dec 19, 2012 · 6 comments

Comments

@dasjo
Copy link

dasjo commented Dec 19, 2012

hi,

i'm having a problem with decoding geohashes:

  • 'u26r' and 'u26q' both decode to lat 48, lon 15.

i can "reproduce" this here
http://geohash.org/u26r
http://geohash.org/u26q

on the other hand, these sites visualize those geohashes as different squares

u26r
latitude :47.724609
longitude:14.589844

u26q
latitude :47.548828
longitude:14.589844

http://geohash.2ch.to/u26r
http://geohash.2ch.to/u26q
http://openlocation.org/geohash/geohash-js/
http://geohash.gofreerange.com/

i'm confused, thanks for any clarification :)

@dasjo
Copy link
Author

dasjo commented Dec 19, 2012

to me this seems like a rounding issue. here's my workaround
dasjo@fba595c

@mprins
Copy link
Contributor

mprins commented Dec 19, 2012

geoPHP conforms to the spec/reference of geohash.org (see also: https://en.wikipedia.org/wiki/Geohash)

The second list of examples that you provide is actually incorrect as these provide a sense of accuracy that is false, anything beyond the integer values (or at least the thenths fraction) is made up, an artifact of the conversion.

Also because you're using 4 chars the precision is different for lat and lon

That doesn't mean our rounding is perfect or couldn't be enhanced, however I think your change actually introduces more error/noise than it solves.

ps. if you want the squares/bounding boxes you should pass the $as_grid =TRUE to read().

@dasjo
Copy link
Author

dasjo commented Dec 19, 2012

thanks for the quick feedback. i'm not sure, if the implemented rounding really conforms to the spec.

the wikipedia article states:

"Final rounding should be done carefully in a way that
min <= round(value) <= max
So if rounding 42.605 to 42.61 or 42.6 is correct, rounding to 43 it is not."

i didn't double check manually, but the example from http://geohash.2ch.to/u26r stated that u26r maps to
latitude min / max: 47.636719 / 47.812500
longitude min / max: 14.414063 / 14.765625

if those are correct, we should only round up to
lat: 47.7
lon: 14.6

@dasjo
Copy link
Author

dasjo commented Dec 20, 2012

besides that, thanks for the pointer to pass the $as_grid =TRUE to read(). i should be able to use this workaround for calculating a center point within the application.

the reason why this bugs me, is because for http://drupal.org/project/geocluster, i decided to use geohash prefixes for spatial clustering. this obviously doesn't work when i want to visualize clusters based on their geohash prefix and sometimes different geohash prefixes map to equal lat/lon points.

@mprins
Copy link
Contributor

mprins commented Dec 20, 2012

I think you're correct on the rounding.

I think you can force higher precision hashes using the $precision = parameter on write(), i think this should be an integer..

@phayes
Copy link
Owner

phayes commented Apr 23, 2013

@dasjo, would you be willing to create a pull request for this?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants