XML deserialization support for a raster_symbolizer with a colorizer

This commit is contained in:
Alberto Valverde 2010-03-12 14:49:34 +00:00
parent a7ea07ee0d
commit 807881c47a
2 changed files with 69 additions and 0 deletions

View file

@ -37,6 +37,7 @@
#include <mapnik/filter_factory.hpp>
#include <mapnik/path_expression_grammar.hpp>
#include <mapnik/raster_colorizer.hpp>
// boost
#include <boost/optional.hpp>
@ -90,6 +91,7 @@ namespace mapnik
void parse_polygon_symbolizer( rule_type & rule, ptree const & sym);
void parse_building_symbolizer( rule_type & rule, ptree const & sym );
void parse_raster_symbolizer( rule_type & rule, ptree const & sym );
void parse_raster_colorizer(raster_colorizer_ptr const& rc, ptree const& node );
void parse_markers_symbolizer( rule_type & rule, ptree const & sym );
void ensure_font_face( const std::string & face_name );
@ -1492,6 +1494,12 @@ namespace mapnik
"parameter '" + css_name + "'");
}
}
else if (css_tag.first == "RasterColorizer")
{
raster_colorizer_ptr colorizer(new raster_colorizer());
raster_sym.set_colorizer(colorizer);
parse_raster_colorizer(colorizer, css_tag.second);
}
else if (css_tag.first != "<xmlcomment>" &&
css_tag.first != "<xmlattr>" )
{
@ -1507,6 +1515,45 @@ namespace mapnik
throw;
}
}
void map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc,
ptree const& node )
{
try
{
ptree::const_iterator cbIter = node.begin();
ptree::const_iterator endCb = node.end();
for(; cbIter != endCb; ++cbIter)
{
ptree::value_type const& cb_tag = *cbIter;
ptree const & cb = cbIter->second;
if (cb_tag.first == "ColorBand")
{
std::string value_s = get_attr<string>(cb, "value");
float value;
std::stringstream(value_s) >> value;
optional<color> c = get_opt_attr<color>(cb, "color");
if (!c) {
throw config_error("missing color");
}
unsigned midpoints = get_attr(cb, "midpoints", 0);
rc->append_band(value, *c, midpoints);
}
else if (cb_tag.first != "<xmlcomment>" &&
cb_tag.first != "<xmlattr>" )
{
throw config_error(std::string("Unknown child node. ") +
"Expected 'ColorBand' but got '" + cb_tag.first + "'");
}
}
}
catch (const config_error & ex)
{
ex.append_context("in RasterColorizer");
throw;
}
}
void map_parser::ensure_font_face( const std::string & face_name )
{

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Map>
<Style name="elevation">
<Rule>
<RasterSymbolizer>
<RasterColorizer>
<ColorBand value="-200" color="rgb(0,0,0)" label="&lt;0"></ColorBand>
<ColorBand value="0" color="rgb(0,60,20)" midpoints="199"></ColorBand>
<ColorBand value="100" color="rgb(0,200,10)" midpoints="199"></ColorBand>
<ColorBand value="300" color="rgb(234,234,10)" midpoints="199"></ColorBand>
<ColorBand value="500" color="rgb(214,185,10)" midpoints="199"></ColorBand>
<ColorBand value="700" color="rgb(195,136,20)" midpoints="199"></ColorBand>
<ColorBand value="900" color="rgb(175,88,29)" midpoints="199"></ColorBand>
<ColorBand value="1400" color="rgb(133,72,34)" midpoints="499"></ColorBand>
<ColorBand value="2500" color="rgb(200,200,200)" midpoints="1099"></ColorBand>
<ColorBand value="3400" color="rgb(255,255,255)" midpoints="999"></ColorBand>
<ColorBand value="10000" color="rgb(255,255,255)"></ColorBand>
</RasterColorizer>
</RasterSymbolizer>
</Rule>
</Style>
</Map>