Browse files

amend 516f7c7 to suport filtering on collections and rename line to l…

…inestring for consistency - refs #546
  • Loading branch information...
1 parent b298e21 commit fa052c50211f051c415c174423e56cce1eb60469 @springmeyer springmeyer committed Jul 25, 2012
Showing with 51 additions and 7 deletions.
  1. +8 −6 include/mapnik/attribute.hpp
  2. +2 −1 include/mapnik/expression_grammar.hpp
  3. +41 −0 tests/python_tests/filter_test.py
View
14 include/mapnik/attribute.hpp
@@ -26,8 +26,7 @@
// mapnik
#include <mapnik/value.hpp>
#include <mapnik/geometry.hpp>
-// boost
-#include <boost/foreach.hpp>
+
// stl
#include <string>
@@ -53,15 +52,18 @@ struct geometry_type_attribute
template <typename V, typename F>
V value(F const& f) const
{
- int result = 0;
-
+ int type = 0;
geometry_container::const_iterator itr = f.paths().begin();
geometry_container::const_iterator end = f.paths().end();
for ( ; itr != end; ++itr)
{
- result = itr->type();
+ if (type != 0 && itr->type() != type)
+ {
+ return 4; // Collection
+ }
+ type = itr->type();
}
- return result;
+ return type;
}
};
View
3 include/mapnik/expression_grammar.hpp
@@ -114,8 +114,9 @@ struct geometry_types : qi::symbols<char,int>
{
add
("point",1)
- ("line", 2)
+ ("linestring", 2)
("polygon",3)
+ ("collection",4)
;
}
};
View
41 tests/python_tests/filter_test.py
@@ -92,6 +92,47 @@ def test_filter_init():
eq_(s.filter_mode,mapnik.filter_mode.FIRST)
+def test_geometry_type_eval():
+ # clashing field called 'mapnik::geometry'
+ context2 = mapnik.Context()
+ context2.push('mapnik::geometry_type')
+ f = mapnik.Feature(context2,0)
+ f["mapnik::geometry_type"] = 'sneaky'
+ expr = mapnik.Expression("[mapnik::geometry_type]")
+ eq_(expr.evaluate(f),0)
+
+ expr = mapnik.Expression("[mapnik::geometry_type]")
+ context = mapnik.Context()
+
+ # no geometry
+ f = mapnik.Feature(context,0)
+ eq_(expr.evaluate(f),0)
+ eq_(mapnik.Expression("[mapnik::geometry_type]=0").evaluate(f),True)
+
+ # POINT = 1
+ f = mapnik.Feature(context,0)
+ f.add_geometries_from_wkt('POINT(10 40)')
+ eq_(expr.evaluate(f),1)
+ eq_(mapnik.Expression("[mapnik::geometry_type]=point").evaluate(f),True)
+
+ # LINESTRING = 2
+ f = mapnik.Feature(context,0)
+ f.add_geometries_from_wkt('LINESTRING (30 10, 10 30, 40 40)')
+ eq_(expr.evaluate(f),2)
+ eq_(mapnik.Expression("[mapnik::geometry_type]=linestring").evaluate(f),True)
+
+ # POLYGON = 3
+ f = mapnik.Feature(context,0)
+ f.add_geometries_from_wkt('POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))')
+ eq_(expr.evaluate(f),3)
+ eq_(mapnik.Expression("[mapnik::geometry_type]=polygon").evaluate(f),True)
+
+ # COLLECTION = 4
+ f = mapnik.Feature(context,0)
+ f.add_geometries_from_wkt('GEOMETRYCOLLECTION(POLYGON((1 1,2 1,2 2,1 2,1 1)),POINT(2 3),LINESTRING(2 3,3 4))')
+ eq_(expr.evaluate(f),4)
+ eq_(mapnik.Expression("[mapnik::geometry_type]=collection").evaluate(f),True)
+
def test_regex_match():
context = mapnik.Context()
context.push('name')

0 comments on commit fa052c5

Please sign in to comment.