Skip to content

Commit

Permalink
Fixed breaking of large tiled maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed May 18, 2014
1 parent 2e42749 commit 4d45fe0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Nik4 Change History

## 1.1, 18.05.2014

* True scale (like 1:10000) was calculated incorrectly. [#3](https://github.com/Zverik/Nik4/issues/3)
* Mapnik image size limit (16384×16384) is now enforced.
* Fixed breaking of large tiled maps.

## 1.0, 16.05.2014

Initial release
16 changes: 13 additions & 3 deletions nik4.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def prepare_wld(m):
else:
raise Exception('Image dimensions or scale were not specified in any way')

if need_cairo and options.tiles > 1:
options.tiles = 1
if max(size[0], size[1]) / options.tiles > 16384:
raise Exception('Image size exceeds mapnik limit ({} > {}), use --tiles'.format(max(size[0], size[1]) / options.tiles, 16384))

# add / remove some layers
if options.layers:
filter_layers(m, options.layers.split(','))
Expand Down Expand Up @@ -257,8 +262,13 @@ def prepare_wld(m):
mapnik.render(m, im, scale_factor)
im.save(options.output, fmt)
else:
scale = m.scale()
bbox = m.envelope()
# we cannot make mapnik calculate scale for us, so fixing aspect ratio outselves
rdiff = (bbox.maxx-bbox.minx) / (bbox.maxy-bbox.miny) - size[0] / size[1]
if rdiff > 0:
bbox.height((bbox.maxx - bbox.minx) * size[1] / size[0])
elif rdiff < 0:
bbox.width((bbox.maxy - bbox.miny) * size[0] / size[1])
scale = (bbox.maxx - bbox.minx) / size[0]
width = max(32, int(math.ceil(1.0 * size[0] / options.tiles)))
height = max(32, int(math.ceil(1.0 * size[1] / options.tiles)))
m.resize(width, height)
Expand All @@ -273,7 +283,7 @@ def prepare_wld(m):
for column in range(0, tile_cnt[0]):
if options.debug:
print 'tile={},{}'.format(row, column)
m.zoom_to_box(mapnik.Box2d(bbox.minx + width * scale * column, bbox.maxy - height * scale * row, bbox.minx + width * scale * (column + 1), bbox.maxy - height * scale * (row + 1)))
m.zoom_to_box(mapnik.Box2d(bbox.minx + 1.0 * width * scale * column, bbox.maxy - 1.0 * height * scale * row, bbox.minx + 1.0 * width * scale * (column + 1), bbox.maxy - 1.0 * height * scale * (row + 1)))
im = mapnik.Image(width if column < tile_cnt[0] - 1 else size[0] - width * (tile_cnt[0] - 1), height if row < tile_cnt[1] - 1 else size[1] - height * (tile_cnt[1] - 1))
mapnik.render(m, im, scale_factor)
tile_name = tmp_tile.format(row, column, options.output)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='Nik4',
version='1.0.0',
version='1.1.1',
license='WTFPL',
description='Command-line interface to a Mapnik rendering toolkit',
long_description=open('README.txt').read(),
Expand Down

0 comments on commit 4d45fe0

Please sign in to comment.