add tests for grid rendering with point_symbolizer
This commit is contained in:
parent
b7630a3eb8
commit
587f0131a2
1 changed files with 30 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
|
from utilities import execution_path
|
||||||
import os, mapnik
|
import os, mapnik
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -10,6 +10,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
|
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('.'))
|
||||||
|
|
||||||
# first pass impl where resolution is passed as render
|
# first pass impl where resolution is passed as render
|
||||||
# time rather than encoding time, likely will be deprecated soon
|
# time rather than encoding time, likely will be deprecated soon
|
||||||
grid_correct_old = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
grid_correct_old = {"keys": ["", "North West", "North East", "South West", "South East"], "data": {"South East": {"Name": "South East"}, "North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||||
|
@ -39,7 +44,7 @@ def resolve(grid,row,col):
|
||||||
return grid['data'].get(key)
|
return grid['data'].get(key)
|
||||||
|
|
||||||
|
|
||||||
def create_grid_map(width,height):
|
def create_grid_map(width,height,marker=True):
|
||||||
ds = mapnik.MemoryDatasource()
|
ds = mapnik.MemoryDatasource()
|
||||||
context = mapnik.Context()
|
context = mapnik.Context()
|
||||||
context.push('Name')
|
context.push('Name')
|
||||||
|
@ -64,9 +69,12 @@ def create_grid_map(width,height):
|
||||||
ds.add_feature(f)
|
ds.add_feature(f)
|
||||||
s = mapnik.Style()
|
s = mapnik.Style()
|
||||||
r = mapnik.Rule()
|
r = mapnik.Rule()
|
||||||
symb = mapnik.MarkersSymbolizer()
|
if marker:
|
||||||
symb.width = mapnik.Expression('10')
|
symb = mapnik.MarkersSymbolizer()
|
||||||
symb.height = mapnik.Expression('10')
|
symb.width = mapnik.Expression('10')
|
||||||
|
symb.height = mapnik.Expression('10')
|
||||||
|
else:
|
||||||
|
symb = mapnik.PointSymbolizer(mapnik.PathExpression('../data/images/dummy.png'))
|
||||||
symb.allow_overlap = True
|
symb.allow_overlap = True
|
||||||
r.symbols.append(symb)
|
r.symbols.append(symb)
|
||||||
|
|
||||||
|
@ -274,6 +282,23 @@ def test_line_rendering():
|
||||||
eq_(utf1,line_expected,show_grids('line',utf1,line_expected))
|
eq_(utf1,line_expected,show_grids('line',utf1,line_expected))
|
||||||
#open('test.json','w').write(json.dumps(grid.encode()))
|
#open('test.json','w').write(json.dumps(grid.encode()))
|
||||||
|
|
||||||
|
point_expected = {"keys": ["", "3", "4", "2", "1"], "data": {"1": {"Name": "South East"}, "3": {"Name": "North West"}, "2": {"Name": "South West"}, "4": {"Name": "North East"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||||
|
|
||||||
|
def test_point_symbolizer_grid():
|
||||||
|
width,height = 256,256
|
||||||
|
m = create_grid_map(width,height,marker=False)
|
||||||
|
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
||||||
|
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
||||||
|
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
||||||
|
#mapnik.render_to_file(m,'test.png')
|
||||||
|
#print mapnik.save_map_to_string(m)
|
||||||
|
grid = mapnik.Grid(m.width,m.height)
|
||||||
|
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
||||||
|
utf1 = grid.encode()
|
||||||
|
#open('test.json','w').write(json.dumps(grid.encode()))
|
||||||
|
eq_(utf1,point_expected,show_grids('point-sym',utf1,point_expected))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
setup()
|
||||||
[eval(run)() for run in dir() if 'test_' in run]
|
[eval(run)() for run in dir() if 'test_' in run]
|
||||||
|
|
Loading…
Reference in a new issue