+add pickle support for proj_transform and view/coord_transform - see #345

This commit is contained in:
Dane Springmeyer 2009-05-24 06:31:32 +00:00
parent 92ca0a8ac9
commit dadd64519b
5 changed files with 58 additions and 11 deletions

View file

@ -25,6 +25,19 @@
#include <mapnik/proj_transform.hpp>
// 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 {
@ -73,10 +86,10 @@ namespace {
void export_proj_transform ()
{
using namespace boost::python;
using mapnik::proj_transform;
using mapnik::projection;
using namespace boost::python;
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)

View file

@ -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)

View file

@ -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,12 +134,22 @@ 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
{
return sx_;

View file

@ -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_;

View file

@ -99,5 +99,15 @@ namespace mapnik {
}
return true;
}
}
mapnik::projection const& proj_transform::source() const
{
return source_;
}
mapnik::projection const& proj_transform::dest() const
{
return dest_;
}
}