Class Geohash

java.lang.Object
org.elasticsearch.geometry.utils.Geohash

public class Geohash extends Object
Utilities for converting to/from the GeoHash standard The geohash long format is represented as lon/lat (x/y) interleaved with the 4 least significant bits representing the level (1-12) [xyxy...xyxyllll] This differs from a morton encoded value which interleaves lat/lon (y/x). NOTE: this will replace org.elasticsearch.common.geo.GeoHashUtils
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    maximum precision for geohash strings
  • Method Summary

    Modifier and Type
    Method
    Description
    static final <E extends Collection<? super String>>
    E
    addNeighbors(String geohash, E neighbors)
    Add all geohashes of the cells next to a given geohash to a list.
    static final <E extends Collection<? super String>>
    E
    addNeighborsAtLevel(String geohash, int level, E neighbors)
    Add all geohashes of the cells next to a given geohash to a list.
    static double
    decodeLatitude(long hash)
    decode latitude value from morton encoded geo point
    static final double
    returns the latitude value from the string based geohash
    static double
    decodeLongitude(long hash)
    decode longitude value from morton encoded geo point
    static final double
    returns the latitude value from the string based geohash
    static int
    encodeLatitude(double latitude)
    encode latitude to integer
    static int
    encodeLongitude(double longitude)
    encode longitude to integer
    static final String
    getNeighbor(String geohash, int level, int dx, int dy)
    Calculate the geohash of a neighbor of a geohash
    static Collection<? extends CharSequence>
    Calculate all neighbors of a given geohash cell.
    static String[]
    getSubGeohashes(String baseGeohash)
    Array of geohashes one level below the baseGeohash.
    static double
    latHeightInDegrees(int precision)
    approximate height of geohash tile for a specific precision in degrees
    static final long
    longEncode(double lon, double lat, int level)
    Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
    static final long
    Encode a string geohash to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
    static double
    lonWidthInDegrees(int precision)
    approximate width of geohash tile for a specific precision in degrees
    static long
    Encode to a morton long value from a given geohash string
    static final String
    stringEncode(double lon, double lat)
    Encode to a geohash string from full resolution longitude, latitude)
    static final String
    stringEncode(double lon, double lat, int level)
    Encode to a level specific geohash string from full resolution longitude, latitude
    static final String
    stringEncode(long geoHashLong)
    Encode to a geohash string from the geohash based long format
    static Rectangle
    Computes the bounding box coordinates from a given geohash
    static Point
    toPoint(String geohash)
    Returns a Point instance from a geohash string

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PRECISION

      public static final int PRECISION
      maximum precision for geohash strings
      See Also:
  • Method Details

    • toPoint

      public static Point toPoint(String geohash) throws IllegalArgumentException
      Returns a Point instance from a geohash string
      Throws:
      IllegalArgumentException
    • toBoundingBox

      public static Rectangle toBoundingBox(String geohash)
      Computes the bounding box coordinates from a given geohash
      Parameters:
      geohash - Geohash of the defined cell
      Returns:
      GeoRect rectangle defining the bounding box
    • getSubGeohashes

      public static String[] getSubGeohashes(String baseGeohash)
      Array of geohashes one level below the baseGeohash. Sorted.
    • getNeighbors

      public static Collection<? extends CharSequence> getNeighbors(String geohash)
      Calculate all neighbors of a given geohash cell.
      Parameters:
      geohash - Geohash of the defined cell
      Returns:
      geohashes of all neighbor cells
    • addNeighbors

      public static final <E extends Collection<? super String>> E addNeighbors(String geohash, E neighbors)
      Add all geohashes of the cells next to a given geohash to a list.
      Parameters:
      geohash - Geohash of a specified cell
      neighbors - list to add the neighbors to
      Returns:
      the given list
    • addNeighborsAtLevel

      public static final <E extends Collection<? super String>> E addNeighborsAtLevel(String geohash, int level, E neighbors)
      Add all geohashes of the cells next to a given geohash to a list.
      Parameters:
      geohash - Geohash of a specified cell
      level - level of the given geohash
      neighbors - list to add the neighbors to
      Returns:
      the given list
    • getNeighbor

      public static final String getNeighbor(String geohash, int level, int dx, int dy)
      Calculate the geohash of a neighbor of a geohash
      Parameters:
      geohash - the geohash of a cell
      level - level of the geohash
      dx - delta of the first grid coordinate (must be -1, 0 or +1)
      dy - delta of the second grid coordinate (must be -1, 0 or +1)
      Returns:
      geohash of the defined cell
    • longEncode

      public static final long longEncode(String hash)
      Encode a string geohash to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
    • longEncode

      public static final long longEncode(double lon, double lat, int level)
      Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
    • stringEncode

      public static final String stringEncode(double lon, double lat)
      Encode to a geohash string from full resolution longitude, latitude)
    • stringEncode

      public static final String stringEncode(double lon, double lat, int level)
      Encode to a level specific geohash string from full resolution longitude, latitude
    • stringEncode

      public static final String stringEncode(long geoHashLong)
      Encode to a geohash string from the geohash based long format
    • mortonEncode

      public static long mortonEncode(String hash)
      Encode to a morton long value from a given geohash string
    • lonWidthInDegrees

      public static double lonWidthInDegrees(int precision)
      approximate width of geohash tile for a specific precision in degrees
    • latHeightInDegrees

      public static double latHeightInDegrees(int precision)
      approximate height of geohash tile for a specific precision in degrees
    • encodeLatitude

      public static int encodeLatitude(double latitude)
      encode latitude to integer
    • encodeLongitude

      public static int encodeLongitude(double longitude)
      encode longitude to integer
    • decodeLatitude

      public static final double decodeLatitude(String geohash)
      returns the latitude value from the string based geohash
    • decodeLongitude

      public static final double decodeLongitude(String geohash)
      returns the latitude value from the string based geohash
    • decodeLongitude

      public static double decodeLongitude(long hash)
      decode longitude value from morton encoded geo point
    • decodeLatitude

      public static double decodeLatitude(long hash)
      decode latitude value from morton encoded geo point