Upcoming SlideShare
×

# Geohash in mapping applications

2,330 views

Published on

Geohash in mapping applications by Igor Luzhanov

Published in: Technology
3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
2,330
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
20
0
Likes
3
Embeds 0
No embeds

No notes for slide

### Geohash in mapping applications

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