public class SpatialKeyAlgo extends Object implements KeyAlgo
lat0 lon0 | lat1 lon1 | lat2 lon2
This works similar to how BIG endianness works for bytes to int packing. Detailed information is available in this blog post: http://karussell.wordpress.com/2012/05/23/spatial-keys-memory-efficient-geohashes/
The bits are usable as key for hash tables like our SpatialKeyHashtable or for a spatial tree like QuadTreeSimple. Also the binary form makes it relative simple for implementations using this encoding scheme to expand to arbitrary dimension (e.g. shifting n-times if n would be the dimension).
A 32 bit representation has a precision of approx 600 meters = 40000/2^16
There are different possibilities how to handle different precision and order of bits. Either:
lat0 lon0 | lat1 lon1 | lat2 lon2
0 0 | lat0 lon0 | lat1 lon1
as it is done now. Advantage: A single shift is only necessary to make it less precise. Or:
lat2 lon2 | lat1 lon1 | lat0 lon0
0 0 | lat1 lon1 | lat0 lon0
Advantage: the bit mask to get lat0 lon0 is simple: 000..0011 and independent of the precision! But when stored e.g. as int one would need to (left) shift several times if precision is only 3bits.
Constructor and Description |
---|
SpatialKeyAlgo(int allBits) |
Modifier and Type | Method and Description |
---|---|
SpatialKeyAlgo |
bounds(BBox box) |
void |
decode(long spatialKey,
GHPoint latLon)
This method returns latitude and longitude via latLon - calculated from specified spatialKey
|
long |
encode(double lat,
double lon)
Take latitude and longitude as input.
|
long |
encode(GHPoint coord) |
int |
getBits() |
int |
getExactPrecision() |
SpatialKeyAlgo |
setBounds(double minLonInit,
double maxLonInit,
double minLatInit,
double maxLatInit)
Sets the bounds of the underlying key algorithm.
|
protected void |
setWorldBounds() |
String |
toString() |
public SpatialKeyAlgo(int allBits)
allBits
- how many bits should be used for the spatial key when encoding/decodingpublic int getBits()
public int getExactPrecision()
public SpatialKeyAlgo bounds(BBox box)
public SpatialKeyAlgo setBounds(double minLonInit, double maxLonInit, double minLatInit, double maxLatInit)
KeyAlgo
protected void setWorldBounds()
public final long encode(double lat, double lon)
public final void decode(long spatialKey, GHPoint latLon)
Copyright © 2012–2020. All rights reserved.