Skip to content

Commit

Permalink
Merge pull request #69 from sbrunner/mapcache_resolutions
Browse files Browse the repository at this point in the history
Change MapCache resolutions strategy
  • Loading branch information
sbrunner committed Mar 5, 2013
2 parents 24c3f4c + c7031b3 commit 29598de
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 44 deletions.
10 changes: 9 additions & 1 deletion tilecloud_chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 0 additions & 23 deletions tilecloud_chain/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tilecloud_chain/mapcache_config_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<extent>{{grid['bbox'][0]}} {{grid['bbox'][1]}} {{grid['bbox'][2]}} {{grid['bbox'][3]}}</extent>
<srs>{{grid['srs']}}</srs>
<units>{{grid['unit']}}</units>
<resolutions>{% for r in mapcache['resolutions'] %}{{r}} {% endfor %}</resolutions>
<resolutions>{% for r in grid['resolutions'] %}{{r}} {% endfor %}</resolutions>
<origin>top-left</origin>
</grid>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tilecloud_chain/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ def test_mapcache(self):
<extent>420000.0 30000.0 900000.0 350000.0</extent>
<srs>epsg:21781</srs>
<units>m</units>
<resolutions>100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 </resolutions>
<resolutions>1.0 0.2 0.1 </resolutions>
<origin>top-left</origin>
</grid>
Expand All @@ -969,7 +969,7 @@ def test_mapcache(self):
<extent>420000.0 30000.0 900000.0 350000.0</extent>
<srs>epsg:21781</srs>
<units>m</units>
<resolutions>100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 </resolutions>
<resolutions>100.0 50.0 20.0 10.0 5.0 </resolutions>
<origin>top-left</origin>
</grid>
Expand All @@ -978,7 +978,7 @@ def test_mapcache(self):
<extent>420000.0 30000.0 900000.0 350000.0</extent>
<srs>epsg:21781</srs>
<units>m</units>
<resolutions>100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 </resolutions>
<resolutions>0.25 </resolutions>
<origin>top-left</origin>
</grid>
Expand All @@ -987,7 +987,7 @@ def test_mapcache(self):
<extent>420000.0 30000.0 900000.0 350000.0</extent>
<srs>epsg:21781</srs>
<units>m</units>
<resolutions>100.0 50.0 20.0 10.0 5.0 2.0 1.0 0.5 </resolutions>
<resolutions>2.5 </resolutions>
<origin>top-left</origin>
</grid>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"""

Expand Down
13 changes: 1 addition & 12 deletions tilecloud_chain/tests/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
},
Expand Down
13 changes: 13 additions & 0 deletions tilecloud_chain/tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tilecloud_chain/tests/tilegeneration/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 29598de

Please sign in to comment.