From 587f0131a2310882df33bb392e1bb66f04bfba71 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 18 Jul 2012 17:29:22 -0700 Subject: [PATCH] add tests for grid rendering with point_symbolizer --- tests/python_tests/render_grid_test.py | 35 ++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/python_tests/render_grid_test.py b/tests/python_tests/render_grid_test.py index 575717660..f2ce75b3c 100644 --- a/tests/python_tests/render_grid_test.py +++ b/tests/python_tests/render_grid_test.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from nose.tools import * - +from utilities import execution_path import os, mapnik try: @@ -10,6 +10,11 @@ try: except ImportError: 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 # 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": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]} @@ -39,7 +44,7 @@ def resolve(grid,row,col): return grid['data'].get(key) -def create_grid_map(width,height): +def create_grid_map(width,height,marker=True): ds = mapnik.MemoryDatasource() context = mapnik.Context() context.push('Name') @@ -64,9 +69,12 @@ def create_grid_map(width,height): ds.add_feature(f) s = mapnik.Style() r = mapnik.Rule() - symb = mapnik.MarkersSymbolizer() - symb.width = mapnik.Expression('10') - symb.height = mapnik.Expression('10') + if marker: + symb = mapnik.MarkersSymbolizer() + symb.width = mapnik.Expression('10') + symb.height = mapnik.Expression('10') + else: + symb = mapnik.PointSymbolizer(mapnik.PathExpression('../data/images/dummy.png')) symb.allow_overlap = True r.symbols.append(symb) @@ -274,6 +282,23 @@ def test_line_rendering(): eq_(utf1,line_expected,show_grids('line',utf1,line_expected)) #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__": + setup() [eval(run)() for run in dir() if 'test_' in run]