Description
The ST_SquareHash
function takes a longitude, latitude (in WGS 84) and a
precision. The precision determines how large the grid cells are (higher precision means
smaller grid cells). It returns the string ID of the grid cell at the specified precision
that contains the point. Square hash cells appear square when displayed on a Popular
Mercator map.
Syntax
ST_SquareHash(Number|String X, Number|String Y, Number precision)
Parameters
Parameter |
Type |
Description |
X
|
Number or String |
The longitude value of the point. |
Y
|
Number or String |
The latitude value of the point. |
precision
|
Number |
The length of the string key to be returned. The precision determines how large
the grid cells are (longer strings means higher precision and smaller grid
cells). |
Return Values
Return Type |
Description |
String |
The ID of the grid cell at the specified precision that contains the
point. |
Examples
SELECT ST_SquareHash(x, y, precision) FROM table;
SELECT ST_SquareHash("-73.750333", "42.736103", 3);
SELECT ST_SquareHash(-73.750333, 42.736103, 3);
CREATE TEMPORARY TABLE tmptbl AS
SELECT *, (ST_SquareHash(x, y, 10)) AS hashID
FROM coordinates ORDER BY hashID;
INSERT INTO TABLE coordinates_with_hash
SELECT *, (ST_SquareHash(x, y, 10)) AS hashID
FROM coordinates ORDER BY hashID;
SELECT c.hashID, ST_ToWKT(ST_SquareHashBoundary(c.hashID)),
count (*) AS quantity FROM (SELECT ST_SquareHash(x, y, 10)
AS hashID FROM coordinates)
c GROUP BY c.hashID;