Skip to content

Commit

Permalink
+ expose geometry type in expression grammar to allow following
Browse files Browse the repository at this point in the history
  filter expressions : [mapnik::geometry_type] = Polygon (#546)
  • Loading branch information
artemp committed Jul 20, 2012
1 parent e0c2304 commit 516f7c7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
21 changes: 21 additions & 0 deletions include/mapnik/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

// mapnik
#include <mapnik/value.hpp>
#include <mapnik/geometry.hpp>
// boost
#include <boost/foreach.hpp>
// stl
#include <string>

Expand All @@ -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
5 changes: 5 additions & 0 deletions include/mapnik/attribute_collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions include/mapnik/expression_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 19 additions & 5 deletions include/mapnik/expression_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

// boost
#include <boost/version.hpp>
#include <boost/variant.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/concept_check.hpp>

Expand Down Expand Up @@ -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>
{
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 ] >> ')'
;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/mapnik/expression_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> >,
Expand Down
5 changes: 5 additions & 0 deletions src/expression_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 516f7c7

Please sign in to comment.