From 8d37ba41ac16666b642ad5b470923bda499ef551 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Wed, 2 Nov 2016 15:53:43 +0000 Subject: [PATCH] Add bbox filter to test for partial overlapping, rather than intersecting, the bbox. --- tilequeue/command.py | 2 ++ tilequeue/query.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/tilequeue/command.py b/tilequeue/command.py index 4f28e23d..df730e84 100755 --- a/tilequeue/command.py +++ b/tilequeue/command.py @@ -15,6 +15,7 @@ from tilequeue.query import jinja_filter_bbox_padded_intersection from tilequeue.query import jinja_filter_bbox from tilequeue.query import jinja_filter_geometry +from tilequeue.query import jinja_filter_bbox_overlaps from tilequeue.queue import make_sqs_queue from tilequeue.tile import coord_int_zoom_up from tilequeue.tile import coord_marshall_int @@ -372,6 +373,7 @@ def parse_layer_data(query_cfg, buffer_cfg, template_path, reload_templates, environment.filters['bbox_padded_intersection'] = ( jinja_filter_bbox_padded_intersection) environment.filters['bbox'] = jinja_filter_bbox + environment.filters['bbox_overlaps'] = jinja_filter_bbox_overlaps for layer_name, layer_config in layers_config.items(): template_name = layer_config['template'] diff --git a/tilequeue/query.py b/tilequeue/query.py index fc01e91f..4784b10e 100644 --- a/tilequeue/query.py +++ b/tilequeue/query.py @@ -72,6 +72,17 @@ def jinja_filter_bbox(bounds, srid=3857): return bbox +def jinja_filter_bbox_overlaps(bounds, geometry_col_name, srid=3857): + min_point = 'ST_MakePoint(%.12f, %.12f)' % (bounds[0], bounds[1]) + max_point = 'ST_MakePoint(%.12f, %.12f)' % (bounds[2], bounds[3]) + bbox_no_srid = 'ST_MakeBox2D(%s, %s)' % (min_point, max_point) + bbox = 'ST_SetSrid(%s, %d)' % (bbox_no_srid, srid) + bbox_filter = \ + '((%(col)s && %(bbox)s) AND st_overlaps(%(col)s, %(bbox)s))' \ + % dict(col=geometry_col_name, bbox=bbox) + return bbox_filter + + def build_feature_queries(unpadded_bounds, layer_data, zoom): meters_per_pixel_dim = calc_meters_per_pixel_dim(zoom) queries_to_execute = []