+ expose geometry type in expression grammar to allow following
filter expressions : [mapnik::geometry_type] = Polygon (#546)
This commit is contained in:
parent
e0c2304d42
commit
516f7c75b1
6 changed files with 55 additions and 5 deletions
|
@ -25,6 +25,9 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
// boost
|
||||
#include <boost/foreach.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
|
@ -44,6 +47,24 @@ struct attribute
|
|||
|
||||
std::string const& name() const { return name_;}
|
||||
};
|
||||
|
||||
struct geometry_type_attribute
|
||||
{
|
||||
template <typename V, typename F>
|
||||
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
|
||||
|
|
|
@ -47,6 +47,11 @@ struct expression_attributes : boost::static_visitor<void>
|
|||
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());
|
||||
|
|
|
@ -50,6 +50,10 @@ struct evaluate : boost::static_visitor<T1>
|
|||
return attr.value<value_type,feature_type>(feature_);
|
||||
}
|
||||
|
||||
value_type operator() (geometry_type_attribute const& attr) const
|
||||
{
|
||||
return attr.value<value_type,feature_type>(feature_);
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_and> const & x) const
|
||||
{
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
// boost
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
|
@ -123,6 +122,18 @@ struct regex_replace_impl
|
|||
mapnik::transcoder const& tr_;
|
||||
};
|
||||
|
||||
struct geometry_types : qi::symbols<char,int>
|
||||
{
|
||||
geometry_types()
|
||||
{
|
||||
add
|
||||
("point",1)
|
||||
("line", 2)
|
||||
("polygon",3)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
||||
{
|
||||
|
@ -150,7 +161,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
|||
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<Iterator, expr_node(), space_type>
|
|||
|
||||
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<mapnik::geometry_type_attribute>()]
|
||||
| attr [_val = construct<mapnik::attribute>( _1 ) ]
|
||||
| '(' >> expr [_val = _1 ] >> ')'
|
||||
;
|
||||
|
@ -270,6 +283,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
|
|||
qi::rule<Iterator, std::string(), qi::locals<char> > ustring;
|
||||
qi::symbols<char const, char const> unesc_char;
|
||||
qi::rule<Iterator, char() > quote_char;
|
||||
geometry_types geom_type;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -174,6 +174,7 @@ typedef mapnik::value value_type;
|
|||
typedef boost::variant <
|
||||
value_type,
|
||||
attribute,
|
||||
geometry_type_attribute,
|
||||
boost::recursive_wrapper<unary_node<tags::negate> >,
|
||||
boost::recursive_wrapper<binary_node<tags::plus> >,
|
||||
boost::recursive_wrapper<binary_node<tags::minus> >,
|
||||
|
|
|
@ -50,6 +50,11 @@ struct expression_string : boost::static_visitor<void>
|
|||
str_ += "]";
|
||||
}
|
||||
|
||||
void operator() (geometry_type_attribute const& attr) const
|
||||
{
|
||||
str_ += "[mapnik::geometry_type]";
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
void operator() (binary_node<Tag> const& x) const
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue