Merge remote-tracking branch 'origin/master'

This commit is contained in:
artemp 2012-06-29 08:57:11 +01:00
commit 8849ba7d4d
14 changed files with 87 additions and 33 deletions

View file

@ -11,6 +11,8 @@ For a complete change history, see the git log.
Not yet released Not yet released
- MarkersSymbolizer width and height moved to expressions (#1102)
- Added style-level 'opacity' (#314) - Added style-level 'opacity' (#314)
- PostGIS: Added 'simplify_geometries' option - will trigger ST_Simplify on geometries before returning to Mapnik (#1179) - PostGIS: Added 'simplify_geometries' option - will trigger ST_Simplify on geometries before returning to Mapnik (#1179)

View file

@ -171,6 +171,16 @@ struct symbolizer_attributes : public boost::static_visitor<>
void operator () (markers_symbolizer const& sym) void operator () (markers_symbolizer const& sym)
{ {
expression_ptr const& height_expr = sym.get_height();
if (height_expr)
{
boost::apply_visitor(f_attr,*height_expr);
}
expression_ptr const& width_expr = sym.get_width();
if (width_expr)
{
boost::apply_visitor(f_attr,*width_expr);
}
collect_metawriter(sym); collect_metawriter(sym);
collect_transform(sym.get_image_transform()); collect_transform(sym.get_image_transform());
collect_transform(sym.get_transform()); collect_transform(sym.get_transform());

View file

@ -29,6 +29,7 @@
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/stroke.hpp> #include <mapnik/stroke.hpp>
#include <mapnik/enumeration.hpp> #include <mapnik/enumeration.hpp>
#include <mapnik/expression.hpp>
namespace mapnik { namespace mapnik {
@ -66,10 +67,10 @@ public:
double get_max_error() const; double get_max_error() const;
void set_fill(color fill); void set_fill(color fill);
color const& get_fill() const; color const& get_fill() const;
void set_width(double width); void set_width(expression_ptr width);
double get_width() const; expression_ptr get_width() const;
void set_height(double height); void set_height(expression_ptr height);
double get_height() const; expression_ptr get_height() const;
stroke const& get_stroke() const; stroke const& get_stroke() const;
void set_stroke(stroke const& stroke); void set_stroke(stroke const& stroke);
void set_marker_placement(marker_placement_e marker_p); void set_marker_placement(marker_placement_e marker_p);
@ -83,8 +84,8 @@ private:
color fill_; color fill_;
double spacing_; double spacing_;
double max_error_; double max_error_;
double width_; expression_ptr width_;
double height_; expression_ptr height_;
stroke stroke_; stroke stroke_;
marker_placement_e marker_p_; marker_placement_e marker_p_;
marker_type_e marker_type_; marker_type_e marker_type_;

View file

@ -196,8 +196,9 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
unsigned s_g=col.green(); unsigned s_g=col.green();
unsigned s_b=col.blue(); unsigned s_b=col.blue();
unsigned s_a=col.alpha(); unsigned s_a=col.alpha();
double w = sym.get_width(); double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
double h = sym.get_height(); double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
double rx = w/2.0; double rx = w/2.0;
double ry = h/2.0; double ry = h/2.0;

View file

@ -1480,8 +1480,8 @@ void cairo_renderer_base::start_map_processing(Map const& map)
stroke const& stroke_ = sym.get_stroke(); stroke const& stroke_ = sym.get_stroke();
color const& col = stroke_.get_color(); color const& col = stroke_.get_color();
double strk_width = stroke_.get_width(); double strk_width = stroke_.get_width();
double w = sym.get_width(); double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
double h = sym.get_height(); double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
double rx = w/2.0; double rx = w/2.0;
double ry = h/2.0; double ry = h/2.0;

View file

@ -152,16 +152,16 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
else else
{ {
double w; double w = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_width()))).to_double() * scale_factor_;
double h; double h = (boost::apply_visitor(evaluate<Feature,value_type>(feature), *(sym.get_height()))).to_double() * scale_factor_;
// clamp to at least 4 px otherwise interactive pixels can be too small // clamp to at least 4 px otherwise interactive pixels can be too small
if (res == 1) { if (res == 1) {
w = std::max(sym.get_width(),4.0); w = std::max(w,4.0);
h = std::max(sym.get_height(),4.0); h = std::max(h,4.0);
} else { } else {
double min = static_cast<double>(4.0/res); double min = static_cast<double>(4.0/res);
w = std::max(sym.get_width()/res,min); w = std::max(w/res,min);
h = std::max(sym.get_height()/res,min); h = std::max(h/res,min);
} }
double rx = w/2.0; double rx = w/2.0;

View file

@ -1045,8 +1045,9 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
if (allow_overlap) symbol.set_allow_overlap(*allow_overlap); if (allow_overlap) symbol.set_allow_overlap(*allow_overlap);
if (ignore_placement) symbol.set_ignore_placement(*ignore_placement); if (ignore_placement) symbol.set_ignore_placement(*ignore_placement);
optional<double> w = sym.get_opt_attr<double>("width"); optional<expression_ptr> w = sym.get_opt_attr<expression_ptr>("width");
optional<double> h = sym.get_opt_attr<double>("height"); optional<expression_ptr> h = sym.get_opt_attr<expression_ptr>("height");
if (w && h) if (w && h)
{ {
symbol.set_width(*w); symbol.set_width(*w);

View file

@ -23,6 +23,9 @@
// mapnik // mapnik
#include <mapnik/markers_symbolizer.hpp> #include <mapnik/markers_symbolizer.hpp>
// boost
#include <boost/make_shared.hpp>
namespace mapnik { namespace mapnik {
static const char * marker_placement_strings[] = { static const char * marker_placement_strings[] = {
@ -50,8 +53,8 @@ markers_symbolizer::markers_symbolizer()
fill_(color(0,0,255)), fill_(color(0,0,255)),
spacing_(100.0), spacing_(100.0),
max_error_(0.2), max_error_(0.2),
width_(10.0), width_(boost::make_shared<expr_node>(10.0)),
height_(10.0), height_(boost::make_shared<expr_node>(10.0)),
stroke_(), stroke_(),
marker_p_(MARKER_LINE_PLACEMENT), marker_p_(MARKER_LINE_PLACEMENT),
marker_type_(MARKER_ARROW) {} marker_type_(MARKER_ARROW) {}
@ -64,8 +67,8 @@ markers_symbolizer::markers_symbolizer(path_expression_ptr filename)
fill_(color(0,0,255)), fill_(color(0,0,255)),
spacing_(100.0), spacing_(100.0),
max_error_(0.2), max_error_(0.2),
width_(10.0), width_(boost::make_shared<expr_node>(10.0)),
height_(10.0), height_(boost::make_shared<expr_node>(10.0)),
stroke_(), stroke_(),
marker_p_(MARKER_LINE_PLACEMENT), marker_p_(MARKER_LINE_PLACEMENT),
marker_type_(MARKER_ARROW) {} marker_type_(MARKER_ARROW) {}
@ -134,22 +137,22 @@ color const& markers_symbolizer::get_fill() const
return fill_; return fill_;
} }
void markers_symbolizer::set_width(double width) void markers_symbolizer::set_width(expression_ptr width)
{ {
width_ = width; width_ = width;
} }
double markers_symbolizer::get_width() const expression_ptr markers_symbolizer::get_width() const
{ {
return width_; return width_;
} }
void markers_symbolizer::set_height(double height) void markers_symbolizer::set_height(expression_ptr height)
{ {
height_ = height; height_ = height;
} }
double markers_symbolizer::get_height() const expression_ptr markers_symbolizer::get_height() const
{ {
return height_; return height_;
} }

View file

@ -288,11 +288,11 @@ public:
} }
if (sym.get_width() != dfl.get_width() || explicit_defaults_) if (sym.get_width() != dfl.get_width() || explicit_defaults_)
{ {
set_attr( sym_node, "width", sym.get_width() ); set_attr( sym_node, "width", to_expression_string(*sym.get_width()) );
} }
if (sym.get_height() != dfl.get_height() || explicit_defaults_) if (sym.get_height() != dfl.get_height() || explicit_defaults_)
{ {
set_attr( sym_node, "height", sym.get_height() ); set_attr( sym_node, "height", to_expression_string(*sym.get_height()) );
} }
if (sym.get_marker_type() != dfl.get_marker_type() || explicit_defaults_) if (sym.get_marker_type() != dfl.get_marker_type() || explicit_defaults_)
{ {

View file

@ -124,5 +124,27 @@ def test_unicode_regex_replace():
expr = mapnik.Expression("[name].replace('(\B)|( )','$1 ')") expr = mapnik.Expression("[name].replace('(\B)|( )','$1 ')")
eq_(expr.evaluate(f), u'Q u é b e c') eq_(expr.evaluate(f), u'Q u é b e c')
def test_float_precision():
context = mapnik.Context()
context.push('num')
f = mapnik.Feature(context,0)
f["num"] = 1.0000
eq_(f["num"],1.0000)
expr = mapnik.Expression("[num] = 1.0000")
eq_(expr.evaluate(f),True)
expr = mapnik.Expression("[num].match('.*0$')")
eq_(expr.evaluate(f),True)
expr = mapnik.Expression("[num].match('.*0$')")
eq_(expr.evaluate(f),True)
def test_string_matching_on_precision():
context = mapnik.Context()
context.push('num')
f = mapnik.Feature(context,0)
f["num"] = "1.0000"
eq_(f["num"],"1.0000")
expr = mapnik.Expression("[num].match('.*(^0|00)$')")
eq_(expr.evaluate(f),True)
if __name__ == "__main__": if __name__ == "__main__":
[eval(run)() for run in dir() if 'test_' in run] [eval(run)() for run in dir() if 'test_' in run]

View file

@ -134,6 +134,18 @@ def test_markersymbolizer_init():
eq_(p.ignore_placement,False) eq_(p.ignore_placement,False)
eq_(p.spacing,100) eq_(p.spacing,100)
eq_(p.max_error,0.2) eq_(p.max_error,0.2)
eq_(str(p.width),'10.0')
eq_(str(p.height),'10.0')
p.width = mapnik.Expression('12')
p.height = mapnik.Expression('12')
eq_(str(p.width),'12')
eq_(str(p.height),'12')
p.width = mapnik.Expression('[field] + 2')
p.height = mapnik.Expression('[field] + 2')
eq_(str(p.width),'([field]+2)')
eq_(str(p.height),'([field]+2)')
stroke = mapnik.Stroke() stroke = mapnik.Stroke()
stroke.color = mapnik.Color('black') stroke.color = mapnik.Color('black')

View file

@ -26,7 +26,9 @@ if 'ogr' in mapnik.DatasourceCache.instance().plugin_names():
# Shapefile properties # Shapefile properties
def test_shapefile_properties(): def test_shapefile_properties():
ds = mapnik.Ogr(file='../../demo/data/boundaries.shp',layer_by_index=0,encoding='latin1') # NOTE: encoding is latin1 but gdal >= 1.9 should now expose utf8 encoded features
# See SHAPE_ENCODING for overriding: http://gdal.org/ogr/drv_shapefile.html
ds = mapnik.Ogr(file='../../demo/data/boundaries.shp',layer_by_index=0)
f = ds.features_at_point(ds.envelope().center()).features[0] f = ds.features_at_point(ds.envelope().center()).features[0]
eq_(ds.geometry_type(),mapnik.DataGeometryType.Polygon) eq_(ds.geometry_type(),mapnik.DataGeometryType.Polygon)

View file

@ -57,8 +57,8 @@ def create_grid_map(width,height):
s = mapnik.Style() s = mapnik.Style()
r = mapnik.Rule() r = mapnik.Rule()
symb = mapnik.MarkersSymbolizer() symb = mapnik.MarkersSymbolizer()
symb.width = 10 symb.width = mapnik.Expression('10')
symb.height = 10 symb.height = mapnik.Expression('10')
symb.allow_overlap = True symb.allow_overlap = True
r.symbols.append(symb) r.symbols.append(symb)

View file

@ -146,8 +146,8 @@ def test_render_grid():
s = mapnik.Style() s = mapnik.Style()
r = mapnik.Rule() r = mapnik.Rule()
symb = mapnik.MarkersSymbolizer() symb = mapnik.MarkersSymbolizer()
symb.width = 10 symb.width = mapnik.Expression('10')
symb.height = 10 symb.height = mapnik.Expression('10')
symb.allow_overlap = True symb.allow_overlap = True
r.symbols.append(symb) r.symbols.append(symb)
s.rules.append(r) s.rules.append(r)