grid renderer: remove old method and fix tests
This commit is contained in:
parent
4502ef2c83
commit
f3a824c2cc
4 changed files with 4 additions and 130 deletions
|
@ -599,17 +599,6 @@ BOOST_PYTHON_MODULE(_mapnik)
|
|||
">>> clear_cache()\n"
|
||||
);
|
||||
|
||||
#if defined(GRID_RENDERER)
|
||||
def("render_grid",&mapnik::render_grid,
|
||||
( arg("map"),
|
||||
arg("layer"),
|
||||
args("key")="__id__",
|
||||
arg("resolution")=4,
|
||||
arg("fields")=boost::python::list()
|
||||
)
|
||||
);
|
||||
#endif
|
||||
|
||||
def("render_to_file",&render_to_file1,
|
||||
"\n"
|
||||
"Render Map to file using explicit image type.\n"
|
||||
|
|
|
@ -394,82 +394,6 @@ void render_layer_for_grid(mapnik::Map const& map,
|
|||
ren.apply(layer,attributes);
|
||||
}
|
||||
|
||||
/* old, original impl - to be removed after further testing
|
||||
* grid object is created on the fly at potentially reduced size
|
||||
*/
|
||||
boost::python::dict render_grid(mapnik::Map const& map,
|
||||
unsigned layer_idx, // layer
|
||||
std::string const& key, // key_name
|
||||
unsigned int step, // resolution
|
||||
boost::python::list const& fields)
|
||||
{
|
||||
|
||||
std::vector<mapnik::layer> const& layers = map.layers();
|
||||
std::size_t layer_num = layers.size();
|
||||
if (layer_idx >= layer_num) {
|
||||
std::ostringstream s;
|
||||
s << "Zero-based layer index '" << layer_idx << "' not valid, only '"
|
||||
<< layer_num << "' layers are in map\n";
|
||||
throw std::runtime_error(s.str());
|
||||
}
|
||||
|
||||
unsigned int grid_width = map.width()/step;
|
||||
unsigned int grid_height = map.height()/step;
|
||||
|
||||
// TODO - no need to pass step here
|
||||
mapnik::grid grid(grid_width,grid_height,key,step);
|
||||
|
||||
// convert python list to std::set
|
||||
boost::python::ssize_t num_fields = boost::python::len(fields);
|
||||
for(boost::python::ssize_t i=0; i<num_fields; i++) {
|
||||
boost::python::extract<std::string> name(fields[i]);
|
||||
if (name.check()) {
|
||||
grid.add_property_name(name());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "list of field names must be strings";
|
||||
throw mapnik::value_error(s.str());
|
||||
}
|
||||
}
|
||||
|
||||
// copy property names
|
||||
std::set<std::string> attributes = grid.property_names();
|
||||
// todo - make this a static constant
|
||||
std::string known_id_key = "__id__";
|
||||
if (attributes.find(known_id_key) != attributes.end())
|
||||
{
|
||||
attributes.erase(known_id_key);
|
||||
}
|
||||
|
||||
std::string join_field = grid.get_key();
|
||||
if (known_id_key != join_field &&
|
||||
attributes.find(join_field) == attributes.end())
|
||||
{
|
||||
attributes.insert(join_field);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::grid_renderer<mapnik::grid> ren(map,grid,1.0,0,0);
|
||||
mapnik::layer const& layer = layers[layer_idx];
|
||||
ren.apply(layer,attributes);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
bool add_features = false;
|
||||
if (num_fields > 0)
|
||||
add_features = true;
|
||||
// build dictionary and return to python
|
||||
boost::python::dict json;
|
||||
grid_encode_utf(grid,json,add_features,1);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -76,14 +76,6 @@ void render_layer_for_grid(const mapnik::Map& map,
|
|||
unsigned layer_idx, // TODO - layer by name or index
|
||||
boost::python::list const& fields);
|
||||
|
||||
/* old, original impl - to be removed after further testing
|
||||
* grid object is created on the fly at potentially reduced size
|
||||
*/
|
||||
boost::python::dict render_grid(const mapnik::Map& map,
|
||||
unsigned layer_idx, // layer
|
||||
std::string const& key, // key_name
|
||||
unsigned int step, // resolution
|
||||
boost::python::list const& fields);
|
||||
}
|
||||
|
||||
#endif // MAPNIK_PYTHON_BINDING_GRID_UTILS_INCLUDED
|
||||
|
|
|
@ -61,15 +61,6 @@ if mapnik.has_grid_renderer():
|
|||
val += '\n\t%s\n\t%s' % (g1_file,g2_expected)
|
||||
return val
|
||||
|
||||
# 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": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " !!! ### ", " !!!!! ##### ", " !!!!! ##### ", " !!! ### ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " $$$$ %%%% ", " $$$$$ %%%%% ", " $$$$$ %%%%% ", " $$$ %%% ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
|
||||
# now using svg rendering
|
||||
grid_correct_old2 = {"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_old3 = {"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"]}
|
||||
|
||||
# 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"]}
|
||||
|
||||
|
@ -130,32 +121,9 @@ if mapnik.has_grid_renderer():
|
|||
m.layers.append(lyr)
|
||||
return m
|
||||
|
||||
def test_render_grid_old():
|
||||
""" test old method """
|
||||
width,height = 256,256
|
||||
symb = mapnik.PointSymbolizer(mapnik.PathExpression('../data/images/dummy.png'))
|
||||
sym = mapnik.MarkersSymbolizer()
|
||||
sym.width = mapnik.Expression('10')
|
||||
sym.height = mapnik.Expression('10')
|
||||
m = create_grid_map(width,height,sym)
|
||||
#print mapnik.save_map_to_string(m)
|
||||
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))
|
||||
grid = mapnik.render_grid(m,0,key='Name',resolution=4,fields=['Name'])
|
||||
eq_(grid,grid_correct_old3,show_grids('old-markers',grid,grid_correct_old3))
|
||||
eq_(resolve(grid,0,0),None)
|
||||
|
||||
# check every pixel of the nw symbol
|
||||
expected = {"Name": "North West"}
|
||||
|
||||
# top row
|
||||
eq_(resolve(grid,23,9),expected)
|
||||
eq_(resolve(grid,23,10),expected)
|
||||
eq_(resolve(grid,23,11),expected)
|
||||
|
||||
def test_render_grid_new():
|
||||
""" test old against new"""
|
||||
def test_render_grid():
|
||||
""" test render_grid method"""
|
||||
width,height = 256,256
|
||||
sym = mapnik.MarkersSymbolizer()
|
||||
sym.width = mapnik.Expression('10')
|
||||
|
@ -327,7 +295,8 @@ if mapnik.has_grid_renderer():
|
|||
|
||||
def test_point_symbolizer_grid():
|
||||
width,height = 256,256
|
||||
sym = mapnik.PointSymbolizer(mapnik.PathExpression('../data/images/dummy.png'))
|
||||
sym = mapnik.PointSymbolizer()
|
||||
sym.file = '../data/images/dummy.png'
|
||||
m = create_grid_map(width,height,sym)
|
||||
ul_lonlat = mapnik.Coord(142.30,-38.20)
|
||||
lr_lonlat = mapnik.Coord(143.40,-38.80)
|
||||
|
|
Loading…
Add table
Reference in a new issue