+ add initial support for new WKT path/geometry parser concept

This commit is contained in:
Artem Pavlenko 2011-09-08 11:52:59 +00:00
parent 53b50c871c
commit 6575e34973
2 changed files with 25 additions and 10 deletions

View file

@ -664,6 +664,7 @@ __all__ = [
'Map', 'Map',
'MarkersSymbolizer', 'MarkersSymbolizer',
'Names', 'Names',
'Path',
'Parameter', 'Parameter',
'Parameters', 'Parameters',
'PointDatasource', 'PointDatasource',

View file

@ -24,6 +24,10 @@
#include <boost/python/def.hpp> #include <boost/python/def.hpp>
#include <boost/python/exception_translator.hpp> #include <boost/python/exception_translator.hpp>
#include <boost/python/manage_new_object.hpp> #include <boost/python/manage_new_object.hpp>
//#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/iterator.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
// mapnik // mapnik
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/wkt/wkt_factory.hpp> #include <mapnik/wkt/wkt_factory.hpp>
@ -33,14 +37,20 @@ namespace {
using mapnik::from_wkt; using mapnik::from_wkt;
using mapnik::geometry_type; using mapnik::geometry_type;
geometry_type * make_from_wkt(std::string const& wkt) typedef boost::ptr_vector<geometry_type> path_type;
geometry_type const& getitem_impl(path_type & p, int key)
{ {
std::pair<bool,geometry_type*> result = from_wkt(wkt); if (key >=0 && key < p.size())
if (result.first) return p[key];
{ PyErr_SetString(PyExc_IndexError, "Index is out of range");
return result.second; throw boost::python::error_already_set();
} }
throw std::runtime_error("Failed to parse WKT");
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; using mapnik::geometry_type;
class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init) class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init)
// factory method
.def("from_wkt",make_from_wkt,return_value_policy<manage_new_object>())
.staticmethod("from_wkt")
.def("envelope",&geometry_type::envelope) .def("envelope",&geometry_type::envelope)
// .def("__str__",&geometry_type::to_string) // .def("__str__",&geometry_type::to_string)
.def("type",&geometry_type::type) .def("type",&geometry_type::type)
.def("area",&geometry_type::area) .def("area",&geometry_type::area)
// TODO add other geometry_type methods // TODO add other geometry_type methods
; ;
class_<path_type,boost::noncopyable>("Path")
.def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>())
.def("from_wkt",from_wkt_impl)
;
} }