Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: Databricks Runtime 17.1 and above
Important
This feature is in Public Preview.
Returns the geohash of the input geometry at the given precision. If the precision is not specified, the expression behaves as if the precision specified was -1.
Syntax
st_geohash ( geo [, precision] )
Arguments
geo
: AGEOMETRY
value.precision
: The optional precision (number of significant digits) of the output geohash.
Returns
A value of type STRING
, representing the geohash of the input geometry.
More precisely:
- If the input geometry is empty, the expression returns
NULL
. - If the precision is 0, the empty string is returned.
- If the precision is positive, the expression returns the geohash value of the center of the bounding box of the geometry at the specified precision.
- If the precision is negative, the expression returns the geohash value that corresponds to the geohash grid bucket of maximum precision (but not more than 12) that fully covers the bounding box of the input geometry. If such a geohash grid bucket does not exist, the empty string is returned.
See Wikipedia for more details on geohashes.
The function returns NULL
if the input is NULL
.
Error conditions
- If the input contains longitude coordinates outside the [-180, 180] range, the function returns ST_INVALID_ARGUMENT.
- If the input contains latitude coordinates outside the [-90, 90] range, the function returns ST_INVALID_ARGUMENT.
Examples
-- Returns the geohash of a point at default precision.
> SELECT st_geohash(st_geomfromtext('POINT(-122.4261475 37.77374268)'))
9q8yyhebpbpb
-- Returns the geohash of a point at precision 6.
> SELECT st_geohash(st_geomfromtext('POINT(-122.4261475 37.77374268)'), 6)
9q8yyh
-- Returns the geohash of a linestring at default precision.
> SELECT st_geohash(st_geomfromtext('LINESTRING(-122.43 37.77,-122.42 37.78)'))
9q8yy
-- Returns the geohash of a linestring at precision 9.
> SELECT st_geohash(st_geomfromtext('LINESTRING(-122.43 37.77,-122.42 37.78)'), 9)
9q8yyhsz6
-- Returns empty string for a large geometry that doesn't fit in any geohash bucket.
> SELECT length(st_geohash(st_geomfromtext('LINESTRING(0 0,60 60)')))
0