Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created September 4, 2012 11:01
Show Gist options
  • Save javisantana/3620152 to your computer and use it in GitHub Desktop.
Save javisantana/3620152 to your computer and use it in GitHub Desktop.
grid postgis query
"WITH hgrid AS (SELECT CDB_HexagonGrid(ST_Expand(CDB_XYZ_Extent({x},{y},{z}), CDB_XYZ_Resolution({z}) * 15), CDB_XYZ_Resolution({z}) * 15) as cell) SELECT hgrid.cell as the_geom_webmercator, 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