+ add initial support for new WKT path/geometry parser concept
This commit is contained in:
parent
53b50c871c
commit
6575e34973
2 changed files with 25 additions and 10 deletions
|
@ -664,6 +664,7 @@ __all__ = [
|
|||
'Map',
|
||||
'MarkersSymbolizer',
|
||||
'Names',
|
||||
'Path',
|
||||
'Parameter',
|
||||
'Parameters',
|
||||
'PointDatasource',
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/exception_translator.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
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
|
@ -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<geometry_type> path_type;
|
||||
|
||||
geometry_type const& getitem_impl(path_type & p, int key)
|
||||
{
|
||||
std::pair<bool,geometry_type*> 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_<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("__str__",&geometry_type::to_string)
|
||||
.def("type",&geometry_type::type)
|
||||
.def("area",&geometry_type::area)
|
||||
// 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)
|
||||
|
||||
;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue