Allow different views based on number of steps

This commit is contained in:
Raul Ochoa 2014-11-24 16:34:37 +01:00
parent 82bbe84c12
commit 02a23d4364

View File

@ -12,12 +12,12 @@ WITH par AS (
SELECT CDB_XYZ_Resolution({zoom})*{resolution} as res, innerpar.resinv as resinv, start, step FROM innerpar, bounds
)
select
floor(st_x(i.{gcol})*resinv) as xx,
floor(st_y(i.{gcol})*resinv) as yy
floor(st_x(i.{gcol})*resinv)::int as x,
floor(st_y(i.{gcol})*resinv)::int as y
, {countby} c
, floor(({column_conv} - start)/step) d
, floor(({column_conv} - start)/step)::int d
FROM ({_sql}) i, par p
GROUP BY xx, yy, d
GROUP BY x, y, d
"""
@ -29,22 +29,28 @@ if len(sys.argv) != 6:
sys.exit()
zoom = int(sys.argv[1])
steps = int(sys.argv[4])
table = sys.argv[5]
for x in xrange(zoom + 1):
zoom_name = '%s_torque_zoom_%d' % (table, x)
mat = "DROP MATERIALIZED VIEW IF EXISTS %s ;\n" % zoom_name
mat += "create materialized view %s as " % zoom_name
view_steps_zoom_name = '%s_torque_zoom_%d_%d' % (table, steps, x)
mat = "DROP MATERIALIZED VIEW IF EXISTS %s;\n" % view_steps_zoom_name
mat += "CREATE MATERIALIZED VIEW %s as " % view_steps_zoom_name
mat += tile_sql.format(
zoom=x,
resolution=int(sys.argv[2]),
gcol='the_geom_webmercator',
column_conv=sys.argv[3],
steps=int(sys.argv[4]),
steps=steps,
_sql='select * from %s' % table,
countby='count(cartodb_id)'
)
mat += ";"
mat += '''
GRANT SELECT ON {zoom_name} TO tileuser;
GRANT SELECT ON {zoom_name} TO publicuser;
'''.format(zoom_name=view_steps_zoom_name)
print mat