Download - Geohash in mapping applications
![Page 1: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/1.jpg)
www.ciklum.net
Geohash in mapping applications
December, 2011
Igor Luzhanov
![Page 2: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/2.jpg)
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) { ...
}
![Page 3: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/3.jpg)
Common approach
www.ciklum.net 3
![Page 4: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/4.jpg)
Common approach problems
www.ciklum.net 4
![Page 5: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/5.jpg)
Solution - Geohash
46.4845830 N, 30.7326000 E = u8mb7q6b36r6x
Invented by Gustavo Niemeyer, 2008, public domain
www.ciklum.net 5
![Page 6: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/6.jpg)
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
![Page 7: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/7.jpg)
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
![Page 8: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/8.jpg)
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
![Page 9: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/9.jpg)
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)
![Page 10: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/10.jpg)
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
![Page 11: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/11.jpg)
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
![Page 12: Geohash in mapping applications](https://reader033.vdocuments.site/reader033/viewer/2022052900/555c790ed8b42adc358b4bb9/html5/thumbnails/12.jpg)
Thank you!
?
www.ciklum.net 12