solidDB Help : solidDB reference : SQL: Functions : Geohash SQL functions
  
Geohash SQL functions
The following table details the available geohash SQL functions and the matching API calls (where available).
For the functions described, the following rules apply:
Latitude and longitude are floating point numbers (or other numeric values).
Precision is an integer between 1 and 23 (1 is least precise, 23 is most precise).
Geohash is a string of arbitrary length. The longer the string, the more precise the location.
Direction is an integer between 0 and 7 that specifies the direction of an adjacent block by using points of the compass numbered in a clockwise direction. (0 = North, 7 = Northwest).
Scale is an integer between 1 and 100 that indicates the expected granularity of returned geohash blocks. The higher the scale value, the greater the number of blocks that are returned but with a longer response time. There is no exact mapping between the number of returned blocks and the scale value.
 
SQL function
Purpose
Equivalent solidDB API call
GEO_BLOCKLIST(lat1,lon1,lat2,lon2,scale)
Legal scale values are from 1 to 100.
 
Example:
SELECT GEO_BLOCKLIST(59.999,60.001,29.999,30.001,1)
Result: udtm6dk,udtm6dm,udtm6dq,udtm6ds,
udtm6dt,udtm6du,udtm6dv,udtm6dw,udtm6dy
Find the set of geohash blocks that fit inside a boundary that is defined by specified lines of latitude and longitude.
All parameters must be numeric.
Note Depending on the lines of longitude and latitude chosen, the list of blocks can be long. Choose an appropriate scale value to restrict the number of blocks returned.
GEO_BOUNDARY(lat1,lat2,lon1,lon2)
or
GEO_BOUNDARY(lat1,lat2,lon1,lon2,
latexc1,latexc2,lonexc1,lonexc2,)
Used with GEO_INSIDE in the WHERE clause of a SELECT statement.
Examples:
Define a square that is bound by lines of latitude and longitude.
You can provide multiple sequences of four parameters. Subsequent sets of co-ordinates exclude squares within the first set of co-ordinates. Up to five sets of co-ordinates are accepted.
All parameters must be numeric.
None
GEO_DECODE_LATITUDE(geohash)
GEO_DECODE_LATITUDE_HIGH(geohash)
GEO_DECODE_LATITUDE_LOW(geohash)
GEO_DECODE_LONGITUDE(geohash)
GEO_DECODE_LONGITUDE_HIGH(geohash)
GEO_DECODE_LONGITUDE_LOW(geohash)
GEO_DECODE_PRECISION(geohash)
Example:
SELECT GEO_DECODE_LATITUDE('u6ygjbew')
Result: 61.0
Convert a geohash value to coordinates and precision.
The parameter must be a legal geohash value in string format.
GEO_ENCODE(lat,lon,precision)
Example:
SELECT GEO_ENCODE(61.0,21.0,8)
Result: u6ygjbew
Convert co-ordinates to geohash values.
All parameters must be numeric.
GEO_HASHTOBOUNDARY(geohash)
Example:
SELECT GEO_HASHTOBOUNDARY('u6ygjbew')
Result: 0.999870,61.000042,20.999680,
21.000023
Convert a geohash to a boundary that is defined lines of latitude and longitude.
The parameter must be a legal geohash value in string format.
GEO_INSIDE
Used in the WHERE clause of a SELECT statement.
Example:
SELECT * FROM T WHERE GH GEO_INSIDE GEO_BOUNDARY(-50,-40,-43,-40)
Result: 5pf666yc
Find all geohash blocks within a specified boundary that is defined by lines of latitude and longitude.
None
GEO_NEIGHBOR(geohash,direction)
or
GEO_NEIGHBOUR(geohash,direction)
Example:
SELECT GEO_NEIGHBOR('u6ygjbew',1)
Result: u6ygjbez
Find an adjacent geohash block in a given direction.
The parameters must be a legal geohash value in string format and a direction as an integer.
GEO_NEIGHBORS(geohash)
or
GEO_NEIGHBOURS(geohash)
Example:
SELECT GEO_NEIGHBORHOOD('5pf666y7')
Result: 5pf666yw,5pf666y1,5pf666y2,
5pf666yb,5pf666yc,5pf666ye,
5pf666yf,5pf666yg
Find adjacent geohash blocks in all 8 directions.
The parameter must be a legal geohash value in string format.
GEO_NEIGHBORHOODTOBOUNDARY(geohash)
or
GEO_NEIGHBOURHOODTOBOUNDARY(geohash)
Used with GEO_INSIDE in the WHERE clause of a SELECT statement.
Example:
SELECT * FROM T WHERE GH GEO_INSIDE GEO_NEIGHBORHOODTOBOUNDARY('5pf')
Result: 5pf666yc
Find the boundary of the geohash neighborhood (the lines of latitude and longitude that define the edges of the area that contains the geohash and its adjacent neighbors).
The parameter must be a legal geohash value in string format.
Other examples
Store data in database table:
INSERT INTO T (LAT, LON, PREC, GH) VALUES (61.0,21.0,100, GEO_ENCODE(61.0,21.0,8))
Find a block (of given size) from database by using geohash in condition:
SELECT * FROM T WHERE GH = '5pf666y7';
Find all blocks (also of higher precision) that match a geohash condition
SELECT * FROM T WHERE GH LIKE '5pf666y7%'; -- indexed, fast search
Note that column GH should be indexed. All blocks of higher precision are returned by the query.
Retrieve all cities within longitude and latitude limits.
SELECT * FROM CITIES WHERE
    GH GEO_INSIDE GEO_BOUNDARY(50,70,-5,30)
Result:
NAME LONGITUDE LATITUDE GEOHASH
---- --------- -------- -------
London -0.1 51.5 gcpuvxr1
Helsinki 24.9 60.15 ud9wntgx
Tampere 23.7 61.5 udbvg79z
Retrieve all cities within longitude and latitude limits that are not excluded by second set of coordinates.
SELECT * FROM CITIES WHERE
    GEOHASH GEO_INSIDE GEO_BOUNDARY(50,70,-5,30,50,60,-5,5)
Result
NAME LONGITUDE LATITUDE GEOHASH
---- --------- -------- -------
Helsinki 24.9 60.15 ud9wntgx
Tampere 23.7 61.5 udbvg79z
Go up to
SQL: Functions