diff --git a/tilecloud_chain/__init__.py b/tilecloud_chain/__init__.py index 1118d7296..1a0e33de3 100644 --- a/tilecloud_chain/__init__.py +++ b/tilecloud_chain/__init__.py @@ -146,6 +146,7 @@ def __init__(self, config_file, options=None, layer_name=None): error = self.validate(layer, name, 'name', attribute_type=str, default=lname) or error error = self.validate(layer, name, 'grid', attribute_type=str, required=True) or error + error = self.validate(layer, name, 'min_resolution_seed', attribute_type=float) or error error = self.validate(layer, name, 'px_buffer', attribute_type=float, default=False) or error error = self.validate( layer, name, 'type', attribute_type=str, required=True, @@ -618,6 +619,12 @@ def init_tilecoords(self, options): if options.time and not options.zoom: options.zoom = [max(bounding_pyramid.bounds)] + if not options.zoom and 'min_resolution_seed' in self.layer: + options.zoom = [] + for z, resolution in enumerate(self.layer['grid_ref']['resolutions']): + if resolution >= self.layer['min_resolution_seed']: + options.zoom.append(z) + meta = self.layer['meta'] if meta: if options.zoom: @@ -646,7 +653,8 @@ def ziter(): def set_tilecoords(self, tilecoords): self.tilestream = ( - Tile(tilecoord) for tilecoord in tilecoords) + Tile(tilecoord) for tilecoord in tilecoords + ) def set_store(self, store): # pragma: no cover self.tilestream = store.list() diff --git a/tilecloud_chain/controller.py b/tilecloud_chain/controller.py index 7b2ddc3fd..56692ce7b 100644 --- a/tilecloud_chain/controller.py +++ b/tilecloud_chain/controller.py @@ -726,10 +726,6 @@ def _validate_generate_mapcache_config(gene): gene.config['mapcache'], 'mapcache', 'config_file', attribute_type=str, default='apache/mapcache.xml.in' ) or error - error = gene.validate( - gene.config['mapcache'], 'mapcache', 'resolutions', attribute_type=float, - is_array=True, required=True - ) or error error = gene.validate( gene.config['mapcache'], 'mapcache', 'memcache_host', attribute_type=str, default='localhost' @@ -743,25 +739,6 @@ def _validate_generate_mapcache_config(gene): required=True, enumeration=gene.config['layers'].keys() ) or error - if 'layers' in gene.config['mapcache'] and 'resolutions' in gene.config['mapcache']: - for layer in gene.config['mapcache']['layers']: - if len(gene.layers[layer]['grid_ref']['resolutions']) > gene.config['mapcache']['resolutions']: - logger.error( - "The layer '%s' (grid '%s') has more resolutions than mapcache." % - (layer, gene.layers[layer]['grid']) - ) # pragma: no cover - error = True # pragma: no cover - else: - for i, resolution in enumerate(gene.layers[layer]['grid_ref']['resolutions']): - if resolution != gene.config['mapcache']['resolutions'][i]: - logger.error( - "The resolutions of layer '%s' (grid '%s') " - "don't corresponds to mapcache resolutions (%f != %s)." % - (layer, gene.layers[layer]['grid'], - resolution, gene.config['mapcache']['resolutions'][i]) - ) # pragma: no cover - error = True # pragma: no cover - if error: exit(1) # pragma: no cover diff --git a/tilecloud_chain/mapcache_config_template.py b/tilecloud_chain/mapcache_config_template.py index dcf2b0c6c..561fb6472 100644 --- a/tilecloud_chain/mapcache_config_template.py +++ b/tilecloud_chain/mapcache_config_template.py @@ -13,7 +13,7 @@ {{grid['bbox'][0]}} {{grid['bbox'][1]}} {{grid['bbox'][2]}} {{grid['bbox'][3]}} {{grid['srs']}} {{grid['unit']}} - {% for r in mapcache['resolutions'] %}{{r}} {% endfor %} + {% for r in grid['resolutions'] %}{{r}} {% endfor %} top-left {% endfor %} diff --git a/tilecloud_chain/scaffolds/create/tilegeneration/config.yaml.in_tmpl b/tilecloud_chain/scaffolds/create/tilegeneration/config.yaml.in_tmpl index f9a2799a5..6fdf601bc 100644 --- a/tilecloud_chain/scaffolds/create/tilegeneration/config.yaml.in_tmpl +++ b/tilecloud_chain/scaffolds/create/tilegeneration/config.yaml.in_tmpl @@ -37,9 +37,11 @@ caches: # this defines some defaults values for all the layers layer_default: + type: wms # name of the grid to use (defined in grids) grid: swissgrid_05 - type: wms + # The minimum resolution to seed, useful to use with mapcache, optional. + # min_resolution_seed: 1 # the URL of the WMS server to used url: http://${facts:fqdn}/${vars:instanceid}/mapserv # file name extension diff --git a/tilecloud_chain/tests/test_controller.py b/tilecloud_chain/tests/test_controller.py index e3fa8b438..90aac9b9f 100644 --- a/tilecloud_chain/tests/test_controller.py +++ b/tilecloud_chain/tests/test_controller.py @@ -960,7 +960,7 @@ def test_mapcache(self): 420000.0 30000.0 900000.0 350000.0 epsg:21781 m - 100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 + 1.0 0.2 0.1 top-left @@ -969,7 +969,7 @@ def test_mapcache(self): 420000.0 30000.0 900000.0 350000.0 epsg:21781 m - 100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 + 100.0 50.0 20.0 10.0 5.0 top-left @@ -978,7 +978,7 @@ def test_mapcache(self): 420000.0 30000.0 900000.0 350000.0 epsg:21781 m - 100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 + 0.25 top-left @@ -987,7 +987,7 @@ def test_mapcache(self): 420000.0 30000.0 900000.0 350000.0 epsg:21781 m - 100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 + 2.5 top-left @@ -1502,6 +1502,7 @@ def test_mapcache(self): meta_buffer: 128 meta_size: 8 mime_type: image/png + min_resolution_seed: 10.0 name: point px_buffer: false sql: ST_Buffer(ST_Union(the_geom), 100, 2) FROM tests.point @@ -1606,7 +1607,6 @@ def test_mapcache(self): mapserver_url: http://localhost/mapserv memcache_host: localhost memcache_port: '11211' - resolutions: [100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0, 0.5] openlayers: {center_x: 600000.0, center_y: 200000.0, srs: 'epsg:21781'} sns: {region: eu-west-1, topic: sns_topic}""" diff --git a/tilecloud_chain/tests/test_cost.py b/tilecloud_chain/tests/test_cost.py index fc71c9acd..16e35ee42 100644 --- a/tilecloud_chain/tests/test_cost.py +++ b/tilecloud_chain/tests/test_cost.py @@ -114,13 +114,11 @@ def test_cost_point_count(self): 'Calculate zoom 1.', 'Calculate zoom 2.', 'Calculate zoom 3.', - 'Calculate zoom 4.', '', '1 meta tiles in zoom 0.', '1 meta tiles in zoom 1.', '2 meta tiles in zoom 2.', '2 meta tiles in zoom 3.', - '2 meta tiles in zoom 4.', self.ZOOM_SUMMARY % { 'tiles': '2', 'zoom': '0', @@ -157,17 +155,8 @@ def test_cost_point_count(self): 'esb': '0.00', 'sqs': '0.00' }, - self.ZOOM_SUMMARY % { - 'tiles': '3', - 'zoom': '4', - 'time': '0 0:00:00', - 's3': '0.00', - 'ec2': '0.00', - 'esb': '0.00', - 'sqs': '0.00' - }, self.LAYER_SUMMARY % { - 'tiles': '12', + 'tiles': '9', 'time': '0 0:00:00', 'cost': '0.00' }, diff --git a/tilecloud_chain/tests/test_generate.py b/tilecloud_chain/tests/test_generate.py index 967849ab7..cac5dff18 100644 --- a/tilecloud_chain/tests/test_generate.py +++ b/tilecloud_chain/tests/test_generate.py @@ -165,6 +165,19 @@ def test_zoom_range(self): ] ) + def test_no_zoom(self): + self.assert_tiles_generated( + './buildout/bin/generate_tiles -c tilegeneration/test.yaml -l point', + generate.main, + "/tmp/tiles/", + '1.0.0/%s/default/2012/swissgrid_5/%i/%i/%i.png', [ + ('point', 0, 5, 7), ('point', 0, 7, 4), + ('point', 1, 11, 14), ('point', 1, 15, 8), + ('point', 2, 29, 35), ('point', 2, 39, 21), + ('point', 3, 58, 70), ('point', 3, 78, 42), ('point', 3, 78, 43), + ] + ) + def test_py_buffer(self): self.assert_tiles_generated( './buildout/bin/generate_tiles -c tilegeneration/test.yaml -l point_px_buffer --zoom 0-2', diff --git a/tilecloud_chain/tests/tilegeneration/test.yaml b/tilecloud_chain/tests/tilegeneration/test.yaml index 6b33157cf..0c48b6842 100644 --- a/tilecloud_chain/tests/tilegeneration/test.yaml +++ b/tilecloud_chain/tests/tilegeneration/test.yaml @@ -84,6 +84,7 @@ layers: point: layers: point sql: ST_Buffer(ST_Union(the_geom), 100, 2) FROM tests.point + min_resolution_seed: 10 point_px_buffer: layers: point px_buffer: 100 @@ -186,7 +187,6 @@ mapcache: mapserver_url: http://localhost/mapserv mapcache_url: /mapcache config_file: mapcache.xml - resolutions: [100, 50, 20, 10, 5, 2, 1, 0.5] layers: [point, line, polygon] sns: