add pickling support for point_symbolizer and expose the filename property (patch from mishok13 - thanks) - closes #114, addresses #345
This commit is contained in:
parent
770d5a727d
commit
5b9ddbaecd
2 changed files with 70 additions and 5 deletions
|
@ -22,17 +22,80 @@
|
|||
//$Id$
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <mapnik/graphics.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/point_symbolizer.hpp>
|
||||
|
||||
|
||||
using mapnik::point_symbolizer;
|
||||
using mapnik::symbolizer_with_image;
|
||||
|
||||
struct point_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
getinitargs(const point_symbolizer& p)
|
||||
{
|
||||
boost::shared_ptr<mapnik::ImageData32> img = p.get_image();
|
||||
const std::string & filename = p.get_filename();
|
||||
|
||||
if ( ! filename.empty() ) {
|
||||
return boost::python::make_tuple(filename,mapnik::guess_type(filename),img->width(),img->height());
|
||||
} else {
|
||||
return boost::python::make_tuple();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static boost::python::tuple
|
||||
getstate(const point_symbolizer& p)
|
||||
{
|
||||
return boost::python::make_tuple(p.get_allow_overlap(),p.get_opacity());
|
||||
}
|
||||
|
||||
static void
|
||||
setstate (point_symbolizer& p, boost::python::tuple state)
|
||||
{
|
||||
using namespace boost::python;
|
||||
if (len(state) != 2)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
("expected 2-item tuple in call to __setstate__; got %s"
|
||||
% state).ptr()
|
||||
);
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
p.set_allow_overlap(extract<bool>(state[0]));
|
||||
p.set_opacity(extract<float>(state[1]));
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
const char *get_filename(mapnik::point_symbolizer& symbolizer)
|
||||
{
|
||||
return symbolizer.get_filename().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
void export_point_symbolizer()
|
||||
{
|
||||
using namespace boost::python;
|
||||
using mapnik::point_symbolizer;
|
||||
|
||||
class_<point_symbolizer>("PointSymbolizer",
|
||||
init<>("Default Point Symbolizer - 4x4 black square"))
|
||||
.def (init<std::string const&,
|
||||
std::string const&,unsigned,unsigned>("TODO"))
|
||||
.def_pickle(point_symbolizer_pickle_suite())
|
||||
.add_property("filename",
|
||||
// DS - Using workaround as the normal make_function does not work for unknown reasons...
|
||||
//make_function(&point_symbolizer::get_filename,return_value_policy<copy_const_reference>()),
|
||||
get_filename,
|
||||
&point_symbolizer::set_filename)
|
||||
.add_property("allow_overlap",
|
||||
&point_symbolizer::get_allow_overlap,
|
||||
&point_symbolizer::set_allow_overlap)
|
||||
|
|
|
@ -45,10 +45,12 @@ def test_pointsymbolizer_missing_image():
|
|||
|
||||
# PointSymbolizer pickling
|
||||
def test_pointsymbolizer_pickle():
|
||||
raise Todo("PointSymbolizer does not support pickling yet.")
|
||||
#p = mapnik.PointSymbolizer()
|
||||
#p2 = pickle.loads(pickle.dumps(p,pickle.HIGHEST_PROTOCOL))
|
||||
#eq_(p2, p)
|
||||
p = mapnik.PointSymbolizer("../data/images/dummy.png", "png", 16, 16)
|
||||
p2 = pickle.loads(pickle.dumps(p,pickle.HIGHEST_PROTOCOL))
|
||||
# image type, width, and height only used in contructor...
|
||||
eq_(p.filename, p2.filename)
|
||||
eq_(p.allow_overlap, p2.allow_overlap)
|
||||
eq_(p.opacity, p2.opacity)
|
||||
|
||||
# PolygonSymbolizer initialization
|
||||
def test_polygonsymbolizer_init():
|
||||
|
|
Loading…
Add table
Reference in a new issue