public class SpatialKeyAlgo extends Object
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.
Constructor and Description |
---|
SpatialKeyAlgo(int allBits,
BBox bounds) |
Modifier and Type | Method and Description |
---|---|
int[] |
decode(long z) |
long |
down(long z) |
long |
encode(int x,
int y) |
long |
encodeLatLon(double lat,
double lon) |
int |
getBits() |
long |
left(long z) |
long |
right(long z) |
long |
up(long z) |
int |
x(double lon) |
int |
y(double lat) |
public SpatialKeyAlgo(int allBits, BBox bounds)
allBits
- how many bits should be used for the spatial key when encoding/decodingpublic int getBits()
public final long encodeLatLon(double lat, double lon)
public int y(double lat)
public int x(double lon)
public long encode(int x, int y)
public int[] decode(long z)
public long up(long z)
public long down(long z)
public long right(long z)
public long left(long z)
Copyright © 2012–2021. All rights reserved.