Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Created November 15, 2012 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/4079180 to your computer and use it in GitHub Desktop.
Save wboykinm/4079180 to your computer and use it in GitHub Desktop.
Hexbins out of PostGIS
var query="WITH hgrid AS (SELECT CDB_HexagonGrid(ST_Expand(CDB_XYZ_Extent({x},{y},{z}),CDB_XYZ_Resolution({z}) * ({z}+1)),CDB_XYZ_Resolution({z}) * ({z}+1) ) as cell) SELECT hgrid.cell as the_geom_webmercator, count(i.cartodb_id) as prop_count FROM hgrid, coverage_oldweather_new_style 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