Geohash (geohash)
Description
This operation can be used to:
Transform latitude/longitude (sexagesimal) geocoordinate values of geocoord data type (for example 40°24'46.3"N 3°41'43.8"W) into geohash geocoordinate values (for example ezjmguvj). In this case, you can also adjust the number of characters of the output geohashes.
Convert geohash geocoordinate values of string data type (for example ezjmguvj) into geocoord data type.Â
In both cases, the output is of geocoord data type.
Learn more about geocoords and their types in the Geocoord (geocoord)Â article.
How does it work in the search window?
Select Create column in the search window toolbar, then select the Geohash operation.Â
Argument | Description | Data type |
---|---|---|
Geocoord / Geocoord string mandatory | Choose the field containing the input geocoordinate values. As explained above, you can select either a set of coordinate values of geocoord data type or a set of strings representing geohashes. Note that if you choose a field containing string values, they must be strings representing valid geohashes. The operation will not transform input strings representing latitude/longitude geocoordinate values into geocoord data type automatically. To do that, you must use the Geocoord (geocoord) operation. | geocoord / string |
Size | You can only use this argument if you select a set of geocoord data type coordinates in the first argument. Specify the length of the output geohashes in characters. If not specified, the default length is 8 characters. | integer |
The data type of the new column containing the geohash is geocoord.
Example 1
In the demo.ecommerce.data
table, we created a column called geocoord that contains the latitude/longitude geocoordinate values of a given set of IP addresses.
This was created by using the Geolocated Latitude (mmlatitude) and Geolocated Longitude (mmlongitude) operations to get the latitude and longitude of each IP address, then using the Latitude and longitude coordinates (latlon) operation to combine them into sexagesimal coordinate values of data type geocoord.Â
We want to transform these sexagesimal coordinates into geohashes with a length of 6 characters. To do it, click Create column and select the Geohash operation. Select the geocoord column as the Geocoord argument. Add a second argument, Size, and enter 6.
The result is a column containing geohash values in the geocoord data type.
Example 2
This example uses values in a data table generated from the following CSV file.
If you want to try the example by yourself, download the file and upload it to your domain by clicking Data upload in the navigation pane. Name the new table my.upload.geolocation.data and select Current date as Date parsing type. Learn more about uploading data in Uploading log files.
After receiving the confirmation message, you can access the table from the finder, selecting my → upload → geolocation → data. When you upload data from a file, all the information is included in a single column called message. To split the values into different columns, you can use the Split (split) operation. Click Query code editor in the search window toolbar and paste the following LINQ query to save time:
from my.upload.geolocation.data
select split(message, ";", 1) as geohash_strings
Our geohash_strings column contains strings representing different geocoords. We want to get the type of these geocoords in a new column.
Click Create column and select the Geohash operation. Then, select geohash_strings as the Geocoord string argument and click Create Column.
The result is a new column (geohash) containing the same geohash strings but with the geocoord data type.
How does it work in LINQ?
Use the operator select
... as
... and add the operation syntax to create the new column. These are the valid formats of the Geohash operation:
geohash(geocoord)
geohash(geocoord, int)
geohash(string)
Example 1
Copy the following LINQ script and try the above example on the demo.ecommerce.data
 table.Â
from demo.ecommerce.data
select mmlatitude(clientIpAddress) as latitude,
mmlongitude(clientIpAddress) as longitude,
latlon(latitude, longitude) as geocoord,
geohash(geocoord, 6) as geohash
Example 2
Note that you must have uploaded the following CSV file to your Devo domain as explained above to try out this example.
Copy the following LINQ script and try the above example on the my.upload.geolocation.data
 table.Â
from my.upload.geolocation.data
select split(message, ";", 1) as geohash_strings
select geohash(geogash_strings) as geohash