Class SpatialKeyAlgo

java.lang.Object
com.graphhopper.geohash.SpatialKeyAlgo

public class SpatialKeyAlgo extends Object
This class implements the idea of a geohash but without a string representation - to avoid confusion, this is called 'spatial key'. Detailed information is available in this blog post: http://karussell.wordpress.com/2012/05/23/spatial-keys-memory-efficient-geohashes/

The hash can be used as a key for hash tables. When you organize the grid as a quad tree, it resembles the path down the tree to reach the cell that it encodes. That's how it is used in LocationIndexTree.

A 32 bit representation has a precision of approx 600 meters = 40000/2^16

Implementation: - From the query point and the grid parameters, calculate (integer) coordinates (x,y) of the cell the query point is in, using simple arithmetics. - Use a lookup table to interleave the bits of (x,y) to get the cell number, which is the spatial key. See the drawing below. This is called a Z-order curve (because of the path you get when you follow increasing cell numbers through the grid), or Morton code.

Author:
Peter Karich, Michael Zilske
  • Constructor Details

    • SpatialKeyAlgo

      public SpatialKeyAlgo(int allBits, BBox bounds)
      Parameters:
      allBits - how many bits should be used for the spatial key when encoding/decoding
  • Method Details

    • getBits

      public int getBits()
      Returns:
      the number of involved bits
    • encodeLatLon

      public final long encodeLatLon(double lat, double lon)
    • y

      public int y(double lat)
    • x

      public int x(double lon)
    • encode

      public long encode(int x, int y)
    • decode

      public int[] decode(long z)
    • up

      public long up(long z)
    • down

      public long down(long z)
    • right

      public long right(long z)
    • left

      public long left(long z)