From 516f7c75b191ccc7d75269dc0d5a162294d0ba20 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 20 Jul 2012 12:28:25 +0100 Subject: [PATCH] + expose geometry type in expression grammar to allow following filter expressions : [mapnik::geometry_type] = Polygon (#546) --- include/mapnik/attribute.hpp | 21 +++++++++++++++++++++ include/mapnik/attribute_collector.hpp | 5 +++++ include/mapnik/expression_evaluator.hpp | 4 ++++ include/mapnik/expression_grammar.hpp | 24 +++++++++++++++++++----- include/mapnik/expression_node.hpp | 1 + src/expression_string.cpp | 5 +++++ 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp index b38292c48..a9ae97169 100644 --- a/include/mapnik/attribute.hpp +++ b/include/mapnik/attribute.hpp @@ -25,6 +25,9 @@ // mapnik #include +#include +// boost +#include // stl #include @@ -44,6 +47,24 @@ struct attribute std::string const& name() const { return name_;} }; + +struct geometry_type_attribute +{ + template + V value(F const& f) const + { + int result = 0; + + geometry_container::const_iterator itr = f.paths().begin(); + geometry_container::const_iterator end = f.paths().end(); + for ( ; itr != end; ++itr) + { + result = itr->type(); + } + return result; + } +}; + } #endif // MAPNIK_ATTRIBUTE_HPP diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 4cba3a09b..f814d1ac5 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -47,6 +47,11 @@ struct expression_attributes : boost::static_visitor boost::ignore_unused_variable_warning(x); } + void operator() (geometry_type_attribute const& type) const + { + // do nothing + } + void operator() (attribute const& attr) const { names_.insert(attr.name()); diff --git a/include/mapnik/expression_evaluator.hpp b/include/mapnik/expression_evaluator.hpp index a4d199012..e23da962f 100644 --- a/include/mapnik/expression_evaluator.hpp +++ b/include/mapnik/expression_evaluator.hpp @@ -50,6 +50,10 @@ struct evaluate : boost::static_visitor return attr.value(feature_); } + value_type operator() (geometry_type_attribute const& attr) const + { + return attr.value(feature_); + } value_type operator() (binary_node const & x) const { diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index c74b70d47..8f11aea55 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -29,7 +29,6 @@ // boost #include -#include #include #include @@ -123,6 +122,18 @@ struct regex_replace_impl mapnik::transcoder const& tr_; }; +struct geometry_types : qi::symbols +{ + geometry_types() + { + add + ("point",1) + ("line", 2) + ("polygon",3) + ; + } +}; + template struct expression_grammar : qi::grammar { @@ -150,7 +161,7 @@ struct expression_grammar : qi::grammar using qi::hex; using qi::omit; using standard_wide::char_; - + using standard_wide::no_case; expr = logical_expr.alias(); logical_expr = not_expr [_val = _1] @@ -221,10 +232,12 @@ struct expression_grammar : qi::grammar primary_expr = strict_double [_val = _1] | int_ [_val = _1] - | lit("true") [_val = true] - | lit("false") [_val = false] - | lit("null") [_val = value_null() ] + | no_case[lit("true")] [_val = true] + | no_case[lit("false")] [_val = false] + | no_case[lit("null")] [_val = value_null() ] + | no_case[geom_type][_val = _1 ] | ustring [_val = unicode_(_1) ] + | lit("[mapnik::geometry_type]")[_val = construct()] | attr [_val = construct( _1 ) ] | '(' >> expr [_val = _1 ] >> ')' ; @@ -270,6 +283,7 @@ struct expression_grammar : qi::grammar qi::rule > ustring; qi::symbols unesc_char; qi::rule quote_char; + geometry_types geom_type; }; } // namespace diff --git a/include/mapnik/expression_node.hpp b/include/mapnik/expression_node.hpp index a123297c5..da5f7e2d9 100644 --- a/include/mapnik/expression_node.hpp +++ b/include/mapnik/expression_node.hpp @@ -174,6 +174,7 @@ typedef mapnik::value value_type; typedef boost::variant < value_type, attribute, +geometry_type_attribute, boost::recursive_wrapper >, boost::recursive_wrapper >, boost::recursive_wrapper >, diff --git a/src/expression_string.cpp b/src/expression_string.cpp index 231e7a5d5..87a082af8 100644 --- a/src/expression_string.cpp +++ b/src/expression_string.cpp @@ -50,6 +50,11 @@ struct expression_string : boost::static_visitor str_ += "]"; } + void operator() (geometry_type_attribute const& attr) const + { + str_ += "[mapnik::geometry_type]"; + } + template void operator() (binary_node const& x) const {