From 8bf359451dc4ac03ef21b6053d860e293b14e1aa Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski Date: Fri, 9 Dec 2011 12:08:50 +0100 Subject: [PATCH] Adding support for height as expression for building symbolizer --- include/mapnik/attribute_collector.hpp | 6 ++++++ include/mapnik/polygon_symbolizer.hpp | 10 +++++----- src/agg/process_building_symbolizer.cpp | 9 ++++++++- src/cairo_renderer.cpp | 8 +++++++- src/grid/process_building_symbolizer.cpp | 9 ++++++++- src/load_map.cpp | 5 ++--- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index b9b62a89c..70e1a5e8d 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -213,6 +213,12 @@ struct symbolizer_attributes : public boost::static_visitor<> void operator () (building_symbolizer const& sym) { + expression_ptr const& height_expr = sym.height(); + if (height_expr) + { + expression_attributes f_attr(names_); + boost::apply_visitor(f_attr,*height_expr); + } collect_metawriter(sym); } // TODO - support remaining syms diff --git a/include/mapnik/polygon_symbolizer.hpp b/include/mapnik/polygon_symbolizer.hpp index 809ceced3..a4791eed3 100644 --- a/include/mapnik/polygon_symbolizer.hpp +++ b/include/mapnik/polygon_symbolizer.hpp @@ -26,6 +26,7 @@ // mapnik #include #include +#include namespace mapnik { @@ -79,11 +80,10 @@ struct MAPNIK_DECL building_symbolizer : public symbolizer_base explicit building_symbolizer() : symbolizer_base(), fill_(color(128,128,128)), - height_(0.0), opacity_(1.0) {} - building_symbolizer(color const& fill,double height) + building_symbolizer(color const& fill, expression_ptr height) : symbolizer_base(), fill_(fill), height_(height), @@ -97,11 +97,11 @@ struct MAPNIK_DECL building_symbolizer : public symbolizer_base { fill_ = fill; } - double height() const + expression_ptr height() const { return height_; } - void set_height(double height) + void set_height(expression_ptr height) { height_=height; } @@ -115,7 +115,7 @@ struct MAPNIK_DECL building_symbolizer : public symbolizer_base } private: color fill_; - double height_; + expression_ptr height_; double opacity_; }; } diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index a9b8b0dbd..4546b0d7d 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include // boost #include @@ -66,7 +67,13 @@ void agg_renderer::process(building_symbolizer const& sym, ras_ptr->reset(); ras_ptr->gamma(agg::gamma_linear()); - double height = sym.height() * scale_factor_; + double height = 0.0; + expression_ptr height_expr = sym.height(); + if (height_expr) + { + value_type result = boost::apply_visitor(evaluate(feature), *height_expr); + height = result.to_double() * scale_factor_; + } for (unsigned i=0;i(feature), *height_expr); + height = 0.7071 * result.to_double(); + } for (unsigned i = 0; i < feature.num_geometries(); ++i) { diff --git a/src/grid/process_building_symbolizer.cpp b/src/grid/process_building_symbolizer.cpp index 27c156a27..dcbb3665e 100644 --- a/src/grid/process_building_symbolizer.cpp +++ b/src/grid/process_building_symbolizer.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // boost #include @@ -59,7 +60,13 @@ void grid_renderer::process(building_symbolizer const& sym, ras_ptr->reset(); - double height = sym.height() * scale_factor_; + double height = 0.0; + expression_ptr height_expr = sym.height(); + if (height_expr) + { + value_type result = boost::apply_visitor(evaluate(feature), *height_expr); + height = result.to_double() * scale_factor_; + } for (unsigned i=0;i opacity = get_opt_attr(sym, "fill-opacity"); if (opacity) building_sym.set_opacity(*opacity); // height - // TODO - expression - optional height = get_opt_attr(sym, "height"); - if (height) building_sym.set_height(*height); + optional height = get_opt_attr(sym, "height"); + if (height) building_sym.set_height(parse_expression(*height, "utf8")); parse_metawriter_in_symbolizer(building_sym, sym); rule.append(building_sym);