diff --git a/CHANGELOG.md b/CHANGELOG.md index 63bcea19b..2e44500b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ For a complete change history, see the git log. Not yet released +- Increased grid encoding performance (#1315) + - Added support for overriding fill, stroke, and opacity for svg markers using marker properties - Added support for setting opacity dynamically on images in polygon pattern and markers symbolizers diff --git a/bindings/python/python_grid_utils.cpp b/bindings/python/python_grid_utils.cpp index a837b5dc2..b1b5fa393 100644 --- a/bindings/python/python_grid_utils.cpp +++ b/bindings/python/python_grid_utils.cpp @@ -233,9 +233,50 @@ void write_features(T const& grid_type, boost::python::dict& feature_data, std::vector const& key_order) { - std::string const& key = grid_type.get_key(); - std::set const& attributes = grid_type.property_names(); typename T::feature_type const& g_features = grid_type.get_grid_features(); + if (g_features.size() <= 0) + { + return; + } + + std::set const& attributes = grid_type.property_names(); + typename T::feature_type::const_iterator feat_end = g_features.end(); + BOOST_FOREACH ( std::string const& key_item, key_order ) + { + if (key_item.empty()) + { + continue; + } + + typename T::feature_type::const_iterator feat_itr = g_features.find(key_item); + if (feat_itr == feat_end) + { + continue; + } + + bool found = false; + boost::python::dict feat; + mapnik::feature_ptr feature = feat_itr->second; + BOOST_FOREACH ( std::string const& attr, attributes ) + { + if (attr == "__id__") + { + feat[attr.c_str()] = feature->id(); + } + else if (feature->has_key(attr)) + { + found = true; + feat[attr.c_str()] = feature->get(attr); + } + } + + if (found) + { + feature_data[feat_itr->first] = feat; + } + } +/* std::string const& key = grid_type.get_key(); + std::set const& attributes = grid_type.property_names(); typename T::feature_type::const_iterator feat_itr = g_features.begin(); typename T::feature_type::const_iterator feat_end = g_features.end(); bool include_key = (attributes.find(key) != attributes.end()); @@ -298,6 +339,7 @@ void write_features(T const& grid_type, MAPNIK_LOG_DEBUG(bindings) << "write_features: Should not get here: key " << key << " not found in grid feature properties"; } } +*/ } template diff --git a/tests/python_tests/render_grid_test.py b/tests/python_tests/render_grid_test.py index f42d4a6df..1b5147081 100644 --- a/tests/python_tests/render_grid_test.py +++ b/tests/python_tests/render_grid_test.py @@ -194,7 +194,7 @@ grid_feat_id = {'keys': ['', '3', '4', '2', '1'], 'data': {'1': {'Name': 'South 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"}, "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"]} def test_render_grid3(): """ test using feature id""" @@ -225,10 +225,10 @@ def test_render_grid3(): # resolve some center points in the # resampled view utf5 = grid_view.encode('utf',resolution=4) - eq_(resolve(utf5,25,10),{"Name": "North West"}) - eq_(resolve(utf5,25,46),{"Name": "North East"}) - eq_(resolve(utf5,38,10),{"Name": "South West"}) - eq_(resolve(utf5,38,46),{"Name": "South East"}) + eq_(resolve(utf5,25,10),{"Name": "North West","__id__": 3}) + eq_(resolve(utf5,25,46),{"Name": "North East","__id__": 4}) + eq_(resolve(utf5,38,10),{"Name": "South West","__id__": 2}) + eq_(resolve(utf5,38,46),{"Name": "South East","__id__": 1}) def gen_grid_for_id(pixel_key): @@ -310,7 +310,7 @@ def test_line_rendering(): m.zoom_all() #mapnik.render_to_file(m,'test.png') 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=['Name']) utf1 = grid.encode() eq_(utf1,line_expected,show_grids('line',utf1,line_expected))