Geospatial functions

Spatial functions allow for operations relating to the geohash types which provide geospatial data support. For more information on this type of data, see the geohashes documentation and the operators which help with filtering data.

rnd_geohash

rnd_geohash(bits) returns a random geohash of variable precision.

Arguments:

bits - an integer between 1 and 60 which determines the precision of the generated geohash.

Return value:

Returns a geohash

Examples:

SELECT rnd_geohash(7) g7,
rnd_geohash(10) g10,
rnd_geohash(30) g30,
rnd_geohash(29) g29,
rnd_geohash(60) g60
FROM long_sequence(5);
g7g10g30g29g60
11011004hhsmmq801110101011001101111110111011rjtwedd0z72p
0010011vff9jc1q10101111100101111111101101101fzj09w97tj1h
0101011kxfkhked01110110010001001000110001100v4cs8qsnjkeh
000000107qm99sm11001010011011000010101100101hrz9gq171nc5
01010116t3r8jb511011101010111001010010001010fm521tq86j2c

make_geohash

make_geohash(lon, lat, bits) returns a geohash equivalent of latitude and longitude, with precision specified in bits.

make_geohash() is intended to be used via SQL over HTTP / PostgreSQL wire protocol, for use within Java (embedded) scenario, see the Java embedded documentation for geohashes.

Arguments:

  • lon - longitude coordinate as a floating point value with up to eight decimal places
  • lat - latitude coordinate as a floating point value with up to eight decimal places
  • bits - an integer between 1 and 60 which determines the precision of the generated geohash.

The latitude and longitude arguments may be constants, column values or the results of a function which produces them.

Return value:

Returns a geohash.

  • If latitude and longitude comes from constants and is incorrect, an error is thrown
  • If column values have invalid lat / long coordinates, this produces null.

Examples:

SELECT make_geohash(142.89124148, -12.90604153, 40)