+add pickle support for proj_transform and view/coord_transform - see #345
This commit is contained in:
parent
92ca0a8ac9
commit
dadd64519b
5 changed files with 58 additions and 11 deletions
|
@ -26,6 +26,19 @@
|
|||
// boost
|
||||
#include <boost/python.hpp>
|
||||
|
||||
using mapnik::proj_transform;
|
||||
using mapnik::projection;
|
||||
|
||||
struct proj_transform_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
getinitargs(const proj_transform& p)
|
||||
{
|
||||
using namespace boost::python;
|
||||
return boost::python::make_tuple(p.source(),p.dest());
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
mapnik::coord2d forward_transform_c(mapnik::proj_transform& t, mapnik::coord2d const& c)
|
||||
|
@ -74,9 +87,9 @@ namespace {
|
|||
void export_proj_transform ()
|
||||
{
|
||||
using namespace boost::python;
|
||||
using mapnik::proj_transform;
|
||||
using mapnik::projection;
|
||||
|
||||
class_<proj_transform, boost::noncopyable>("ProjTransform", init< projection const&, projection const& >())
|
||||
.def_pickle(proj_transform_pickle_suite())
|
||||
.def("forward", forward_transform_c)
|
||||
.def("backward",backward_transform_c)
|
||||
.def("forward", forward_transform_env)
|
||||
|
|
|
@ -27,6 +27,18 @@
|
|||
// mapnik
|
||||
#include <mapnik/ctrans.hpp>
|
||||
|
||||
using mapnik::CoordTransform;
|
||||
|
||||
struct view_transform_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
getinitargs(const CoordTransform& c)
|
||||
{
|
||||
using namespace boost::python;
|
||||
return boost::python::make_tuple(c.width(),c.height(),c.extent());
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
mapnik::coord2d forward_point(mapnik::CoordTransform const& t, mapnik::coord2d const& in)
|
||||
|
@ -58,11 +70,11 @@ void export_view_transform()
|
|||
{
|
||||
using namespace boost::python;
|
||||
using mapnik::Envelope;
|
||||
using mapnik::CoordTransform;
|
||||
using mapnik::coord2d;
|
||||
|
||||
class_<CoordTransform>("ViewTransform",init<int,int,Envelope<double> const& > (
|
||||
"Create a ViewTransform with a width and height as integers and extent"))
|
||||
.def_pickle(view_transform_pickle_suite())
|
||||
.def("forward", forward_point)
|
||||
.def("backward",backward_point)
|
||||
.def("forward", forward_envelope)
|
||||
|
|
|
@ -124,8 +124,8 @@ namespace mapnik {
|
|||
class CoordTransform
|
||||
{
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
int width_;
|
||||
int height_;
|
||||
double sx_;
|
||||
double sy_;
|
||||
Envelope<double> extent_;
|
||||
|
@ -134,10 +134,20 @@ namespace mapnik {
|
|||
public:
|
||||
CoordTransform(int width,int height,const Envelope<double>& extent,
|
||||
double offset_x = 0, double offset_y = 0)
|
||||
:width(width),height(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y)
|
||||
:width_(width),height_(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y)
|
||||
{
|
||||
sx_ = ((double)width)/extent_.width();
|
||||
sy_ = ((double)height)/extent_.height();
|
||||
sx_ = ((double)width_)/extent_.width();
|
||||
sy_ = ((double)height_)/extent_.height();
|
||||
}
|
||||
|
||||
inline int width() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
inline int height() const
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
|
||||
inline double scale_x() const
|
||||
|
|
|
@ -40,6 +40,8 @@ namespace mapnik {
|
|||
|
||||
bool forward (double& x, double& y , double& z) const;
|
||||
bool backward (double& x, double& y , double& z) const;
|
||||
mapnik::projection const& source() const;
|
||||
mapnik::projection const& dest() const;
|
||||
|
||||
private:
|
||||
projection const& source_;
|
||||
|
|
|
@ -100,4 +100,14 @@ namespace mapnik {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
mapnik::projection const& proj_transform::source() const
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
mapnik::projection const& proj_transform::dest() const
|
||||
{
|
||||
return dest_;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue