Skip to content

Instantly share code, notes, and snippets.

@strk
Forked from javisantana/query.sql
Created September 4, 2012 11:10
Show Gist options
  • Save strk/3620249 to your computer and use it in GitHub Desktop.
Save strk/3620249 to your computer and use it in GitHub Desktop.
grid postgis query
WITH
hgrid AS (
SELECT CDB_HexagonGrid(
ST_Transform(ST_MakeEnvelope(-180, -89, 180, 89, 4326), 3857), -- extent of the grid
CDB_XYZ_Resolution({z}) * 15 -- size of each cell
) as cell
)
SELECT count(i.<%=prop%>) as points_count
FROM hgrid, <%= table_name %> i
where ST_Intersects(i.the_geom_webmercator, hgrid.cell) GROUP BY hgrid.cell;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment