Merge branch 'master' into conv_simplify

This commit is contained in:
artemp 2012-09-27 08:54:32 +01:00
commit d7abfc267b
34 changed files with 174 additions and 142 deletions

View file

@ -153,6 +153,14 @@ If you see bits of code around that do not follow these please don't hesitate to
// more...
}
#### Prefer `empty()` over `size() == 0` if container supports it
This avoids implicit conversions to bool and reduces compiler warnings.
if (container.empty()) // please
if (container.size() == 0) // no
### Other C++ style resources

View file

@ -665,7 +665,9 @@ void csv_datasource::parse_csv(T & stream,
}
}
// now, add all values as attributes
// now, add attributes, skipping any WKT or JSON fiels
if ((has_wkt_field) && (i == wkt_idx)) continue;
if ((has_json_field) && (i == json_idx)) continue;
/* First we detect likely strings, then try parsing likely numbers,
finally falling back to string type
* We intentionally do not try to detect boolean or null types

View file

@ -62,8 +62,8 @@ raster_datasource::raster_datasource(parameters const& 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");
@ -100,8 +100,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)
{

View file

@ -83,7 +83,8 @@ void agg_renderer<T>::process(raster_symbolizer const& sym,
if (scaling_method == SCALING_BILINEAR8)
{
scale_image_bilinear8<image_data_32>(target.data_,source->data_, 0.0, 0.0);
} else
}
else
{
double scaling_ratio = ext.width() / source->data_.width();
scale_image_agg<image_data_32>(target.data_,

View file

@ -1154,7 +1154,7 @@ void map_parser::parse_text_symbolizer(rule & rule, xml_node const& sym)
placement_finder->defaults.from_xml(sym, fontsets_);
}
if (strict_ &&
!placement_finder->defaults.format.fontset->size())
!placement_finder->defaults.format.fontset)
{
ensure_font_face(placement_finder->defaults.format.face_name);
}
@ -1183,7 +1183,7 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
}
placement_finder->defaults.from_xml(sym, fontsets_);
if (strict_ &&
!placement_finder->defaults.format.fontset->size())
!placement_finder->defaults.format.fontset)
{
ensure_font_face(placement_finder->defaults.format.face_name);
}

View file

@ -47,11 +47,11 @@
namespace mapnik {
void reproject_and_scale_raster(raster & target, raster const& source,
proj_transform const& prj_trans,
double offset_x, double offset_y,
unsigned mesh_size,
double filter_radius,
scaling_method_e scaling_method)
proj_transform const& prj_trans,
double offset_x, double offset_y,
unsigned mesh_size,
double filter_radius,
scaling_method_e scaling_method)
{
CoordTransform ts(source.data_.width(), source.data_.height(),
source.ext_);
@ -160,10 +160,10 @@ void reproject_and_scale_raster(raster & target, raster const& source,
tt.forward(polygon+6, polygon+7);
rasterizer.reset();
rasterizer.move_to_d(polygon[0]-1, polygon[1]-1);
rasterizer.line_to_d(polygon[2]+1, polygon[3]-1);
rasterizer.line_to_d(polygon[4]+1, polygon[5]+1);
rasterizer.line_to_d(polygon[6]-1, polygon[7]+1);
rasterizer.move_to_d(std::floor(polygon[0]), std::floor(polygon[1]));
rasterizer.line_to_d(std::floor(polygon[2]), std::floor(polygon[3]));
rasterizer.line_to_d(std::floor(polygon[4]), std::floor(polygon[5]));
rasterizer.line_to_d(std::floor(polygon[6]), std::floor(polygon[7]));
unsigned x0 = i * mesh_size;
unsigned y0 = j * mesh_size;

View file

@ -0,0 +1,7 @@
x,y,line
0,0,"
many
lines
of text
with unix newlines
"
1 x y line
2 0 0 many lines of text with unix newlines

View file

@ -0,0 +1,2 @@
x,y,line
0,0,"\r\nmany\r\nlines\r\nof text\r\nwith unix newlines\r\n"
1 x y line
2 0 0 \r\nmany\r\nlines\r\nof text\r\nwith unix newlines\r\n

View file

@ -0,0 +1,7 @@
x,y,line
0,0,"
many
lines
of text
with unix newlines
"
1 x y line
2 0 0 many lines of text with unix newlines

View file

@ -0,0 +1,2 @@
x,y,line
0,0,"many\n lines\n of text\n with unix newlines"
1 x y line
2 0 0 many\n lines\n of text\n with unix newlines

View file

@ -0,0 +1,7 @@
x,y,line
0,0,"
many
lines
of text
with unix newlines
"
1 x y line
2 0 0 many lines of text with unix newlines

View file

@ -0,0 +1,2 @@
x,y,line
0,0,"many\n lines\n of text\n with unix newlines"
1 x y line
2 0 0 many\n lines\n of text\n with unix newlines

View file

@ -6,6 +6,8 @@ from nose.tools import *
from utilities import execution_path
import os, mapnik
# make the tests silent since we intentially test error conditions that are noisy
mapnik.logger.set_severity(mapnik.severity_type.None)
def setup():
# All of the paths used are relative, if we run the tests
@ -137,9 +139,9 @@ if 'csv' in mapnik.DatasourceCache.plugin_names():
def test_wkt_field(**kwargs):
ds = get_csv_ds('wkt.csv')
eq_(len(ds.fields()),2)
eq_(ds.fields(),['type','WKT'])
eq_(ds.field_types(),['str','str'])
eq_(len(ds.fields()),1)
eq_(ds.fields(),['type'])
eq_(ds.field_types(),['str'])
fs = ds.all_features()
eq_(len(fs[0].geometries()),1)
eq_(fs[0].geometries()[0].type(),mapnik.DataGeometryType.Point)
@ -396,9 +398,9 @@ if 'csv' in mapnik.DatasourceCache.plugin_names():
eq_(feat['Name'],u"Winthrop, WA")
def validate_geojson_datasource(ds):
eq_(len(ds.fields()),2)
eq_(ds.fields(),['type','GeoJSON'])
eq_(ds.field_types(),['str','str'])
eq_(len(ds.fields()),1)
eq_(ds.fields(),['type'])
eq_(ds.field_types(),['str'])
fs = ds.all_features()
eq_(len(fs[0].geometries()),1)
eq_(fs[0].geometries()[0].type(),mapnik.DataGeometryType.Point)

View file

@ -3,7 +3,10 @@
from nose.tools import *
import os,sys
import mapnik
import json
try:
import json
except ImportError:
import simplejson as json
chars = [
{

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path, save_data, contains_word
from utilities import execution_path, contains_word
import os, mapnik
@ -40,8 +40,6 @@ def test_multi_tile_policy():
im = mapnik.Image(_map.width, _map.height)
mapnik.render(_map, im)
save_data('test_multi_tile_policy.png', im.tostring('png'))
# test green chunk
eq_(im.view(0,64,1,1).tostring(), '\x00\xff\x00\xff')
eq_(im.view(127,64,1,1).tostring(), '\x00\xff\x00\xff')

View file

@ -1,56 +0,0 @@
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path
import os, mapnik
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('.'))
if 'gdal' in mapnik.DatasourceCache.plugin_names():
def test_map_alpha_compare():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/raster-alpha.xml')
m.zoom_all()
actual = '/tmp/mapnik-raster-alpha.png'
expected = 'images/support/raster-alpha.png'
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
im.save(actual)
expected_im = mapnik.Image.open(expected)
eq_(im.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected))
def test_map_alpha_gradient_compare():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/raster-alpha-gradient.xml')
m.zoom_all()
actual = '/tmp/mapnik-raster-alpha-gradient.png'
expected = 'images/support/raster-alpha-gradient.png'
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
im.save(actual)
expected_im = mapnik.Image.open(expected)
eq_(im.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected))
# there should be no gray edges on raster
# https://github.com/mapnik/mapnik/issues/1471
def test_edge_scaling_with_nodata():
m = mapnik.Map(600,400)
mapnik.load_map(m,'../data/good_maps/raster-nodata-edge.xml')
m.zoom_all()
actual = '/tmp/mapnik-raster-nodata-edge.png'
expected = 'images/support/raster-nodata-edge.png'
im = mapnik.Image(m.width,m.height)
mapnik.render(m,im)
im.save(actual)
expected_im = mapnik.Image.open(expected)
eq_(im.tostring(),expected_im.tostring(), 'failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected))
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from nose.tools import *
from utilities import execution_path, save_data, contains_word
from utilities import execution_path, contains_word
import os, mapnik
@ -51,8 +51,6 @@ def test_dataraster_coloring():
im = mapnik.Image(_map.width,_map.height)
mapnik.render(_map, im)
# save a png somewhere so we can see it
save_data('test_dataraster_coloring.png', im.tostring('png'))
imdata = im.tostring()
# we have some values in the [20,30) interval so check that they're colored
assert contains_word('\xff\xff\x00\xff', imdata)
@ -135,8 +133,6 @@ def test_raster_with_alpha_blends_correctly_with_background():
mim = mapnik.Image(WIDTH, HEIGHT)
mapnik.render(map, mim)
save_data('test_raster_with_alpha_blends_correctly_with_background.png',
mim.tostring('png'))
imdata = mim.tostring()
# All white is expected
assert contains_word('\xff\xff\xff\xff', imdata)
@ -166,8 +162,6 @@ def test_raster_warping():
im = mapnik.Image(_map.width,_map.height)
mapnik.render(_map, im)
# save a png somewhere so we can see it
save_data('test_raster_warping.png', im.tostring('png'))
imdata = im.tostring()
assert contains_word('\xff\xff\x00\xff', imdata)
@ -195,9 +189,6 @@ def test_raster_warping_does_not_overclip_source():
im = mapnik.Image(_map.width,_map.height)
mapnik.render(_map, im)
# save a png somewhere so we can see it
save_data('test_raster_warping_does_not_overclip_source.png',
im.tostring('png'))
assert im.view(0,200,1,1).tostring()=='\xff\xff\x00\xff'
if __name__ == "__main__":

View file

@ -15,20 +15,6 @@ class TodoPlugin(ErrorClassPlugin):
todo = ErrorClass(Todo, label='TODO', isfailure=False)
def save_data(filename, data, key='MAPNIK_TEST_DATA_DIR'):
"""Saves bytestring 'data' into os.environ[key]/filename if
key in os.environ"""
if key in os.environ:
dir = os.environ[key]
if not os.path.exists(dir):
os.makedirs(dir)
fname = os.path.join(dir, filename)
f = open(fname, 'w')
try:
f.write(data)
finally:
f.close()
def contains_word(word, bytestring_):
"""
Checks that a bytestring contains a given word. len(bytestring) should be

View file

@ -1,2 +1 @@
*-agg.png
*-out.xml

View file

@ -1,3 +1,2 @@
rm -f images/*-agg.png
rm -f xml_output/*-out.xml

View file

@ -49,7 +49,7 @@ def compare(actual, expected):
passed += 1
return diff
def summary():
def summary(generate=False):
global errors
global passed
print "-"*80
@ -57,7 +57,13 @@ def summary():
if len(errors) != 0:
for error in errors:
if (error[0] is None):
print "Could not verify %s: No reference image found!" % error[1]
if generate:
actual = open(error[1],'r').read()
open(error[2],'wb').write(actual)
print "Generating reference image: '%s'" % error[2]
continue
else:
print "Could not verify %s: No reference image found!" % error[1]
else:
print "Failed: %d different pixels:\n\t%s (actual)\n\t%s (expected)" % error
sys.exit(1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 202 KiB

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

View file

@ -11,7 +11,7 @@
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>white</StyleName>
<Datasource>
<Parameter name="file">../raster/white-alpha.tiff</Parameter>
<Parameter name="file">../../data/raster/white-alpha.tiff</Parameter>
<Parameter name="type">gdal</Parameter>
</Datasource>
</Layer>

View file

@ -11,7 +11,7 @@
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>transp</StyleName>
<Datasource>
<Parameter name="file">../raster/transp.tiff</Parameter>
<Parameter name="file">../../data/raster/transp.tiff</Parameter>
<Parameter name="type">gdal</Parameter>
</Datasource>
</Layer>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="blue">
<Style name="transp">
<Rule>
<RasterSymbolizer opacity="1" scaling="bilinear" />
</Rule>
</Style>
<Layer name="transp"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>transp</StyleName>
<Datasource>
<Parameter name="file">../../data/raster/transp.tiff</Parameter>
<Parameter name="type">raster</Parameter>
<Parameter name="extent">0,0,256,256</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="red">
<Style name="white">
<Rule>
<RasterSymbolizer opacity="1" scaling="bilinear" comp-op="src-over"/>
</Rule>
</Style>
<Layer name="white"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>white</StyleName>
<Datasource>
<Parameter name="file">../../data/raster/white-alpha.tiff</Parameter>
<Parameter name="type">raster</Parameter>
<Parameter name="extent">1001859.9561,5922814.94334,1021141.75555,5942096.74279</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -12,7 +12,7 @@
<StyleName>style</StyleName>
<Datasource>
<!-- https://github.com/mapnik/mapnik/issues/1471 -->
<Parameter name="file">../raster/nodata-edge.tif</Parameter>
<Parameter name="file">../../data/raster/nodata-edge.tif</Parameter>
<Parameter name="type">gdal</Parameter>
</Datasource>
</Layer>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over" background-color="#F0CCAC">
<Style name="style" >
<Rule>
<RasterSymbolizer opacity="1" />
</Rule>
</Style>
<Layer name="raster"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>style</StyleName>
<Datasource>
<!-- https://github.com/mapnik/mapnik/issues/1471 -->
<Parameter name="file">../../data/raster/nodata-edge.tif</Parameter>
<Parameter name="type">raster</Parameter>
<Parameter name="extent">-12329035.765216826,4508650.398543958,-12328653.027947057,4508957.346255356</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -7,8 +7,7 @@ import os.path
from compare import compare, summary
defaults = {
'sizes': [(500, 100)],
'bbox': mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
'sizes': [(500, 100)]
}
sizes_many_in_big_range = [(800, 100), (600, 100), (400, 100),
@ -18,33 +17,39 @@ sizes_few_square = [(800, 800), (600, 600), (400, 400), (200, 200)]
sizes_many_in_small_range = [(490, 100), (495, 100), (497, 100), (498, 100),
(499, 100), (500, 100), (501, 100), (502, 100), (505, 100), (510, 100)]
default_text_box = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
dirname = os.path.dirname(__file__)
files = [
{'name': "list", 'sizes': sizes_many_in_big_range},
{'name': "simple", 'sizes': sizes_many_in_big_range},
{'name': "lines-1", 'sizes': sizes_few_square},
{'name': "lines-2", 'sizes': sizes_few_square},
{'name': "lines-3", 'sizes': sizes_few_square},
{'name': "lines-shield", 'sizes': sizes_few_square},
{'name': "simple-E"},
{'name': "simple-NE"},
{'name': "simple-NW"},
{'name': "simple-N"},
{'name': "simple-SE"},
{'name': "simple-SW"},
{'name': "simple-S"},
{'name': "simple-W"},
{'name': "formatting-1"},
{'name': "formatting-2"},
{'name': "formatting-3"},
{'name': "formatting-4"},
{'name': "expressionformat"},
{'name': "shieldsymbolizer-1", 'sizes': sizes_many_in_small_range},
{'name': "rtl-point", 'sizes': [(200, 200)]},
{'name': "jalign-auto", 'sizes': [(200, 200)]},
{'name': "line-offset", 'sizes':[(900, 250)],
'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
{'name': "list", 'sizes': sizes_many_in_big_range,'bbox':default_text_box},
{'name': "simple", 'sizes': sizes_many_in_big_range,'bbox':default_text_box},
{'name': "lines-1", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "lines-2", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "lines-3", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "lines-shield", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "simple-E", 'bbox':mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)},
{'name': "simple-NE",'bbox':default_text_box},
{'name': "simple-NW",'bbox':default_text_box},
{'name': "simple-N",'bbox':default_text_box},
{'name': "simple-SE",'bbox':default_text_box},
{'name': "simple-SW",'bbox':default_text_box},
{'name': "simple-S",'bbox':default_text_box},
{'name': "simple-W",'bbox':default_text_box},
{'name': "formatting-1",'bbox':default_text_box},
{'name': "formatting-2",'bbox':default_text_box},
{'name': "formatting-3",'bbox':default_text_box},
{'name': "formatting-4",'bbox':default_text_box},
{'name': "expressionformat",'bbox':default_text_box},
{'name': "shieldsymbolizer-1", 'sizes': sizes_many_in_small_range,'bbox':default_text_box},
{'name': "rtl-point", 'sizes': [(200, 200)],'bbox':default_text_box},
{'name': "jalign-auto", 'sizes': [(200, 200)],'bbox':default_text_box},
{'name': "line-offset", 'sizes':[(900, 250)],'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
{'name': "tiff-alpha-gdal", 'sizes':[(600,400)]},
{'name': "tiff-alpha-raster", 'sizes':[(600,400)]},
{'name': "tiff-alpha-gradient-gdal", 'sizes':[(600,400)]},
{'name': "tiff-nodata-edge-gdal", 'sizes':[(600,400)]},
{'name': "tiff-nodata-edge-raster", 'sizes':[(600,400)]},
]
def render(filename, width, height, bbox, quiet=False):
@ -89,7 +94,7 @@ if __name__ == "__main__":
config = dict(defaults)
config.update(f)
for size in config['sizes']:
m = render(config['name'], size[0], size[1], config['bbox'], quiet=quiet)
m = render(config['name'], size[0], size[1], config.get('bbox'), quiet=quiet)
mapnik.save_map(m, os.path.join(dirname, 'xml_output', "%s-out.xml" % config['name']))
summary()
summary(generate=False)