2009-01-13 00:56:09 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:54:32 +00:00
|
|
|
*
|
2009-01-13 00:56:09 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
//$Id$
|
|
|
|
|
|
|
|
// boost
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <boost/python/def.hpp>
|
2011-02-28 12:40:59 +00:00
|
|
|
#include <boost/python/exception_translator.hpp>
|
|
|
|
#include <boost/python/manage_new_object.hpp>
|
2011-09-08 11:52:59 +00:00
|
|
|
#include <boost/python/iterator.hpp>
|
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
|
2009-01-13 00:56:09 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/geometry.hpp>
|
2011-02-28 12:40:59 +00:00
|
|
|
#include <mapnik/wkt/wkt_factory.hpp>
|
2011-09-13 11:54:12 +00:00
|
|
|
#include <mapnik/wkb.hpp>
|
2011-02-28 12:40:59 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using mapnik::from_wkt;
|
|
|
|
using mapnik::geometry_type;
|
|
|
|
|
2011-09-08 11:52:59 +00:00
|
|
|
typedef boost::ptr_vector<geometry_type> path_type;
|
|
|
|
|
|
|
|
geometry_type const& getitem_impl(path_type & p, int key)
|
|
|
|
{
|
|
|
|
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)
|
2011-02-28 12:40:59 +00:00
|
|
|
{
|
2011-10-19 14:29:24 +00:00
|
|
|
bool result = mapnik::from_wkt(wkt , p);
|
2011-09-08 11:52:59 +00:00
|
|
|
if (!result) throw std::runtime_error("Failed to parse WKT");
|
2011-02-28 12:40:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-13 11:54:12 +00:00
|
|
|
void from_wkb_impl(path_type& p, std::string const& wkb)
|
|
|
|
{
|
|
|
|
mapnik::geometry_utils::from_wkb(p, wkb.c_str(), wkb.size(), true);
|
|
|
|
}
|
|
|
|
|
2011-02-28 12:40:59 +00:00
|
|
|
}
|
2009-01-13 00:56:09 +00:00
|
|
|
|
|
|
|
void export_geometry()
|
|
|
|
{
|
2010-06-02 11:03:30 +00:00
|
|
|
using namespace boost::python;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-02-28 12:40:59 +00:00
|
|
|
enum_<mapnik::eGeomType>("GeometryType")
|
|
|
|
.value("Point",mapnik::Point)
|
|
|
|
.value("LineString",mapnik::LineString)
|
|
|
|
.value("Polygon",mapnik::Polygon)
|
|
|
|
.value("MultiPoint",mapnik::MultiPoint)
|
|
|
|
.value("MultiLineString",mapnik::MultiLineString)
|
|
|
|
.value("MultiPolygon",mapnik::MultiPolygon)
|
|
|
|
;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-02-28 12:40:59 +00:00
|
|
|
using mapnik::geometry_type;
|
|
|
|
class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init)
|
2010-11-03 13:19:15 +00:00
|
|
|
.def("envelope",&geometry_type::envelope)
|
|
|
|
// .def("__str__",&geometry_type::to_string)
|
|
|
|
.def("type",&geometry_type::type)
|
|
|
|
// TODO add other geometry_type methods
|
2010-06-02 11:03:30 +00:00
|
|
|
;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-09-08 11:52:59 +00:00
|
|
|
class_<path_type,boost::noncopyable>("Path")
|
|
|
|
.def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>())
|
2011-09-13 13:23:23 +00:00
|
|
|
.def("__len__", &path_type::size)
|
2011-09-08 11:52:59 +00:00
|
|
|
.def("from_wkt",from_wkt_impl)
|
2011-09-13 11:54:12 +00:00
|
|
|
.def("from_wkb",from_wkb_impl)
|
2011-09-08 11:52:59 +00:00
|
|
|
;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2009-01-13 00:56:09 +00:00
|
|
|
}
|