From c5eb808059aa07f48761524a715e80a23d902d09 Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski Date: Fri, 9 Dec 2011 12:08:50 +0100 Subject: [PATCH 1/3] 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); From 79af8fdbc958b905fcd39d16a701f1d89c085d9b Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski Date: Tue, 13 Dec 2011 15:28:18 +0100 Subject: [PATCH 2/3] refactoring following comment on pull request --- include/mapnik/attribute_collector.hpp | 12 ++++++------ src/agg/process_building_symbolizer.cpp | 4 ++-- src/cairo_renderer.cpp | 12 ++++++------ src/save_map.cpp | 7 +++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 70e1a5e8d..e256a6c9e 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -213,12 +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); - } + 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/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index 4546b0d7d..0a5b573a7 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -71,8 +71,8 @@ void agg_renderer::process(building_symbolizer const& sym, 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_; + 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(); - } + expression_ptr height_expr = sym.height(); + if (height_expr) + { + value_type result = boost::apply_visitor(evaluate(feature), *height_expr); + height = 0.7071 * result.to_double(); + } for (unsigned i = 0; i < feature.num_geometries(); ++i) { diff --git a/src/save_map.cpp b/src/save_map.cpp index 63edbfce8..63f1b84ff 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -241,10 +241,9 @@ public: { set_attr( sym_node, "fill-opacity", sym.get_opacity() ); } - if ( sym.height() != dfl.height() || explicit_defaults_ ) - { - set_attr( sym_node, "height", sym.height() ); - } + + set_attr( sym_node, "height", to_expression_string(*sym.height()) ); + add_metawriter_attributes(sym_node, sym); } From fbe8829791d0311cb8a030de3e1124bb510dbd2c Mon Sep 17 00:00:00 2001 From: Cezary Tarnowski Date: Tue, 13 Dec 2011 15:40:47 +0100 Subject: [PATCH 3/3] Changing the gamma for better visual effect --- src/agg/process_polygon_symbolizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index c376d9544..a3c3f9d1d 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -62,7 +62,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, renderer ren(renb); ras_ptr->reset(); - ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma())); + ras_ptr->gamma(agg::gamma_power(sym.get_gamma())); metawriter_with_properties writer = sym.get_metawriter(); for (unsigned i=0;i