def worker(zoom_level, tile_row, tile_column): coord = _Coord(tile_row, tile_column, zoom_level) tile = _Tile(tile_size, tile_size, coord) for rts, builder in builders: builder.reset_to_new_tile(tile) cursor.execute('EXECUTE select_data (%s, %s, %s)', (zoom_level, tile_row, tile_column)) for region_type, region_uid, svg in cursor: path = _preprocess_svg_path( svg, builders[0][1]) # all builders have the same params json_id = region_type + '-' + region_uid for rts, builder in builders: if region_type in rts: _add_path_to_builder(path, json_id, builder) utfgrid_objects = [] for rts, builder in builders: utfgrid = builder.get_utfgrid() utfgrid.simplify() if len(utfgrid.keys ) > 1 or utfgrid.keys[0] != '': # if there's a region obj = {'grid': utfgrid.grid, 'keys': utfgrid.keys} if obj not in utfgrid_objects: utfgrid_objects.append(obj) json_str = _dump_json(utfgrid_objects) cursor.execute('EXECUTE insert_processed_data (%s, %s, %s, %s)', (zoom_level, tile_row, tile_column, json_str))
def worker(zoom_level, tile_row, tile_column): coord = _Coord(tile_row, tile_column, zoom_level) tile = _Tile(tile_size, tile_size, coord) for rts, builder in builders: builder.reset_to_new_tile(tile) cursor.execute('EXECUTE select_data (%s, %s, %s)', (zoom_level, tile_row, tile_column)) for region_type, region_uid, svg in cursor: path = _preprocess_svg_path(svg, builders[0][1]) # all builders have the same params json_id = region_type + '-' + region_uid for rts, builder in builders: if region_type in rts: _add_path_to_builder(path, json_id, builder) utfgrid_objects = [] for rts, builder in builders: utfgrid = builder.get_utfgrid() utfgrid.simplify() if len(utfgrid.keys) > 1 or utfgrid.keys[0] != '': # if there's a region obj = { 'grid': utfgrid.grid, 'keys': utfgrid.keys } if obj not in utfgrid_objects: utfgrid_objects.append(obj) json_str = _dump_json(utfgrid_objects) cursor.execute('EXECUTE insert_processed_data (%s, %s, %s, %s)', (zoom_level, tile_row, tile_column , json_str))
def create_worker(db, tile_size): cursor = db.cursor() cursor.execute(''' PREPARE select_data (INT, INT, INT) AS SELECT r.type, r.uid, ST_AsSVG(ST_Collect(rpt.geometry_srid3857)) AS svg FROM region_polygon_tiles rpt INNER JOIN region_polygons_metadata rpm ON rpt.region_polygon_id = rpm.region_polygon_id INNER JOIN regions r ON rpm.region_id = r.id WHERE rpt.zoom_level = $1 AND rpt.tile_row = $2 AND rpt.tile_column = $3 GROUP BY r.type, r.uid, r.position ORDER BY r.position ''') cursor.execute(''' PREPARE insert_processed_data (INT, INT, INT, TEXT) AS INSERT INTO utfgrids (zoom_level, tile_row, tile_column, utfgrids) VALUES ($1, $2, $3, $4) ''') region_type_sets = _get_region_type_sets() coord = _Coord(0, 0, 0) tile = _Tile(tile_size, tile_size, coord) builders = [(rts, _UTFGridBuilder(tile)) for rts in region_type_sets] def worker(zoom_level, tile_row, tile_column): coord = _Coord(tile_row, tile_column, zoom_level) tile = _Tile(tile_size, tile_size, coord) for rts, builder in builders: builder.reset_to_new_tile(tile) cursor.execute('EXECUTE select_data (%s, %s, %s)', (zoom_level, tile_row, tile_column)) for region_type, region_uid, svg in cursor: path = _preprocess_svg_path( svg, builders[0][1]) # all builders have the same params json_id = region_type + '-' + region_uid for rts, builder in builders: if region_type in rts: _add_path_to_builder(path, json_id, builder) utfgrid_objects = [] for rts, builder in builders: utfgrid = builder.get_utfgrid() utfgrid.simplify() if len(utfgrid.keys ) > 1 or utfgrid.keys[0] != '': # if there's a region obj = {'grid': utfgrid.grid, 'keys': utfgrid.keys} if obj not in utfgrid_objects: utfgrid_objects.append(obj) json_str = _dump_json(utfgrid_objects) cursor.execute('EXECUTE insert_processed_data (%s, %s, %s, %s)', (zoom_level, tile_row, tile_column, json_str)) return worker
def create_worker(db, tile_size): cursor = db.cursor() cursor.execute(''' PREPARE select_data (INT, INT, INT) AS SELECT r.type, r.uid, ST_AsSVG(ST_Collect(rpt.geometry_srid3857)) AS svg FROM region_polygon_tiles rpt INNER JOIN region_polygons_metadata rpm ON rpt.region_polygon_id = rpm.region_polygon_id INNER JOIN regions r ON rpm.region_id = r.id WHERE rpt.zoom_level = $1 AND rpt.tile_row = $2 AND rpt.tile_column = $3 GROUP BY r.type, r.uid, r.position ORDER BY r.position ''') cursor.execute(''' PREPARE insert_processed_data (INT, INT, INT, TEXT) AS INSERT INTO utfgrids (zoom_level, tile_row, tile_column, utfgrids) VALUES ($1, $2, $3, $4) ''') region_type_sets = _get_region_type_sets() coord = _Coord(0, 0, 0) tile = _Tile(tile_size, tile_size, coord) builders = [ ( rts, _UTFGridBuilder(tile) ) for rts in region_type_sets ] def worker(zoom_level, tile_row, tile_column): coord = _Coord(tile_row, tile_column, zoom_level) tile = _Tile(tile_size, tile_size, coord) for rts, builder in builders: builder.reset_to_new_tile(tile) cursor.execute('EXECUTE select_data (%s, %s, %s)', (zoom_level, tile_row, tile_column)) for region_type, region_uid, svg in cursor: path = _preprocess_svg_path(svg, builders[0][1]) # all builders have the same params json_id = region_type + '-' + region_uid for rts, builder in builders: if region_type in rts: _add_path_to_builder(path, json_id, builder) utfgrid_objects = [] for rts, builder in builders: utfgrid = builder.get_utfgrid() utfgrid.simplify() if len(utfgrid.keys) > 1 or utfgrid.keys[0] != '': # if there's a region obj = { 'grid': utfgrid.grid, 'keys': utfgrid.keys } if obj not in utfgrid_objects: utfgrid_objects.append(obj) json_str = _dump_json(utfgrid_objects) cursor.execute('EXECUTE insert_processed_data (%s, %s, %s, %s)', (zoom_level, tile_row, tile_column , json_str)) return worker