diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 2e55a22e3..28a57ef21 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -664,6 +664,7 @@ __all__ = [ 'Map', 'MarkersSymbolizer', 'Names', + 'Path', 'Parameter', 'Parameters', 'PointDatasource', diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index 2ad93393d..20cc8b418 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -24,6 +24,10 @@ #include #include #include +//#include +#include +#include + // mapnik #include #include @@ -33,14 +37,20 @@ namespace { using mapnik::from_wkt; using mapnik::geometry_type; -geometry_type * make_from_wkt(std::string const& wkt) +typedef boost::ptr_vector path_type; + +geometry_type const& getitem_impl(path_type & p, int key) { - std::pair result = from_wkt(wkt); - if (result.first) - { - return result.second; - } - throw std::runtime_error("Failed to parse WKT"); + if (key >=0 && key < p.size()) + return p[key]; + PyErr_SetString(PyExc_IndexError, "Index is out of range"); + throw boost::python::error_already_set(); +} + +void from_wkt_impl(path_type& p, std::string const& wkt) +{ + bool result = mapnik::from_wkt(wkt, p); + if (!result) throw std::runtime_error("Failed to parse WKT"); } } @@ -60,13 +70,17 @@ void export_geometry() using mapnik::geometry_type; class_,boost::noncopyable>("Geometry2d",no_init) - // factory method - .def("from_wkt",make_from_wkt,return_value_policy()) - .staticmethod("from_wkt") .def("envelope",&geometry_type::envelope) // .def("__str__",&geometry_type::to_string) .def("type",&geometry_type::type) .def("area",&geometry_type::area) // TODO add other geometry_type methods ; + + class_("Path") + .def("__getitem__", getitem_impl,return_value_policy()) + .def("from_wkt",from_wkt_impl) + + ; + }