fix pep8 linter command + update a few linted files
This commit is contained in:
parent
7d78115886
commit
956d936162
6 changed files with 67 additions and 67 deletions
5
Makefile
5
Makefile
|
@ -84,8 +84,9 @@ demo:
|
||||||
pep8:
|
pep8:
|
||||||
# https://gist.github.com/1903033
|
# https://gist.github.com/1903033
|
||||||
# gsed on osx
|
# gsed on osx
|
||||||
@pep8 -r --select=W293 -q --filename=*.py `pwd`/tests/ | xargs gsed -i 's/^[ \r\t]*$//'
|
@pep8 -r --select=W293 -q --filename=*.py `pwd`/tests/ | xargs gsed -i 's/^[ \r\t]*$$//'
|
||||||
@pep8 -r --select=W391 -q --filename=*.py `pwd`/tests/ | xargs gsed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}'
|
@pep8 -r --select=W391 -q --filename=*.py `pwd`/tests/ | xargs gsed -i -e :a -e '/^\n*$$/{$$d;N;ba' -e '}'
|
||||||
|
@pep8 -r --select=W391 -q --filename=*.py `pwd`/tests/ | xargs ged -i '/./,/^$$/!d'
|
||||||
|
|
||||||
grind:
|
grind:
|
||||||
@for FILE in tests/cpp_tests/*-bin; do \
|
@for FILE in tests/cpp_tests/*-bin; do \
|
||||||
|
|
|
@ -36,7 +36,7 @@ if mapnik.has_grid_renderer():
|
||||||
val += ' ✓ keys match\n'
|
val += ' ✓ keys match\n'
|
||||||
val += '\n\t%s\n\t%s' % (g1_file,g2_file)
|
val += '\n\t%s\n\t%s' % (g1_file,g2_file)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def show_grids2(name,g1,g2):
|
def show_grids2(name,g1,g2):
|
||||||
g2_expected = '../data/grids/mapnik-%s-actual.json' % name
|
g2_expected = '../data/grids/mapnik-%s-actual.json' % name
|
||||||
if not os.path.exists(g2_expected):
|
if not os.path.exists(g2_expected):
|
||||||
|
@ -60,15 +60,15 @@ if mapnik.has_grid_renderer():
|
||||||
val += ' ✓ keys match\n'
|
val += ' ✓ keys match\n'
|
||||||
val += '\n\t%s\n\t%s' % (g1_file,g2_expected)
|
val += '\n\t%s\n\t%s' % (g1_file,g2_expected)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
# previous rendering using agg ellipse directly
|
# previous rendering using agg ellipse directly
|
||||||
grid_correct_new = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
grid_correct_new = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
||||||
|
|
||||||
# newer rendering using svg
|
# newer rendering using svg
|
||||||
grid_correct_new2 = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
grid_correct_new2 = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
||||||
|
|
||||||
grid_correct_new3 = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
grid_correct_new3 = {"data": {"North East": {"Name": "North East"}, "North West": {"Name": "North West"}, "South East": {"Name": "South East"}, "South West": {"Name": "South West"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "North West", "North East", "South West", "South East"]}
|
||||||
|
|
||||||
def resolve(grid,row,col):
|
def resolve(grid,row,col):
|
||||||
""" Resolve the attributes for a given pixel in a grid.
|
""" Resolve the attributes for a given pixel in a grid.
|
||||||
"""
|
"""
|
||||||
|
@ -83,8 +83,8 @@ if mapnik.has_grid_renderer():
|
||||||
codepoint -= 32
|
codepoint -= 32
|
||||||
key = grid['keys'][codepoint]
|
key = grid['keys'][codepoint]
|
||||||
return grid['data'].get(key)
|
return grid['data'].get(key)
|
||||||
|
|
||||||
|
|
||||||
def create_grid_map(width,height,sym):
|
def create_grid_map(width,height,sym):
|
||||||
ds = mapnik.MemoryDatasource()
|
ds = mapnik.MemoryDatasource()
|
||||||
context = mapnik.Context()
|
context = mapnik.Context()
|
||||||
|
@ -93,17 +93,17 @@ if mapnik.has_grid_renderer():
|
||||||
f['Name'] = 'South East'
|
f['Name'] = 'South East'
|
||||||
f.add_geometries_from_wkt('POINT (143.10 -38.60)')
|
f.add_geometries_from_wkt('POINT (143.10 -38.60)')
|
||||||
ds.add_feature(f)
|
ds.add_feature(f)
|
||||||
|
|
||||||
f = mapnik.Feature(context,2)
|
f = mapnik.Feature(context,2)
|
||||||
f['Name'] = 'South West'
|
f['Name'] = 'South West'
|
||||||
f.add_geometries_from_wkt('POINT (142.48 -38.60)')
|
f.add_geometries_from_wkt('POINT (142.48 -38.60)')
|
||||||
ds.add_feature(f)
|
ds.add_feature(f)
|
||||||
|
|
||||||
f = mapnik.Feature(context,3)
|
f = mapnik.Feature(context,3)
|
||||||
f['Name'] = 'North West'
|
f['Name'] = 'North West'
|
||||||
f.add_geometries_from_wkt('POINT (142.48 -38.38)')
|
f.add_geometries_from_wkt('POINT (142.48 -38.38)')
|
||||||
ds.add_feature(f)
|
ds.add_feature(f)
|
||||||
|
|
||||||
f = mapnik.Feature(context,4)
|
f = mapnik.Feature(context,4)
|
||||||
f['Name'] = 'North East'
|
f['Name'] = 'North East'
|
||||||
f.add_geometries_from_wkt('POINT (143.10 -38.38)')
|
f.add_geometries_from_wkt('POINT (143.10 -38.38)')
|
||||||
|
@ -120,8 +120,8 @@ if mapnik.has_grid_renderer():
|
||||||
m.append_style('places_labels',s)
|
m.append_style('places_labels',s)
|
||||||
m.layers.append(lyr)
|
m.layers.append(lyr)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
def test_render_grid():
|
def test_render_grid():
|
||||||
""" test render_grid method"""
|
""" test render_grid method"""
|
||||||
width,height = 256,256
|
width,height = 256,256
|
||||||
|
@ -132,13 +132,13 @@ if mapnik.has_grid_renderer():
|
||||||
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
||||||
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
||||||
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
||||||
|
|
||||||
# new method
|
# new method
|
||||||
grid = mapnik.Grid(m.width,m.height,key='Name')
|
grid = mapnik.Grid(m.width,m.height,key='Name')
|
||||||
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
eq_(utf1,grid_correct_new3,show_grids('new-markers',utf1,grid_correct_new3))
|
eq_(utf1,grid_correct_new3,show_grids('new-markers',utf1,grid_correct_new3))
|
||||||
|
|
||||||
# check a full view is the same as a full image
|
# check a full view is the same as a full image
|
||||||
grid_view = grid.view(0,0,width,height)
|
grid_view = grid.view(0,0,width,height)
|
||||||
# for kicks check at full res too
|
# for kicks check at full res too
|
||||||
|
@ -147,9 +147,9 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(utf3['grid'],utf4['grid'])
|
eq_(utf3['grid'],utf4['grid'])
|
||||||
eq_(utf3['keys'],utf4['keys'])
|
eq_(utf3['keys'],utf4['keys'])
|
||||||
eq_(utf3['data'],utf4['data'])
|
eq_(utf3['data'],utf4['data'])
|
||||||
|
|
||||||
eq_(resolve(utf4,0,0),None)
|
eq_(resolve(utf4,0,0),None)
|
||||||
|
|
||||||
# resolve some center points in the
|
# resolve some center points in the
|
||||||
# resampled view
|
# resampled view
|
||||||
utf5 = grid_view.encode('utf',resolution=4)
|
utf5 = grid_view.encode('utf',resolution=4)
|
||||||
|
@ -157,14 +157,14 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(resolve(utf5,25,46),{"Name": "North East"})
|
eq_(resolve(utf5,25,46),{"Name": "North East"})
|
||||||
eq_(resolve(utf5,38,10),{"Name": "South West"})
|
eq_(resolve(utf5,38,10),{"Name": "South West"})
|
||||||
eq_(resolve(utf5,38,46),{"Name": "South East"})
|
eq_(resolve(utf5,38,46),{"Name": "South East"})
|
||||||
|
|
||||||
|
|
||||||
grid_feat_id = {'keys': ['', '3', '4', '2', '1'], 'data': {'1': {'Name': 'South East'}, '3': {'Name': u'North West'}, '2': {'Name': 'South West'}, '4': {'Name': 'North East'}}, 'grid': [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' !! ## ', ' !!! ### ', ' !! ## ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' $$$ %% ', ' $$$ %%% ', ' $$ %% ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']}
|
grid_feat_id = {'keys': ['', '3', '4', '2', '1'], 'data': {'1': {'Name': 'South East'}, '3': {'Name': u'North West'}, '2': {'Name': 'South West'}, '4': {'Name': 'North East'}}, 'grid': [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' !! ## ', ' !!! ### ', ' !! ## ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' $$$ %% ', ' $$$ %%% ', ' $$ %% ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']}
|
||||||
|
|
||||||
grid_feat_id2 = {"data": {"1": {"Name": "South East"}, "2": {"Name": "South West"}, "3": {"Name": "North West"}, "4": {"Name": "North East"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
grid_feat_id2 = {"data": {"1": {"Name": "South East"}, "2": {"Name": "South West"}, "3": {"Name": "North West"}, "4": {"Name": "North East"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $$ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
||||||
|
|
||||||
grid_feat_id3 = {"data": {"1": {"Name": "South East", "__id__": 1}, "2": {"Name": "South West", "__id__": 2}, "3": {"Name": "North West", "__id__": 3}, "4": {"Name": "North East", "__id__": 4}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
grid_feat_id3 = {"data": {"1": {"Name": "South East", "__id__": 1}, "2": {"Name": "South West", "__id__": 2}, "3": {"Name": "North West", "__id__": 3}, "4": {"Name": "North East", "__id__": 4}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !! ## ", " !!! ### ", " !! ## ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$ %% ", " $$$ %% ", " $ %% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
||||||
|
|
||||||
def test_render_grid3():
|
def test_render_grid3():
|
||||||
""" test using feature id"""
|
""" test using feature id"""
|
||||||
width,height = 256,256
|
width,height = 256,256
|
||||||
|
@ -175,7 +175,7 @@ if mapnik.has_grid_renderer():
|
||||||
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
||||||
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
||||||
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
||||||
|
|
||||||
grid = mapnik.Grid(m.width,m.height,key='__id__')
|
grid = mapnik.Grid(m.width,m.height,key='__id__')
|
||||||
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
|
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
|
@ -188,9 +188,9 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(utf3['grid'],utf4['grid'])
|
eq_(utf3['grid'],utf4['grid'])
|
||||||
eq_(utf3['keys'],utf4['keys'])
|
eq_(utf3['keys'],utf4['keys'])
|
||||||
eq_(utf3['data'],utf4['data'])
|
eq_(utf3['data'],utf4['data'])
|
||||||
|
|
||||||
eq_(resolve(utf4,0,0),None)
|
eq_(resolve(utf4,0,0),None)
|
||||||
|
|
||||||
# resolve some center points in the
|
# resolve some center points in the
|
||||||
# resampled view
|
# resampled view
|
||||||
utf5 = grid_view.encode('utf',resolution=4)
|
utf5 = grid_view.encode('utf',resolution=4)
|
||||||
|
@ -198,8 +198,8 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(resolve(utf5,25,46),{"Name": "North East","__id__": 4})
|
eq_(resolve(utf5,25,46),{"Name": "North East","__id__": 4})
|
||||||
eq_(resolve(utf5,38,10),{"Name": "South West","__id__": 2})
|
eq_(resolve(utf5,38,10),{"Name": "South West","__id__": 2})
|
||||||
eq_(resolve(utf5,38,46),{"Name": "South East","__id__": 1})
|
eq_(resolve(utf5,38,46),{"Name": "South East","__id__": 1})
|
||||||
|
|
||||||
|
|
||||||
def gen_grid_for_id(pixel_key):
|
def gen_grid_for_id(pixel_key):
|
||||||
ds = mapnik.MemoryDatasource()
|
ds = mapnik.MemoryDatasource()
|
||||||
context = mapnik.Context()
|
context = mapnik.Context()
|
||||||
|
@ -224,13 +224,13 @@ if mapnik.has_grid_renderer():
|
||||||
grid = mapnik.Grid(m.width,m.height,key='__id__')
|
grid = mapnik.Grid(m.width,m.height,key='__id__')
|
||||||
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
|
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
|
||||||
return grid
|
return grid
|
||||||
|
|
||||||
def test_negative_id():
|
def test_negative_id():
|
||||||
grid = gen_grid_for_id(-1)
|
grid = gen_grid_for_id(-1)
|
||||||
eq_(grid.get_pixel(128,128),-1)
|
eq_(grid.get_pixel(128,128),-1)
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
eq_(utf1['keys'],['-1'])
|
eq_(utf1['keys'],['-1'])
|
||||||
|
|
||||||
def test_32bit_int_id():
|
def test_32bit_int_id():
|
||||||
int32 = 2147483647
|
int32 = 2147483647
|
||||||
grid = gen_grid_for_id(int32)
|
grid = gen_grid_for_id(int32)
|
||||||
|
@ -242,7 +242,7 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(grid.get_pixel(128,128),max_neg)
|
eq_(grid.get_pixel(128,128),max_neg)
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
eq_(utf1['keys'],[str(max_neg)])
|
eq_(utf1['keys'],[str(max_neg)])
|
||||||
|
|
||||||
def test_64bit_int_id():
|
def test_64bit_int_id():
|
||||||
int64 = 0x7FFFFFFFFFFFFFFF
|
int64 = 0x7FFFFFFFFFFFFFFF
|
||||||
grid = gen_grid_for_id(int64)
|
grid = gen_grid_for_id(int64)
|
||||||
|
@ -254,15 +254,15 @@ if mapnik.has_grid_renderer():
|
||||||
eq_(grid.get_pixel(128,128),max_neg)
|
eq_(grid.get_pixel(128,128),max_neg)
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
eq_(utf1['keys'],[str(max_neg)])
|
eq_(utf1['keys'],[str(max_neg)])
|
||||||
|
|
||||||
def test_id_zero():
|
def test_id_zero():
|
||||||
grid = gen_grid_for_id(0)
|
grid = gen_grid_for_id(0)
|
||||||
eq_(grid.get_pixel(128,128),0)
|
eq_(grid.get_pixel(128,128),0)
|
||||||
utf1 = grid.encode('utf',resolution=4)
|
utf1 = grid.encode('utf',resolution=4)
|
||||||
eq_(utf1['keys'],['0'])
|
eq_(utf1['keys'],['0'])
|
||||||
|
|
||||||
line_expected = {"keys": ["", "1"], "data": {"1": {"Name": "1"}}, "grid": [" !", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", "!! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! "]}
|
line_expected = {"keys": ["", "1"], "data": {"1": {"Name": "1"}}, "grid": [" !", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", " !! ", "!! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! ", " ! "]}
|
||||||
|
|
||||||
def test_line_rendering():
|
def test_line_rendering():
|
||||||
ds = mapnik.MemoryDatasource()
|
ds = mapnik.MemoryDatasource()
|
||||||
context = mapnik.Context()
|
context = mapnik.Context()
|
||||||
|
@ -290,9 +290,9 @@ if mapnik.has_grid_renderer():
|
||||||
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
||||||
utf1 = grid.encode()
|
utf1 = grid.encode()
|
||||||
eq_(utf1,line_expected,show_grids('line',utf1,line_expected))
|
eq_(utf1,line_expected,show_grids('line',utf1,line_expected))
|
||||||
|
|
||||||
point_expected = {"data": {"1": {"Name": "South East"}, "2": {"Name": "South West"}, "3": {"Name": "North West"}, "4": {"Name": "North East"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
point_expected = {"data": {"1": {"Name": "South East"}, "2": {"Name": "South West"}, "3": {"Name": "North West"}, "4": {"Name": "North East"}}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " !!!! #### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " $$$$ %%%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "], "keys": ["", "3", "4", "2", "1"]}
|
||||||
|
|
||||||
def test_point_symbolizer_grid():
|
def test_point_symbolizer_grid():
|
||||||
width,height = 256,256
|
width,height = 256,256
|
||||||
sym = mapnik.PointSymbolizer()
|
sym = mapnik.PointSymbolizer()
|
||||||
|
@ -305,8 +305,8 @@ if mapnik.has_grid_renderer():
|
||||||
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
|
||||||
utf1 = grid.encode()
|
utf1 = grid.encode()
|
||||||
eq_(utf1,point_expected,show_grids('point-sym',utf1,point_expected))
|
eq_(utf1,point_expected,show_grids('point-sym',utf1,point_expected))
|
||||||
|
|
||||||
|
|
||||||
# should throw because this is a mis-usage
|
# should throw because this is a mis-usage
|
||||||
# https://github.com/mapnik/mapnik/issues/1325
|
# https://github.com/mapnik/mapnik/issues/1325
|
||||||
@raises(RuntimeError)
|
@raises(RuntimeError)
|
||||||
|
@ -320,7 +320,7 @@ if mapnik.has_grid_renderer():
|
||||||
r.symbols.append(sym)
|
r.symbols.append(sym)
|
||||||
s.rules.append(r)
|
s.rules.append(r)
|
||||||
m.append_style('points',s)
|
m.append_style('points',s)
|
||||||
|
|
||||||
# NOTE: we use a csv datasource here
|
# NOTE: we use a csv datasource here
|
||||||
# because the memorydatasource fails silently for
|
# because the memorydatasource fails silently for
|
||||||
# queries requesting fields that do not exist in the datasource
|
# queries requesting fields that do not exist in the datasource
|
||||||
|
@ -331,7 +331,7 @@ if mapnik.has_grid_renderer():
|
||||||
lyr1.datasource = ds1
|
lyr1.datasource = ds1
|
||||||
lyr1.styles.append('points')
|
lyr1.styles.append('points')
|
||||||
m.layers.append(lyr1)
|
m.layers.append(lyr1)
|
||||||
|
|
||||||
ds2 = mapnik.Datasource(**{"type":"csv","inline":'''
|
ds2 = mapnik.Datasource(**{"type":"csv","inline":'''
|
||||||
wkt,Value
|
wkt,Value
|
||||||
"POINT (142.48 -38.60)",South West'''})
|
"POINT (142.48 -38.60)",South West'''})
|
||||||
|
@ -339,7 +339,7 @@ if mapnik.has_grid_renderer():
|
||||||
lyr2.datasource = ds2
|
lyr2.datasource = ds2
|
||||||
lyr2.styles.append('points')
|
lyr2.styles.append('points')
|
||||||
m.layers.append(lyr2)
|
m.layers.append(lyr2)
|
||||||
|
|
||||||
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
||||||
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
||||||
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
|
||||||
|
|
|
@ -105,4 +105,3 @@ for format_tree in format_trees:
|
||||||
diff = compare(actual,expected)
|
diff = compare(actual,expected)
|
||||||
if diff > 0:
|
if diff > 0:
|
||||||
print 'comparision failed between:\n %s (actual)\n %s (expected)' % (actual,expected)
|
print 'comparision failed between:\n %s (actual)\n %s (expected)' % (actual,expected)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ if __name__ == "__main__":
|
||||||
for r in style.rules:
|
for r in style.rules:
|
||||||
print " Filter: %s" % r.filter
|
print " Filter: %s" % r.filter
|
||||||
num_sym += len(r.symbols)
|
num_sym += len(r.symbols)
|
||||||
|
|
||||||
print "Total number of layers %s" % len(m.layers)
|
print "Total number of layers %s" % len(m.layers)
|
||||||
print "Total number of styles %s" % len(set(styles)) # unique styles
|
print "Total number of styles %s" % len(set(styles)) # unique styles
|
||||||
print "Total number of rules %s" % num_rules
|
print "Total number of rules %s" % num_rules
|
||||||
|
|
|
@ -40,7 +40,7 @@ def indent(elem, level=0):
|
||||||
else:
|
else:
|
||||||
if level and (not elem.tail or not elem.tail.strip()):
|
if level and (not elem.tail or not elem.tail.strip()):
|
||||||
elem.tail = i
|
elem.tail = i
|
||||||
|
|
||||||
def name2expr(sym):
|
def name2expr(sym):
|
||||||
if 'name' not in sym.attrib: return
|
if 'name' not in sym.attrib: return
|
||||||
name = sym.attrib['name']
|
name = sym.attrib['name']
|
||||||
|
@ -71,12 +71,12 @@ def handle_attr_changes(sym):
|
||||||
sym.attrib.pop('text_convert')
|
sym.attrib.pop('text_convert')
|
||||||
if sym.attrib.get('text_transform'):
|
if sym.attrib.get('text_transform'):
|
||||||
sym.attrib.pop('text_transform')
|
sym.attrib.pop('text_transform')
|
||||||
|
|
||||||
# https://github.com/mapnik/mapnik/issues/807
|
# https://github.com/mapnik/mapnik/issues/807
|
||||||
justify_alignment = sym.attrib.get('justify_alignment',sym.attrib.get('justify-alignment'))
|
justify_alignment = sym.attrib.get('justify_alignment',sym.attrib.get('justify-alignment'))
|
||||||
if justify_alignment and justify_alignment == "middle":
|
if justify_alignment and justify_alignment == "middle":
|
||||||
sym.attrib['justify-alignment'] = 'center'
|
sym.attrib['justify-alignment'] = 'center'
|
||||||
|
|
||||||
minimum_distance = sym.attrib.get('min_distance')
|
minimum_distance = sym.attrib.get('min_distance')
|
||||||
if minimum_distance:
|
if minimum_distance:
|
||||||
sym.attrib['minimum-distance'] = minimum_distance
|
sym.attrib['minimum-distance'] = minimum_distance
|
||||||
|
@ -122,7 +122,7 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):
|
||||||
if not os.path.exists(input_xml):
|
if not os.path.exists(input_xml):
|
||||||
sys.stderr.write('input xml "%s" does not exist' % input_xml)
|
sys.stderr.write('input xml "%s" does not exist' % input_xml)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
pre_read = open(input_xml,'r')
|
pre_read = open(input_xml,'r')
|
||||||
if '!ENTITY' in pre_read.read() and not HAS_LXML:
|
if '!ENTITY' in pre_read.read() and not HAS_LXML:
|
||||||
sys.stderr.write('\nSorry, it appears the xml you are trying to upgrade has entities, which requires lxml (python bindings to libxml2)\n')
|
sys.stderr.write('\nSorry, it appears the xml you are trying to upgrade has entities, which requires lxml (python bindings to libxml2)\n')
|
||||||
|
@ -135,7 +135,7 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):
|
||||||
except:
|
except:
|
||||||
print 'Could not parse "%s" invalid XML' % input_xml
|
print 'Could not parse "%s" invalid XML' % input_xml
|
||||||
return
|
return
|
||||||
|
|
||||||
if hasattr(tree,'xinclude'):
|
if hasattr(tree,'xinclude'):
|
||||||
tree.xinclude()
|
tree.xinclude()
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
@ -144,12 +144,12 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):
|
||||||
if root.attrib.get('bgcolor'):
|
if root.attrib.get('bgcolor'):
|
||||||
root.attrib['background-color'] = root.attrib.get('bgcolor')
|
root.attrib['background-color'] = root.attrib.get('bgcolor')
|
||||||
root.attrib.pop('bgcolor')
|
root.attrib.pop('bgcolor')
|
||||||
|
|
||||||
# underscores to spaces for <Map ..>
|
# underscores to spaces for <Map ..>
|
||||||
underscore2dash(root)
|
underscore2dash(root)
|
||||||
|
|
||||||
root.set('minimum-version', '0.7.2')
|
root.set('minimum-version', '0.7.2')
|
||||||
|
|
||||||
# underscores to spaces for <FontSet ..>
|
# underscores to spaces for <FontSet ..>
|
||||||
fontset = root.findall('FontSet') or root.findall('*/FontSet')
|
fontset = root.findall('FontSet') or root.findall('*/FontSet')
|
||||||
for f in fontset:
|
for f in fontset:
|
||||||
|
@ -161,8 +161,8 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):
|
||||||
layers = root.findall('Layer') or root.findall('*/Layer')
|
layers = root.findall('Layer') or root.findall('*/Layer')
|
||||||
for l in layers:
|
for l in layers:
|
||||||
underscore2dash(l)
|
underscore2dash(l)
|
||||||
|
|
||||||
|
|
||||||
styles = root.findall('Style') or root.findall('*/Style')
|
styles = root.findall('Style') or root.findall('*/Style')
|
||||||
if not len(styles):
|
if not len(styles):
|
||||||
sys.stderr.write('### Warning, no styles encountered and nothing able to be upgraded!\n')
|
sys.stderr.write('### Warning, no styles encountered and nothing able to be upgraded!\n')
|
||||||
|
@ -210,7 +210,7 @@ def upgrade(input_xml,output_xml=None,indent_xml=True):
|
||||||
|
|
||||||
if indent_xml:
|
if indent_xml:
|
||||||
indent(root)
|
indent(root)
|
||||||
|
|
||||||
if output_xml:
|
if output_xml:
|
||||||
tree.write(output_xml)
|
tree.write(output_xml)
|
||||||
else:
|
else:
|
||||||
|
@ -248,20 +248,20 @@ if __name__ == "__main__":
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
if not len(args) > 0:
|
if not len(args) > 0:
|
||||||
parser.error("Please provide the path to a map.xml and a new xml to write")
|
parser.error("Please provide the path to a map.xml and a new xml to write")
|
||||||
|
|
||||||
input_xml = args[0]
|
input_xml = args[0]
|
||||||
output_xml = None
|
output_xml = None
|
||||||
|
|
||||||
if len(args) < 3 and not options.update_in_place:
|
if len(args) < 3 and not options.update_in_place:
|
||||||
if len(args) == 2:
|
if len(args) == 2:
|
||||||
output_xml = args[1]
|
output_xml = args[1]
|
||||||
|
|
||||||
if (len(args) == 1) or (input_xml == output_xml):
|
if (len(args) == 1) or (input_xml == output_xml):
|
||||||
parser.error(color_text(1,'\n\nAre you sure you want to overwrite "%s"?\nIf so, then pass --in-place to confirm.\nOtherwise pass a different filename to write an upgraded copy to.\n' % input_xml))
|
parser.error(color_text(1,'\n\nAre you sure you want to overwrite "%s"?\nIf so, then pass --in-place to confirm.\nOtherwise pass a different filename to write an upgraded copy to.\n' % input_xml))
|
||||||
|
|
||||||
print 'Upgrading "%s" to "%s"...' % (input_xml,output_xml)
|
print 'Upgrading "%s" to "%s"...' % (input_xml,output_xml)
|
||||||
upgrade(input_xml,output_xml=output_xml,indent_xml=options.indent_xml)
|
upgrade(input_xml,output_xml=output_xml,indent_xml=options.indent_xml)
|
||||||
|
|
||||||
elif len(args) == 1:
|
elif len(args) == 1:
|
||||||
print 'Upgrading "%s"...' % (input_xml)
|
print 'Upgrading "%s"...' % (input_xml)
|
||||||
upgrade(input_xml,output_xml=output_xml,indent_xml=options.indent_xml)
|
upgrade(input_xml,output_xml=output_xml,indent_xml=options.indent_xml)
|
||||||
|
|
|
@ -41,7 +41,7 @@ def name2expr(sym):
|
||||||
name = '[%s]' % name
|
name = '[%s]' % name
|
||||||
sym.attrib.pop('name')
|
sym.attrib.pop('name')
|
||||||
sym._setText(name)
|
sym._setText(name)
|
||||||
|
|
||||||
def fixup_pointsym(sym):
|
def fixup_pointsym(sym):
|
||||||
if sym.attrib.get('width'):
|
if sym.attrib.get('width'):
|
||||||
sym.attrib.pop('width')
|
sym.attrib.pop('width')
|
||||||
|
@ -61,10 +61,10 @@ def fixup_sym_attributes(sym):
|
||||||
sym.clear() # remove CssParameter elements
|
sym.clear() # remove CssParameter elements
|
||||||
for k,v in attrib.items(): # insert attributes instead
|
for k,v in attrib.items(): # insert attributes instead
|
||||||
sym.attrib[k] = v
|
sym.attrib[k] = v
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# map_xml_file: outdated stylesheet file
|
# map_xml_file: outdated stylesheet file
|
||||||
# output_file: new stylesheet file
|
# output_file: new stylesheet file
|
||||||
|
@ -74,7 +74,7 @@ if __name__ == "__main__":
|
||||||
print >> sys.stderr,'Usage: %s <map_xml_file> <output_file> <includes_folder>' % sys.argv[0]
|
print >> sys.stderr,'Usage: %s <map_xml_file> <output_file> <includes_folder>' % sys.argv[0]
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
xml = sys.argv[1]
|
xml = sys.argv[1]
|
||||||
|
|
||||||
if sys.argv[3] is not None:
|
if sys.argv[3] is not None:
|
||||||
includes_folder = sys.argv[3]
|
includes_folder = sys.argv[3]
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ if __name__ == "__main__":
|
||||||
# This dummy tree expands the entities that I found and puts them
|
# This dummy tree expands the entities that I found and puts them
|
||||||
# in a dictionary (entity) => resolved_entity
|
# in a dictionary (entity) => resolved_entity
|
||||||
# NOTE: `findall' makes the script very slow
|
# NOTE: `findall' makes the script very slow
|
||||||
|
|
||||||
# First get the entities declared in the header
|
# First get the entities declared in the header
|
||||||
temp_xml = ''.join([good_doctype, dummy_map % '<dummy_tag></dummy_tag>'])
|
temp_xml = ''.join([good_doctype, dummy_map % '<dummy_tag></dummy_tag>'])
|
||||||
expanded_tree = objectify.parse(StringIO.StringIO(temp_xml))
|
expanded_tree = objectify.parse(StringIO.StringIO(temp_xml))
|
||||||
|
@ -135,7 +135,7 @@ if __name__ == "__main__":
|
||||||
# Tree to be updated to be mapnik compliant
|
# Tree to be updated to be mapnik compliant
|
||||||
tree = objectify.parse(StringIO.StringIO(fixed_xml_string), parser=parser)
|
tree = objectify.parse(StringIO.StringIO(fixed_xml_string), parser=parser)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
for layer in layer_entities:
|
for layer in layer_entities:
|
||||||
file = open("%s/%s" % (includes_folder, doctype_entities[layer]))
|
file = open("%s/%s" % (includes_folder, doctype_entities[layer]))
|
||||||
layer_xml_string = file.read()
|
layer_xml_string = file.read()
|
||||||
|
@ -177,7 +177,7 @@ if __name__ == "__main__":
|
||||||
if hasattr(rule,'BuildingSymbolizer') :
|
if hasattr(rule,'BuildingSymbolizer') :
|
||||||
for sym in rule.BuildingSymbolizer:
|
for sym in rule.BuildingSymbolizer:
|
||||||
fixup_sym_attributes(sym)
|
fixup_sym_attributes(sym)
|
||||||
|
|
||||||
updated_xml = etree.tostring(tree,
|
updated_xml = etree.tostring(tree,
|
||||||
pretty_print=True,
|
pretty_print=True,
|
||||||
xml_declaration=True,
|
xml_declaration=True,
|
||||||
|
@ -186,9 +186,9 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# Insert the original doctype declaration
|
# Insert the original doctype declaration
|
||||||
fixed_updated_xml = re.sub(r'(?ims)^.*DOCTYPE.*\[.*\]\>', good_doctype, updated_xml)
|
fixed_updated_xml = re.sub(r'(?ims)^.*DOCTYPE.*\[.*\]\>', good_doctype, updated_xml)
|
||||||
|
|
||||||
output_file = open(sys.argv[2], 'w')
|
output_file = open(sys.argv[2], 'w')
|
||||||
output_file.write(fixed_updated_xml)
|
output_file.write(fixed_updated_xml)
|
||||||
output_file.close()
|
output_file.close()
|
||||||
|
|
||||||
# print fixed_updated_xml
|
# print fixed_updated_xml
|
||||||
|
|
Loading…
Reference in a new issue