Changeset 1687

Show
Ignore:
Timestamp:
03/12/10 09:49:34 (5 months ago)
Author:
alberto
Message:

XML deserialization support for a raster_symbolizer with a colorizer

Location:
trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/load_map.cpp

    r1609 r1687  
    3838#include <mapnik/filter_factory.hpp> 
    3939#include <mapnik/path_expression_grammar.hpp> 
     40#include <mapnik/raster_colorizer.hpp> 
    4041 
    4142// boost 
     
    9192         void parse_building_symbolizer( rule_type & rule, ptree const & sym ); 
    9293         void parse_raster_symbolizer( rule_type & rule, ptree const & sym ); 
     94         void parse_raster_colorizer(raster_colorizer_ptr const& rc, ptree const& node ); 
    9395         void parse_markers_symbolizer( rule_type & rule, ptree const & sym ); 
    9496 
     
    14931495                    } 
    14941496                } 
     1497                else if (css_tag.first == "RasterColorizer") 
     1498                { 
     1499                   raster_colorizer_ptr colorizer(new raster_colorizer()); 
     1500                   raster_sym.set_colorizer(colorizer); 
     1501                   parse_raster_colorizer(colorizer, css_tag.second); 
     1502                } 
    14951503                else if (css_tag.first != "<xmlcomment>" && 
    14961504                        css_tag.first != "<xmlattr>" ) 
     
    15051513        { 
    15061514            ex.append_context("in RasterSymbolizer"); 
     1515            throw; 
     1516        } 
     1517    } 
     1518    void map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc, 
     1519                                            ptree const& node ) 
     1520    { 
     1521        try 
     1522        { 
     1523            ptree::const_iterator cbIter = node.begin(); 
     1524            ptree::const_iterator endCb = node.end(); 
     1525 
     1526            for(; cbIter != endCb; ++cbIter) 
     1527            { 
     1528                ptree::value_type const& cb_tag = *cbIter; 
     1529                ptree const & cb = cbIter->second; 
     1530 
     1531                if (cb_tag.first == "ColorBand") 
     1532                { 
     1533                    std::string value_s  = get_attr<string>(cb, "value"); 
     1534                    float value; 
     1535                    std::stringstream(value_s) >> value; 
     1536                    optional<color> c = get_opt_attr<color>(cb, "color"); 
     1537                    if (!c) { 
     1538                       throw config_error("missing color"); 
     1539                    } 
     1540                    unsigned midpoints = get_attr(cb, "midpoints", 0); 
     1541                    rc->append_band(value, *c, midpoints); 
     1542                } 
     1543                else if (cb_tag.first != "<xmlcomment>" && 
     1544                         cb_tag.first != "<xmlattr>" ) 
     1545                { 
     1546                    throw config_error(std::string("Unknown child node. ") + 
     1547                            "Expected 'ColorBand' but got '" + cb_tag.first + "'"); 
     1548                } 
     1549            } 
     1550        } 
     1551        catch (const config_error & ex) 
     1552        { 
     1553            ex.append_context("in RasterColorizer"); 
    15071554            throw; 
    15081555        }