Polygeohasher: an optimized way to create geo-hashes
By: Krishna Khadka
Tags: Geospatial Intelligence, Geospatial Analytics, Maps, Geohash, Geospatial

1. What is geohash?

Geohash is the encoding technique used to convert geoareas into base-32 alphabet encoding (characters can be 0 to 9 and a to z, excluding ‘a’, ‘i’, ‘l’, and ‘o’). the size of the geohash polygon depends upon the geohash level i.e. 1 to 12.

2. How geohash mapping is done?

The geohash level 1 divides the world into 32 parts and each part/cell is defined by the string of length1. While in geohash level-2 each geohash level-1 cell is divided further into 32 cells, each defined by the string of length 2 and so on. Therefore, the number of letters /alphabets in the string represents the level if geohash.

As shown in the figure the world is divided into 32 geohashes of level-1 having an area of 5000x5000 kmsq. and if we go to geohash level 2 the cells are further divided into 32 parts each of area 1250x625 kmsq. level-3 geohashing will make cells with an area of 156x156 kmsq. Therefore as the geohash level increases, the area decreases, hence precision increases.

3. How creating geohash can be beneficial?

A geohash is a string representation of a particular geo-polygon that is easy to remember and use, as compared to keeping track of longitudes and latitudes or points or the polygons.

Proximity searches: discover the nearby locations and places of interest, number of restaurants or malls established in a particular region.

Social Networking: dating apps to find matches within a particular area, number of people using applications in a particular cell.

4. What is the need of optimizing the geohashing Technique?

Only one type of geohash division for an area is not advantageous as that approach will have some issues:

Suppose we have the geometry of the city represented by four polygons joined together. Now, we want to create geohashes for the city.

While creating the geohash we have to choose a level that will divide the polygon into further cells according to the need.

Consider we choose a low precision geohash with respect to area i.e. geohash level-5 and in this case, the number of geohashes will be less and the area of each cell will be 4.89x4.89 kmsq.

The disadvantage of using this geohash level is that the area outside the boundary is also being added to the polygon although that is not the part of the city.

To overcome the issue of inclusion of the outer boundary areas, we can choose the high precision geohash level i.e. level-6. In this case, the area of each cell will be 1.22x0.61 kmsq.

The disadvantage of using this geohash level is that the no. of polygons increased by more than 30 folds which results in high computation and processing time.

What could be the solution?

Here appears the use of an optimized way to create geohash i.e. using the combination of two or more geohashes according to requirement.

So, the division of polygon into two geohash levels i.e. level-5 and level-6 result in a 67% reduction of the number of polygons as compared to geohash level-6.

Hence using this optimized geohash division approach we can reduce the number of cells and the outer boundary area issue is also resolved.

5. How polygeohasher can be used as an optimized way to create geohash?

polygeohasher is PyPi registered library that can be installed through pip or can be downloaded from this link.

1.import the polygeohasher and load the geojson file of the city/area.

2. create a geohash layer of maximum precision as the primary dataframe.

inner=False indicates we are taking values outside of the boundaries, if True only polygons lying inside are considered.

3. create an optimized geohash dataframe by passing parameters: primart_dataframe, maximum_geohash_level, minimum_geohash_level, input_geohash_level.

4. calculate the optimization summary

5. save the new geojson file.

End Notes:

The PyPI project is available at https://pypi.org/project/polygeohasher/

The Github repository https://github.com/rohitsinghsalyan/polygeohasher

if you like this article, please like and share, and star the repository on Github.