amend 516f7c7 to suport filtering on collections and rename line to linestring for consistency - refs #546

This commit is contained in:
Dane Springmeyer 2012-07-25 14:43:32 -07:00
parent b298e21f8e
commit fa052c5021
3 changed files with 51 additions and 7 deletions

View file

@ -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 file

@ -114,8 +114,9 @@ struct geometry_types : qi::symbols<char,int>
{
add
("point",1)
("line", 2)
("linestring", 2)
("polygon",3)
("collection",4)
;
}
};

View file

@ -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')