Added Python test for multi-tile raster policy.

This commit is contained in:
Matt Amos 2011-10-18 14:34:58 +01:00
parent 49e872049c
commit 517fc59f77
7 changed files with 81 additions and 4 deletions

View file

@ -410,6 +410,13 @@ def Raster(**keywords):
Optional keyword arguments:
base -- path prefix (default None)
multi -- whether the image is in tiles on disk (default False)
Multi-tiled keyword arguments:
x_width -- virtual image number of tiles in X direction (required)
y_width -- virtual image number of tiles in Y direction (required)
tile_size -- if an image is in tiles, how large are the tiles (default 256)
tile_stride -- if an image is in tiles, what's the increment between rows/cols (default 1)
>>> from mapnik import Raster, Layer
>>> raster = Raster(base='/home/mapnik/data',file='elevation.tif',lox=-122.8,loy=48.5,hix=-122.7,hiy=48.6)

View file

@ -66,8 +66,8 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
filename_ = *file;
multi_tiles_ = *params_.get<bool>("multi", false);
tile_size_ = *params_.get<unsigned>("tile-size", 256);
tile_stride_ = *params_.get<unsigned>("tile-stride", 1);
tile_size_ = *params_.get<unsigned>("tile_size", 256);
tile_stride_ = *params_.get<unsigned>("tile_stride", 1);
format_=*params_.get<std::string>("format","tiff");
@ -102,8 +102,8 @@ void raster_datasource::bind() const
if (multi_tiles_)
{
boost::optional<unsigned> x_width = params_.get<unsigned>("x-width");
boost::optional<unsigned> y_width = params_.get<unsigned>("y-width");
boost::optional<unsigned> x_width = params_.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params_.get<unsigned>("y_width");
if (!x_width)
throw datasource_exception("Raster Plugin: x-width parameter not supplied for multi-tiled data source.");

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,70 @@
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path, save_data, contains_word
import os, mapnik2
def setup():
# All of the paths used are relative, if we run the tests
# from another directory we need to chdir()
os.chdir(execution_path('.'))
def test_multi_tile_policy():
srs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
lyr = mapnik2.Layer('raster')
lyr.datasource = mapnik2.Raster(
file = '../data/raster_tiles/${x}/${y}.tif',
lox = -180,
loy = -90,
hix = 180,
hiy = 90,
multi = 1,
tile_size = 256,
x_width = 2,
y_width = 2
)
lyr.srs = srs
_map = mapnik2.Map(256, 256, srs)
style = mapnik2.Style()
rule = mapnik2.Rule()
sym = mapnik2.RasterSymbolizer()
rule.symbols.append(sym)
style.rules.append(rule)
_map.append_style('foo', style)
lyr.styles.append('foo')
_map.layers.append(lyr)
_map.zoom_to_box(lyr.envelope())
im = mapnik2.Image(_map.width, _map.height)
mapnik2.render(_map, im)
save_data('test_multi_tile_policy.png', im.tostring('png'))
# test green chunk
assert im.view(0,64,1,1).tostring() == '\x00\xff\x00\xff'
assert im.view(127,64,1,1).tostring() == '\x00\xff\x00\xff'
assert im.view(0,127,1,1).tostring() == '\x00\xff\x00\xff'
assert im.view(127,127,1,1).tostring() == '\x00\xff\x00\xff'
# test blue chunk
assert im.view(128,64,1,1).tostring() == '\x00\x00\xff\xff'
assert im.view(255,64,1,1).tostring() == '\x00\x00\xff\xff'
assert im.view(128,127,1,1).tostring() == '\x00\x00\xff\xff'
assert im.view(255,127,1,1).tostring() == '\x00\x00\xff\xff'
# test red chunk
assert im.view(0,128,1,1).tostring() == '\xff\x00\x00\xff'
assert im.view(127,128,1,1).tostring() == '\xff\x00\x00\xff'
assert im.view(0,191,1,1).tostring() == '\xff\x00\x00\xff'
assert im.view(127,191,1,1).tostring() == '\xff\x00\x00\xff'
# test magenta chunk
assert im.view(128,128,1,1).tostring() == '\xff\x00\xff\xff'
assert im.view(255,128,1,1).tostring() == '\xff\x00\xff\xff'
assert im.view(128,191,1,1).tostring() == '\xff\x00\xff\xff'
assert im.view(255,191,1,1).tostring() == '\xff\x00\xff\xff'
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]