Skip to content

Fix incorrect geohash for lat 90, lon 180 #29256

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ private GeoHashUtils() {
* 31 bit encoding utils *
*************************/
public static long encodeLatLon(final double lat, final double lon) {
long result = MortonEncoder.encode(lat, lon);
if (result == 0xFFFFFFFFFFFFFFFFL) {
return result & 0xC000000000000000L;
}
return result >>> 2;
return MortonEncoder.encode(lat, lon) >>> 2;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Tests for {@link org.elasticsearch.common.geo.GeoHashUtils}
*/
public class GeoHashTests extends ESTestCase {
public void testGeohashAsLongRoutines() {
public void testGeohashAsLongRoutines() {
final GeoPoint expected = new GeoPoint();
final GeoPoint actual = new GeoPoint();
//Ensure that for all points at all supported levels of precision
Expand Down Expand Up @@ -70,4 +70,16 @@ public void testBboxFromHash() {
assertEquals(expectedLatDiff, bbox.maxLat - bbox.minLat, 0.00001);
assertEquals(hash, GeoHashUtils.stringEncode(bbox.minLon, bbox.minLat, level));
}

public void testGeohashExtremes() {
assertEquals("000000000000", GeoHashUtils.stringEncode(-180, -90));
assertEquals("800000000000", GeoHashUtils.stringEncode(-180, 0));
assertEquals("bpbpbpbpbpbp", GeoHashUtils.stringEncode(-180, 90));
assertEquals("h00000000000", GeoHashUtils.stringEncode(0, -90));
assertEquals("s00000000000", GeoHashUtils.stringEncode(0, 0));
assertEquals("upbpbpbpbpbp", GeoHashUtils.stringEncode(0, 90));
assertEquals("pbpbpbpbpbpb", GeoHashUtils.stringEncode(180, -90));
assertEquals("xbpbpbpbpbpb", GeoHashUtils.stringEncode(180, 0));
assertEquals("zzzzzzzzzzzz", GeoHashUtils.stringEncode(180, 90));
}
}