2011-10-18 13:34:58 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from nose.tools import *
|
2012-09-26 21:12:55 +00:00
|
|
|
from utilities import execution_path, contains_word
|
2011-10-18 13:34:58 +00:00
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
import os, mapnik
|
2011-10-18 13:34:58 +00:00
|
|
|
|
|
|
|
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'
|
2011-11-23 11:33:58 +00:00
|
|
|
lyr = mapnik.Layer('raster')
|
2012-09-05 11:53:37 +00:00
|
|
|
if 'raster' in mapnik.DatasourceCache.plugin_names():
|
2011-11-23 11:33:58 +00:00
|
|
|
lyr.datasource = mapnik.Raster(
|
2011-10-29 00:06:23 +00:00
|
|
|
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
|
2011-11-23 11:33:58 +00:00
|
|
|
_map = mapnik.Map(256, 256, srs)
|
|
|
|
style = mapnik.Style()
|
|
|
|
rule = mapnik.Rule()
|
|
|
|
sym = mapnik.RasterSymbolizer()
|
2011-10-29 00:06:23 +00:00
|
|
|
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())
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-11-23 11:33:58 +00:00
|
|
|
im = mapnik.Image(_map.width, _map.height)
|
|
|
|
mapnik.render(_map, im)
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
# test green chunk
|
2011-10-31 18:46:58 +00:00
|
|
|
eq_(im.view(0,64,1,1).tostring(), '\x00\xff\x00\xff')
|
|
|
|
eq_(im.view(127,64,1,1).tostring(), '\x00\xff\x00\xff')
|
|
|
|
eq_(im.view(0,127,1,1).tostring(), '\x00\xff\x00\xff')
|
|
|
|
eq_(im.view(127,127,1,1).tostring(), '\x00\xff\x00\xff')
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
# test blue chunk
|
2011-10-31 18:46:58 +00:00
|
|
|
eq_(im.view(128,64,1,1).tostring(), '\x00\x00\xff\xff')
|
|
|
|
eq_(im.view(255,64,1,1).tostring(), '\x00\x00\xff\xff')
|
|
|
|
eq_(im.view(128,127,1,1).tostring(), '\x00\x00\xff\xff')
|
|
|
|
eq_(im.view(255,127,1,1).tostring(), '\x00\x00\xff\xff')
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
# test red chunk
|
2011-10-31 18:46:58 +00:00
|
|
|
eq_(im.view(0,128,1,1).tostring(), '\xff\x00\x00\xff')
|
|
|
|
eq_(im.view(127,128,1,1).tostring(), '\xff\x00\x00\xff')
|
|
|
|
eq_(im.view(0,191,1,1).tostring(), '\xff\x00\x00\xff')
|
|
|
|
eq_(im.view(127,191,1,1).tostring(), '\xff\x00\x00\xff')
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2011-10-29 00:06:23 +00:00
|
|
|
# test magenta chunk
|
2011-10-31 18:46:58 +00:00
|
|
|
eq_(im.view(128,128,1,1).tostring(), '\xff\x00\xff\xff')
|
|
|
|
eq_(im.view(255,128,1,1).tostring(), '\xff\x00\xff\xff')
|
|
|
|
eq_(im.view(128,191,1,1).tostring(), '\xff\x00\xff\xff')
|
|
|
|
eq_(im.view(255,191,1,1).tostring(), '\xff\x00\xff\xff')
|
2011-10-18 13:34:58 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup()
|
|
|
|
[eval(run)() for run in dir() if 'test_' in run]
|