Geohash in mapping applications
-
Upload
alex-tumanoff -
Category
Technology
-
view
1.455 -
download
1
description
Transcript of Geohash in mapping applications
www.ciklum.net
Geohash in mapping applications
December, 2011
Igor Luzhanov
Points selection task
Mapping application with brazillions of points
Need to select points in some rectangle
Common approach:
www.ciklum.net 2
if (point.lat > bounds.S && point.lat < bounds.N && point.lon > bounds.W && point.lon < bounds.E) { ...
}
Common approach
www.ciklum.net 3
Common approach problems
www.ciklum.net 4
Solution - Geohash
46.4845830 N, 30.7326000 E = u8mb7q6b36r6x
Invented by Gustavo Niemeyer, 2008, public domain
www.ciklum.net 5
How it works 1/2
Example: decoding from base 32 for ezs42
Base-32 binary
ezs42 0110111111110000010000010
Even – longitude, odd – latitude (start from 0, left to right)
lon = 0111110000000
lat = 101111001001
www.ciklum.net 6
How it works 2/2 Latitude = 101111001001 (~42.6 °)
All latitude range: from [+90°, -90°], middle = 0°
First bit = 1, so select upper interval: [+90°, 0°], middle =
45°
Continue for all bits, getting more detailed range
Geohash define box, not point!
www.ciklum.net 7
How you can use it – 1D In rectangular area (except "faultlines") points placed on
contiguous slices
Points can be requested by single parameter:
www.ciklum.net 8
SELECT * FROM myPoints WHERE
geohash >= u85 AND
geohash <= u8x
How you can use it – 2D
Save all slices for point in DB (u, u8, u8m, u8mb… etc)
Detect all visible top-level slices
Make a query:
www.ciklum.net 9
SELECT p FROM PointEntity p
JOIN p.slices s
WHERE s IN (:boundSlices)
Limitations Geohash define box, not point! Close points can have
different geohashes
1D queries return incorrect results near “faultlines”.
Solution – subqueries.
Close points not always have
common prefix
www.ciklum.net 10
Java implementations
javageomodel - http://code.google.com/p/javageomodel
geospatialweb - http://code.google.com/p/geospatialweb/
geohash-java - https://github.com/kungfoo/geohash-java
jGeohash - http://sourceforge.net/projects/jgeohash
www.ciklum.net 11
Thank you!
?
www.ciklum.net 12