Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Geohash encoding and decoding
ResourceFunction["GeoHash"][lat,lon] finds the geohash for the geo location with coordinates lat and lon. | |
ResourceFunction["GeoHash"][GeoPosition[lat,lon]] finds the geohash of a geo position. | |
ResourceFunction["GeoHash"][geoHash] decodes the given geoHash into a geo position. | |
ResourceFunction["GeoHash"][geoHash,fmt] give the decoded result in the form fmt. |
Encode a given geo position:
In[1]:= |
Out[1]= |
Decode:
In[2]:= |
Out[2]= |
By default the decoding gives the mean point of the corresponding geo rectangle as a GeoPosition object:
In[3]:= |
Out[3]= |
If Mean is given a second argument then the mean point of the corresponding geo rectangle is returned:
In[4]:= |
Out[4]= |
Using Association as a second argument gives the geo rectangle coordinates in a nested association:
In[5]:= |
Out[5]= |
Often it is convenient to get the decoding result as a list of min-min and max-max geo positions of the corresponding geo rectangle:
In[6]:= |
Out[6]= |
Visualize the boundary of the result above:
In[7]:= |
Out[7]= |
If the first argument is a valid geohash string and the second argument is "Neighbors" then a list of neighboring geohashes is returned:
In[8]:= |
Out[4]= |
Here is a corresponding geo plot:
In[9]:= |
Out[9]= |
If the first argument is "Alphabet" then the Geohash encoding alphabet is returned:
In[10]:= |
Out[10]= |
Precision is used to confine the given location into into geo rectangle with an universal identifier (i.e. the geohash). Here are geohashes of the same geo point with different precisions:
In[11]:= |
Out[4]= |
Here are maps with the corresponding bounding regions:
In[12]:= |
Out[12]= |
Find nearest neighbors of a geohash at different precision levels:
In[13]:= |
Out[4]= |
Here is a corresponding Geographics plot:
In[14]:= |
Out[14]= |
Get all cities in Illinois, USA:
In[15]:= |
Out[4]= |
Make an association of the city names to corresponding coordinates:
In[16]:= |
Out[6]= |
Compute geohashes for all cities:
In[17]:= |
Out[17]= |
Find the geo coordinates of a certain focus location:
In[18]:= |
Out[18]= |
Find the corresponding geohash:
In[19]:= |
Out[19]= |
Find the Nearest Neighbors (NNs) of the location by matching a prefix of the focus location geohash in the association of Illinois-geohashes:
In[20]:= |
Out[21]= |
Plot the focus location and the found NNs:
In[22]:= |
Out[22]= |
Using a shorter prefix produces more NNs:
In[23]:= |
Out[24]= |
The geohashes represent nested rectangles -- adding a new "legal" alphabet character to geohash produces nested rectangles of finer granularity:
In[25]:= |
Out[4]= |
Here is another illustration of the geohash nesting -- the core geohash is extended with all characters of the alphabet twice:
In[26]:= |
Out[6]= |
Geohashes with an even number of digits result in a regular grid. Those with an odd number of digits result in an irregular intermediary grid.
The system can be used for proximity searches, but limitations exist. Locations close but on either side of the equator or Greenwich meridian will not have a shared prefix. The proximity search also breaks down at the 180 - degree meridians and the poles.
Here is how Rectangle and RegionMember can be used to verify that a geo position point belongs to the geo rectangle given by GeoHash:
In[27]:= |
Out[6]= |
Not every ASCII string is a valid geohash. Here are the characters not used for GeoHash encoding:
In[28]:= |
Out[28]= |
Visualize the Z-filling curve that corresponds to found hashes:
In[29]:= |
Out[22]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License