+ add mapnik.Context

+ implement __setitem__
+ fix mapnik.Feature ctor - now requires Context obj
This commit is contained in:
Artem Pavlenko 2012-01-13 12:03:26 +00:00 committed by Artem Pavlenko
parent da7574065d
commit 8de670ecb9
2 changed files with 24 additions and 11 deletions

View file

@ -281,8 +281,8 @@ class _Feature(Feature, _injector):
# maybe deprecate?
return dict(self)
def __init__(self, id, wkt=None, **properties):
Feature._c___init__(self, id)
def __init__(self, ctx, id, wkt=None, **properties):
Feature._c___init__(self, ctx, id)
if wkt is not None:
self.add_geometries_from_wkt(wkt)
for k, v in properties.iteritems():

View file

@ -42,6 +42,7 @@ namespace {
using mapnik::Feature;
using mapnik::geometry_utils;
using mapnik::from_wkt;
using mapnik::context;
using mapnik::context_ptr;
void feature_add_geometries_from_wkb(Feature &feature, std::string wkb)
@ -55,6 +56,11 @@ void feature_add_geometries_from_wkt(Feature &feature, std::string wkt)
if (!result) throw std::runtime_error("Failed to parse WKT");
}
void __setitem__(Feature & feature, std::string const& name, mapnik::value const& val)
{
feature.put(name,val);
}
} // end anonymous namespace
namespace boost { namespace python {
@ -269,20 +275,27 @@ void export_feature()
std_pair_to_python_converter<std::string const,mapnik::value>();
UnicodeString_from_python_str();
class_<context,context_ptr,boost::noncopyable>
("Context",init<>("Default ctor."))
.def("push", &context::push)
;
class_<Feature,boost::shared_ptr<Feature>,
boost::noncopyable>("Feature",init<context_ptr, int>("Default ctor."))
boost::noncopyable>("Feature",init<context_ptr,int>("Default ctor."))
.def("id",&Feature::id)
.def("__str__",&Feature::to_string)
.def("add_geometries_from_wkb", &feature_add_geometries_from_wkb)
.def("add_geometries_from_wkt", &feature_add_geometries_from_wkt)
//.def("add_geometry", add_geometry)
//.def("num_geometries",&Feature::num_geometries)
//.def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>()))
.def("add_geometry", &Feature::add_geometry)
.def("num_geometries",&Feature::num_geometries)
.def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>()))
.def("geometries",make_function(&Feature::paths,return_value_policy<reference_existing_object>()))
// FIXME
//.def("envelope", &Feature::envelope)
// .def(map_indexing_suite2<Feature, true >())
// .def("iteritems",iterator<Feature> ())
// TODO define more mapnik::Feature methods
.def("envelope", &Feature::envelope)
.def("__setitem__",&__setitem__)
// FIXME
// .def(map_indexing_suite2<Feature, true >())
// .def("iteritems",iterator<Feature> ())
//TODO define more mapnik::Feature methods
;
}