expose filename (path_expression string) as property on all symbolizers_with_image (TODO consider exposing actual PathExpression) - and fixup displacement get/set on various symbolizers, moving to properties for consistency
This commit is contained in:
parent
2dfe2a9ccf
commit
9775a1ee5b
7 changed files with 195 additions and 102 deletions
|
@ -12,15 +12,20 @@ using mapnik::AZIMUTH;
|
|||
using mapnik::TRIGONOMETRIC;
|
||||
using namespace boost::python;
|
||||
|
||||
list get_displacement_list(const glyph_symbolizer& t)
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
tuple get_displacement(const glyph_symbolizer& s)
|
||||
{
|
||||
position pos = t.get_displacement();
|
||||
double dx = boost::get<0>(pos);
|
||||
double dy = boost::get<1>(pos);
|
||||
boost::python::list disp;
|
||||
disp.append(dx);
|
||||
disp.append(dy);
|
||||
return disp;
|
||||
boost::tuple<double,double> pos = s.get_displacement();
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
void set_displacement(glyph_symbolizer & s, boost::python::tuple arg)
|
||||
{
|
||||
s.set_displacement(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void export_glyph_symbolizer()
|
||||
|
@ -58,20 +63,25 @@ void export_glyph_symbolizer()
|
|||
"Get/Set the flag which controls if glyphs should be "
|
||||
"partially drawn beside the edge of a tile."
|
||||
)
|
||||
.def("get_displacement", get_displacement_list)
|
||||
.def("set_displacement", &glyph_symbolizer::set_displacement)
|
||||
.add_property("displacement",
|
||||
&get_displacement,
|
||||
&set_displacement)
|
||||
|
||||
.add_property("halo_fill",
|
||||
make_function(&glyph_symbolizer::get_halo_fill,
|
||||
return_value_policy<copy_const_reference>()),
|
||||
&glyph_symbolizer::set_halo_fill)
|
||||
|
||||
.add_property("halo_radius",
|
||||
&glyph_symbolizer::get_halo_radius,
|
||||
&glyph_symbolizer::set_halo_radius)
|
||||
|
||||
.add_property("size",
|
||||
&glyph_symbolizer::get_size,
|
||||
&glyph_symbolizer::set_size,
|
||||
"Get/Set the size expression used to size the glyph."
|
||||
)
|
||||
|
||||
.add_property("angle",
|
||||
&glyph_symbolizer::get_angle,
|
||||
&glyph_symbolizer::set_angle,
|
||||
|
|
|
@ -32,8 +32,24 @@ using mapnik::line_pattern_symbolizer;
|
|||
using mapnik::path_processor_type;
|
||||
using mapnik::path_expression_ptr;
|
||||
using mapnik::guess_type;
|
||||
using mapnik::parse_path;
|
||||
|
||||
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
const std::string get_filename(line_pattern_symbolizer const& t)
|
||||
{
|
||||
return path_processor_type::to_string(*t.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(line_pattern_symbolizer & t, std::string const& file_expr)
|
||||
{
|
||||
t.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct line_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
|
@ -56,5 +72,8 @@ void export_line_pattern_symbolizer()
|
|||
.add_property("transform",
|
||||
mapnik::get_svg_transform<line_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<line_pattern_symbolizer>)
|
||||
.add_property("filename",
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,21 @@ using mapnik::symbolizer_with_image;
|
|||
using mapnik::path_processor_type;
|
||||
using mapnik::parse_path;
|
||||
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
std::string get_filename(mapnik::markers_symbolizer const& symbolizer)
|
||||
{
|
||||
return path_processor_type::to_string(*symbolizer.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(mapnik::markers_symbolizer & symbolizer, std::string const& file_expr)
|
||||
{
|
||||
symbolizer.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct markers_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
|
@ -68,21 +83,6 @@ struct markers_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
std::string get_filename(mapnik::markers_symbolizer const& symbolizer)
|
||||
{
|
||||
return path_processor_type::to_string(*symbolizer.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(mapnik::markers_symbolizer & symbolizer, std::string const& file_expr)
|
||||
{
|
||||
symbolizer.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void export_markers_symbolizer()
|
||||
{
|
||||
|
@ -93,8 +93,8 @@ void export_markers_symbolizer()
|
|||
.def (init<mapnik::path_expression_ptr>("<path expression ptr>"))
|
||||
//.def_pickle(markers_symbolizer_pickle_suite())
|
||||
.add_property("filename",
|
||||
get_filename,
|
||||
set_filename)
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
.add_property("allow_overlap",
|
||||
&markers_symbolizer::get_allow_overlap,
|
||||
&markers_symbolizer::set_allow_overlap)
|
||||
|
@ -109,7 +109,7 @@ void export_markers_symbolizer()
|
|||
&markers_symbolizer::set_opacity,
|
||||
"Set/get the text opacity")
|
||||
.add_property("transform",
|
||||
mapnik::get_svg_transform<markers_symbolizer>,
|
||||
mapnik::set_svg_transform<markers_symbolizer>)
|
||||
&mapnik::get_svg_transform<markers_symbolizer>,
|
||||
&mapnik::set_svg_transform<markers_symbolizer>)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,23 @@
|
|||
using mapnik::point_symbolizer;
|
||||
using mapnik::symbolizer_with_image;
|
||||
using mapnik::path_processor_type;
|
||||
using mapnik::parse_path;
|
||||
|
||||
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
const std::string get_filename(point_symbolizer const& t)
|
||||
{
|
||||
return path_processor_type::to_string(*t.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(point_symbolizer & t, std::string const& file_expr)
|
||||
{
|
||||
t.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct point_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
|
@ -68,16 +85,6 @@ struct point_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
const std::string get_filename(mapnik::point_symbolizer& symbolizer)
|
||||
{
|
||||
return path_processor_type::to_string(*symbolizer.get_filename());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void export_point_symbolizer()
|
||||
{
|
||||
|
@ -88,10 +95,8 @@ void export_point_symbolizer()
|
|||
.def (init<mapnik::path_expression_ptr>("<path expression ptr>"))
|
||||
//.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)
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
.add_property("allow_overlap",
|
||||
&point_symbolizer::get_allow_overlap,
|
||||
&point_symbolizer::set_allow_overlap)
|
||||
|
|
|
@ -32,8 +32,24 @@ using namespace mapnik;
|
|||
using mapnik::polygon_pattern_symbolizer;
|
||||
using mapnik::path_expression_ptr;
|
||||
using mapnik::path_processor_type;
|
||||
using mapnik::parse_path;
|
||||
using mapnik::guess_type;
|
||||
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
const std::string get_filename(polygon_pattern_symbolizer const& t)
|
||||
{
|
||||
return path_processor_type::to_string(*t.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(polygon_pattern_symbolizer & t, std::string const& file_expr)
|
||||
{
|
||||
t.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct polygon_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static boost::python::tuple
|
||||
|
@ -86,5 +102,8 @@ void export_polygon_pattern_symbolizer()
|
|||
.add_property("transform",
|
||||
mapnik::get_svg_transform<polygon_pattern_symbolizer>,
|
||||
mapnik::set_svg_transform<polygon_pattern_symbolizer>)
|
||||
.add_property("filename",
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -36,37 +36,55 @@ using mapnik::path_processor_type;
|
|||
using mapnik::path_expression_ptr;
|
||||
using mapnik::guess_type;
|
||||
using mapnik::expression_ptr;
|
||||
using mapnik::parse_path;
|
||||
|
||||
|
||||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
list get_shield_displacement_list(const shield_symbolizer& t)
|
||||
tuple get_shield_displacement(const shield_symbolizer& s)
|
||||
{
|
||||
boost::tuple<double,double> pos = t.get_shield_displacement();
|
||||
double dx = boost::get<0>(pos);
|
||||
double dy = boost::get<1>(pos);
|
||||
boost::python::list disp;
|
||||
disp.append(dx);
|
||||
disp.append(dy);
|
||||
return disp;
|
||||
}
|
||||
|
||||
list get_anchor_list(const shield_symbolizer& t)
|
||||
{
|
||||
boost::tuple<double,double> anch = t.get_anchor();
|
||||
double x = boost::get<0>(anch);
|
||||
double y = boost::get<1>(anch);
|
||||
boost::python::list anchor;
|
||||
anchor.append(x);
|
||||
anchor.append(y);
|
||||
return anchor;
|
||||
boost::tuple<double,double> pos = s.get_shield_displacement();
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
const std::string get_filename(shield_symbolizer& symbolizer)
|
||||
{
|
||||
return path_processor_type::to_string(*symbolizer.get_filename());
|
||||
void set_shield_displacement(shield_symbolizer & s, boost::python::tuple arg)
|
||||
{
|
||||
s.set_shield_displacement(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
tuple get_text_displacement(const shield_symbolizer& t)
|
||||
{
|
||||
boost::tuple<double,double> pos = t.get_displacement();
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
void set_text_displacement(shield_symbolizer & t, boost::python::tuple arg)
|
||||
{
|
||||
t.set_displacement(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
tuple get_anchor(const shield_symbolizer& t)
|
||||
{
|
||||
boost::tuple<double,double> pos = t.get_anchor();
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
void set_anchor(shield_symbolizer & t, boost::python::tuple arg)
|
||||
{
|
||||
t.set_anchor(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
const std::string get_filename(shield_symbolizer const& t)
|
||||
{
|
||||
return path_processor_type::to_string(*t.get_filename());
|
||||
}
|
||||
|
||||
void set_filename(shield_symbolizer & t, std::string const& file_expr)
|
||||
{
|
||||
t.set_filename(parse_path(file_expr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct shield_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
|
@ -119,10 +137,9 @@ void export_shield_symbolizer()
|
|||
path_expression_ptr>("TODO")
|
||||
)
|
||||
//.def_pickle(shield_symbolizer_pickle_suite())
|
||||
.def("anchor",&shield_symbolizer::set_anchor)
|
||||
.def("displacement",&shield_symbolizer::set_shield_displacement)
|
||||
.def("get_anchor",get_anchor_list)
|
||||
.def("get_displacement",get_shield_displacement_list)
|
||||
.add_property("anchor",
|
||||
&get_anchor,
|
||||
&set_anchor)
|
||||
.add_property("allow_overlap",
|
||||
&shield_symbolizer::get_allow_overlap,
|
||||
&shield_symbolizer::set_allow_overlap,
|
||||
|
@ -135,6 +152,9 @@ void export_shield_symbolizer()
|
|||
&shield_symbolizer::get_character_spacing,
|
||||
&shield_symbolizer::set_character_spacing,
|
||||
"Set/get the character_spacing property of the label")
|
||||
.add_property("displacement",
|
||||
&get_text_displacement,
|
||||
&set_text_displacement)
|
||||
.add_property("face_name",
|
||||
make_function(&shield_symbolizer::get_face_name,return_value_policy<copy_const_reference>()),
|
||||
&shield_symbolizer::set_face_name,
|
||||
|
@ -184,6 +204,13 @@ void export_shield_symbolizer()
|
|||
.add_property("name",&shield_symbolizer::get_name,
|
||||
&shield_symbolizer::set_name)
|
||||
.add_property("opacity",
|
||||
&shield_symbolizer::get_opacity,
|
||||
&shield_symbolizer::set_opacity,
|
||||
"Set/get the shield opacity")
|
||||
.add_property("shield_displacement",
|
||||
get_shield_displacement,
|
||||
set_shield_displacement)
|
||||
.add_property("text_opacity",
|
||||
&shield_symbolizer::get_text_opacity,
|
||||
&shield_symbolizer::set_text_opacity,
|
||||
"Set/get the text opacity")
|
||||
|
@ -217,14 +244,10 @@ void export_shield_symbolizer()
|
|||
&shield_symbolizer::get_unlock_image,
|
||||
&shield_symbolizer::set_unlock_image)
|
||||
.add_property("filename",
|
||||
get_filename,
|
||||
&shield_symbolizer::set_filename)
|
||||
&get_filename,
|
||||
&set_filename)
|
||||
.add_property("transform",
|
||||
mapnik::get_svg_transform<shield_symbolizer>,
|
||||
mapnik::set_svg_transform<shield_symbolizer>)
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,27 +37,28 @@ using mapnik::to_expression_string;
|
|||
namespace {
|
||||
using namespace boost::python;
|
||||
|
||||
list get_displacement_list(const text_symbolizer& t)
|
||||
tuple get_text_displacement(const text_symbolizer& t)
|
||||
{
|
||||
position pos = t.get_displacement();
|
||||
double dx = boost::get<0>(pos);
|
||||
double dy = boost::get<1>(pos);
|
||||
boost::python::list disp;
|
||||
disp.append(dx);
|
||||
disp.append(dy);
|
||||
return disp;
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
list get_anchor_list(const text_symbolizer& t)
|
||||
|
||||
void set_text_displacement(text_symbolizer & t, boost::python::tuple arg)
|
||||
{
|
||||
position anch = t.get_anchor();
|
||||
double x = boost::get<0>(anch);
|
||||
double y = boost::get<1>(anch);
|
||||
boost::python::list anchor;
|
||||
anchor.append(x);
|
||||
anchor.append(y);
|
||||
return anchor;
|
||||
t.set_displacement(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
tuple get_anchor(const text_symbolizer& t)
|
||||
{
|
||||
position pos = t.get_anchor();
|
||||
return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos));
|
||||
}
|
||||
|
||||
void set_anchor(text_symbolizer & t, boost::python::tuple arg)
|
||||
{
|
||||
t.set_anchor(extract<double>(arg[0]),extract<double>(arg[1]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
|
@ -74,8 +75,8 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
static boost::python::tuple
|
||||
getstate(const text_symbolizer& t)
|
||||
{
|
||||
boost::python::list disp = get_displacement_list(t);
|
||||
boost::python::list anchor = get_anchor_list(t);
|
||||
boost::python::tuple disp = get_text_displacement(t);
|
||||
boost::python::tuple anchor = get_anchor(t);
|
||||
|
||||
// so we do not exceed max args accepted by make_tuple,
|
||||
// lets put the increasing list of parameters in a list
|
||||
|
@ -91,9 +92,9 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
extras.append(t.get_minimum_padding());
|
||||
|
||||
return boost::python::make_tuple(disp,t.get_label_placement(),
|
||||
t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
|
||||
t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
|
||||
anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
|
||||
t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
|
||||
t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
|
||||
anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
throw_error_already_set();
|
||||
}
|
||||
|
||||
list disp = extract<list>(state[0]);
|
||||
tuple disp = extract<tuple>(state[0]);
|
||||
double dx = extract<double>(disp[0]);
|
||||
double dy = extract<double>(disp[1]);
|
||||
t.set_displacement(dx,dy);
|
||||
|
@ -134,7 +135,7 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
|
||||
t.set_allow_overlap(extract<bool>(state[9]));
|
||||
|
||||
list anch = extract<list>(state[10]);
|
||||
tuple anch = extract<tuple>(state[10]);
|
||||
double x = extract<double>(anch[0]);
|
||||
double y = extract<double>(anch[1]);
|
||||
t.set_anchor(x,y);
|
||||
|
@ -190,15 +191,31 @@ void export_text_symbolizer()
|
|||
;
|
||||
|
||||
class_<text_symbolizer>("TextSymbolizer",init<expression_ptr,std::string const&, unsigned,color const&>())
|
||||
/*
|
||||
// todo - all python classes can have kwargs and default constructors
|
||||
class_<text_symbolizer>("TextSymbolizer",
|
||||
init<expression_ptr,std::string const&, unsigned,color const&>(
|
||||
(
|
||||
arg("name"),
|
||||
arg("font_face")="DejaVu Sans Book",
|
||||
arg("size")=10,
|
||||
arg("color")=color("black")
|
||||
),
|
||||
"Create a TextSymbolizer\n"
|
||||
))
|
||||
*/
|
||||
|
||||
//.def_pickle(text_symbolizer_pickle_suite())
|
||||
.def("anchor",&text_symbolizer::set_anchor)
|
||||
.def("displacement",&text_symbolizer::set_displacement)
|
||||
.def("get_anchor",get_anchor_list)
|
||||
.def("get_displacement",get_displacement_list)
|
||||
.add_property("anchor",
|
||||
&get_anchor,
|
||||
&set_anchor)
|
||||
.add_property("allow_overlap",
|
||||
&text_symbolizer::get_allow_overlap,
|
||||
&text_symbolizer::set_allow_overlap,
|
||||
"Set/get the allow_overlap property of the label")
|
||||
.add_property("displacement",
|
||||
&get_text_displacement,
|
||||
&set_text_displacement)
|
||||
.add_property("avoid_edges",
|
||||
&text_symbolizer::get_avoid_edges,
|
||||
&text_symbolizer::set_avoid_edges,
|
||||
|
|
Loading…
Reference in a new issue