Fix incorrect geohash for lat 90, lon 180 (#29256)
Due to special treatment for the 0xFFFFFF... value in GeoHashUtils' encodeLatLon method, the hashcode for lat 90, lon 180 is incorrectly encoded as `"000000000000"` instead of "zzzzzzzzzzzz". This commit removes the special treatment and fixes the issue. Closes #22163
This commit is contained in:
parent
b6568d0cfd
commit
04d0edc8ee
|
@ -57,11 +57,7 @@ public class 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.test.ESTestCase;
|
|||
* 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
|
||||
|
@ -70,4 +70,16 @@ public class GeoHashTests extends ESTestCase {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue