Class GeoHash

  • All Implemented Interfaces:
    java.io.Serializable

    public class GeoHash
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String base32  
      protected long bitsValue  
      protected short numberOfBits  
    • Constructor Summary

      Constructors 
      Constructor Description
      GeoHash()  
      GeoHash​(double longitude, double latitude, int hashLength)  
    • Field Detail

      • bitsValue

        protected long bitsValue
      • numberOfBits

        protected short numberOfBits
    • Constructor Detail

      • GeoHash

        public GeoHash()
      • GeoHash

        public GeoHash​(double longitude,
                       double latitude,
                       int hashLength)
    • Method Detail

      • geohash

        public static GeoHash geohash​(double longitude,
                                      double latitude,
                                      int hashLength)
        GeoHash from longitude, latitude with number of characters = hashLength
        Parameters:
        longitude - longitude of the point
        latitude - latitude of the point
        hashLength - precision of geohash in number of characters
        Returns:
        GeoHash of the point
      • geohashWithBitsLength

        public static GeoHash geohashWithBitsLength​(double longitude,
                                                    double latitude,
                                                    int numberOfBits)
        GeoHash from longitude, latitude with number of bits = numberOfBits numberOfBits must be a multiple of 5
        Parameters:
        longitude - longitude of the point
        latitude - latitude of the point
        numberOfBits - precision of geohash in number of bits
        Returns:
        GeoHash of the point
      • geohash

        public static GeoHash geohash​(java.lang.String bitString)
        GeoHash from a bit string the length of the string must be a multiple of 5
        Parameters:
        bitString - bit string
        Returns:
        GeoHash of the string
      • geohash

        public static GeoHash geohash​(long value,
                                      int hashLength)
        GeoHash corresponding to the long value
        Parameters:
        value - value
        hashLength - precision of the geohash in number of characters
        Returns:
        GeoHash of the value
      • geohashFromString

        public static GeoHash geohashFromString​(java.lang.String base32String)
        GeoHash from a string (base 32)
        Parameters:
        base32String - base32 string
        Returns:
        GeoHash of the string
      • geohashBits

        public static int[] geohashBits​(double longitude,
                                        double latitude,
                                        int numBits)
      • getGeoHashString

        public java.lang.String getGeoHashString()
        Getter for geohash string
      • getMer

        public double[] getMer()
        Getter for mer
      • getNumberOfBits

        public short getNumberOfBits()
        Getter for the number of bits in the geohash bit string
      • getDecimalValue

        public long getDecimalValue()
        Getter for the numeric value of the geohash
      • getCenterPoint

        public JPoint2DD getCenterPoint()
        Computes the center point of the geohash mer
        Returns:
        JPoint2DD point
      • getValue

        public long getValue()
      • toBinaryString

        public java.lang.String toBinaryString()
        Computes an equivalent bit string representation of the geohash
        Returns:
        a bit string
      • next

        public GeoHash next​(int numberOfSteps)
        Finds the geohash removed by a given number of steps from this.
        Parameters:
        numberOfSteps - number of steps to be moved
        Returns:
        GeoHash
      • next

        public GeoHash next()
        Finds the next geohash.
        Returns:
        GeoHash
      • prev

        public GeoHash prev()
        Finds the previous geohash
        Returns:
        GeoHash
      • asMer

        public static double[] asMer​(java.lang.String geohash)
        Finds the mer corresponding to a geohash
        Returns:
        mer array
      • numberOfStepsBetween

        public static long numberOfStepsBetween​(GeoHash gh1,
                                                GeoHash gh2)
      • getGeoHashToTheNorth

        public GeoHash getGeoHashToTheNorth()
        Finds the geohash to the north of this.
        Returns:
        GeoHash
      • getGeoHashToTheEast

        public GeoHash getGeoHashToTheEast()
        Finds the geohash to the east of this.
        Returns:
        GeoHash
      • getGeoHashToTheSouth

        public GeoHash getGeoHashToTheSouth()
        Finds the geohash to the south of this
        Returns:
        GeoHash
      • getGeoHashToTheWest

        public GeoHash getGeoHashToTheWest()
        Finds the geohash to the west of this
        Returns:
        GeoHash
      • getEightNeighbors

        public GeoHash[] getEightNeighbors()
        Finds the eight neighbors of this
        Returns:
        an array of GeoHash in the order N, NE, E, SE, S, SW, W, NW
      • within

        public boolean within​(GeoHash gh)
        Checks whether the mer of the given geohash is inside the mer of this
        Parameters:
        gh - geohash to be checked
      • within

        public boolean within​(JPoint2DD point)
        Checks whether the given point is inside the mer of this.
        Parameters:
        point - point to be checked
        Returns:
        true if the point is inside mer
      • decimalValue

        public static long decimalValue​(java.lang.String ghString)
        Computes the numeric value of a geohash string
        Parameters:
        ghString - base32 geohash string
        Returns:
        decimal value
      • geohashString

        public java.lang.String geohashString​(double longitude,
                                              double latitude,
                                              int hashLength)