apache / apache/lucene

Geohash encode/decode floating point problems [LUCENE-1815]

Open
#2,890 8 comments 0 reactions 0 assignees View on GitHub
affects-version:2.9 legacy-jira-priority:Minor module:spatial type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

i'm finding the Geohash support in the spatial package to be rather unreliable.
Here is the outcome of a test that encodes/decodes the same lat/lon and geohash a few times.
the format:
action geohash=(latitude, longitude)

the result:
encode u173zq37x014=(52.3738007,4.8909347)
decode u173zq37x014=(52.373799999999996,4.890934)
encode u173zq37rpbw=(52.373799999999996,4.890934)
decode u173zq37rpbw=(52.373799999999996,4.8909329999999995)
encode u173zq37qzzy=(52.373799999999996,4.8909329999999995)

if I now change to the google code implementation:

encode u173zq37x014=(52.3738007,4.8909347)
decode u173zq37x014=(52.37380061298609,4.890934377908707)
encode u173zq37x014=(52.37380061298609,4.890934377908707)
decode u173zq37x014=(52.37380061298609,4.890934377908707)
encode u173zq37x014=(52.37380061298609,4.890934377908707)

Note the differences between the geohashes in both situations and the lat/lon's!
Now things get worse if you work on low-precision geohashes:

decode u173=(52.0,4.0)
encode u14zg429yy84=(52.0,4.0)
decode u14zg429yy84=(52.0,3.999999)
encode u14zg429ywx6=(52.0,3.999999)

and google:

decode u173=(52.20703125,4.5703125)
encode u17300000000=(52.20703125,4.5703125)
decode u17300000000=(52.20703125,4.5703125)
encode u17300000000=(52.20703125,4.5703125)

We are using geohashes extensively and will now use the google code version unfortunately.

---
Migrated from [LUCENE-1815](https://issues.apache.org/jira/browse/LUCENE-1815) by Wouter Heijke (@wheijke), updated Nov 30 2013

Contributor guide

Open the contributing guide

Research direction

Start in Lucene's spatial package and inspect the current geohash encode/decode implementation against the Google code version described in the issue. Reproduce the supplied high- and low-precision examples, then verify that repeated encode/decode operations remain stable and that the resulting coordinates and geohashes match the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.