Skip to content

Instantly share code, notes, and snippets.

@andy-esch
Last active August 29, 2015 14:14
Show Gist options
  • Save andy-esch/0766a904158b032f981d to your computer and use it in GitHub Desktop.
Save andy-esch/0766a904158b032f981d to your computer and use it in GitHub Desktop.
make a checkerboard from an appropriately-sized table
-- By using a table with 4^zoom rows, the following sql statement produces a checkboard
-- The following config works for making a checkerboard with zoom = 3 (4^3 = 64 rows)
WITH
vars AS (SELECT 3 AS zoom)
SELECT
(8 * ss.c1 + ss.c2 = ss.cartodb_id) as tf,
ss.c1,
ss.c2,
ss.cartodb_id as cartodb_id,
CASE
WHEN
ss.cartodb_id % 2 = 0 AND ss.c1 % 2 = 0
THEN
CDB_XYZ_Extent(c1,c2,vars.zoom)
WHEN
ss.cartodb_id % 2 = 1 AND ss.c1 % 2 = 1
THEN
CDB_XYZ_Extent(c1,c2,vars.zoom)
ELSE
null
END AS the_geom_webmercator
FROM (
SELECT
floor((cartodb_id-1) / (1 << vars.zoom))::int as c1,
(cartodb_id % (1 << vars.zoom))::int as c2,
cartodb_id
from for_loops, vars) as ss, vars
ORDER BY c1, c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment