From b76c8e5c646cc8a5ba6b2f1c17fda9bc3d11692c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 20 Aug 2012 18:17:00 -0700 Subject: [PATCH] +reflect building symbolizer in python --- CHANGELOG.md | 2 + .../python/mapnik_building_symbolizer.cpp | 50 +++++++++++++++++++ bindings/python/mapnik_python.cpp | 2 + include/mapnik/building_symbolizer.hpp | 6 +-- src/building_symbolizer.cpp | 6 +-- tests/python_tests/object_test.py | 23 ++++----- 6 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 bindings/python/mapnik_building_symbolizer.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index fabc718de..89d6952f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ TODO - fill these out more: - geometry closed - feature api better - context's provide schema support +- Python: exposed BuildingSymbolizer + - Support in the CSV plugin for reading JSON encoded geometries (#1392) - Increased grid encoding performance (#1315) diff --git a/bindings/python/mapnik_building_symbolizer.cpp b/bindings/python/mapnik_building_symbolizer.cpp new file mode 100644 index 000000000..f8892f167 --- /dev/null +++ b/bindings/python/mapnik_building_symbolizer.cpp @@ -0,0 +1,50 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2012 Artem Pavlenko, Jean-Francois Doyon + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include + +using namespace mapnik; +using mapnik::building_symbolizer; +using mapnik::color; + +void export_building_symbolizer() +{ + using namespace boost::python; + + class_("BuildingSymbolizer", + init<>("Default BuildingSymbolizer")) + .add_property("fill",make_function + (&building_symbolizer::get_fill, + return_value_policy()), + &building_symbolizer::set_fill) + .add_property("fill_opacity", + &building_symbolizer::get_opacity, + &building_symbolizer::set_opacity) + .add_property("height", + make_function(&building_symbolizer::height, + return_value_policy()), + &building_symbolizer::set_height, + "Set/get the building height") + ; + +} diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index ae6b18e90..705d4fdd6 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -57,6 +57,7 @@ void export_point_symbolizer(); void export_line_symbolizer(); void export_line_pattern_symbolizer(); void export_polygon_symbolizer(); +void export_building_symbolizer(); void export_polygon_pattern_symbolizer(); void export_raster_symbolizer(); void export_text_placement(); @@ -395,6 +396,7 @@ BOOST_PYTHON_MODULE(_mapnik) export_line_symbolizer(); export_line_pattern_symbolizer(); export_polygon_symbolizer(); + export_building_symbolizer(); export_polygon_pattern_symbolizer(); export_raster_symbolizer(); export_text_placement(); diff --git a/include/mapnik/building_symbolizer.hpp b/include/mapnik/building_symbolizer.hpp index 3214b7a2a..ad77d0aeb 100644 --- a/include/mapnik/building_symbolizer.hpp +++ b/include/mapnik/building_symbolizer.hpp @@ -34,11 +34,11 @@ namespace mapnik struct MAPNIK_DECL building_symbolizer : public symbolizer_base { building_symbolizer(); - building_symbolizer(color const& fill, expression_ptr height); + building_symbolizer(color const& fill, expression_ptr const& height); color const& get_fill() const; void set_fill(color const& fill); - expression_ptr height() const; - void set_height(expression_ptr height); + expression_ptr const& height() const; + void set_height(expression_ptr const& height); void set_opacity(double opacity); double get_opacity() const; diff --git a/src/building_symbolizer.cpp b/src/building_symbolizer.cpp index 9a85d2bc7..4cf722882 100644 --- a/src/building_symbolizer.cpp +++ b/src/building_symbolizer.cpp @@ -32,7 +32,7 @@ building_symbolizer::building_symbolizer() opacity_(1.0) {} -building_symbolizer::building_symbolizer(color const& fill, expression_ptr height) +building_symbolizer::building_symbolizer(color const& fill, expression_ptr const& height) : symbolizer_base(), fill_(fill), height_(height), @@ -47,12 +47,12 @@ void building_symbolizer::set_fill(color const& fill) { fill_ = fill; } -expression_ptr building_symbolizer::height() const +expression_ptr const& building_symbolizer::height() const { return height_; } -void building_symbolizer::set_height(expression_ptr height) +void building_symbolizer::set_height(expression_ptr const& height) { height_=height; } diff --git a/tests/python_tests/object_test.py b/tests/python_tests/object_test.py index e43ac30eb..18b941e62 100644 --- a/tests/python_tests/object_test.py +++ b/tests/python_tests/object_test.py @@ -107,18 +107,12 @@ def test_shieldsymbolizer_modify(): check_transform("scale([sx], [sy]/2)") # TODO check expected failures -def test_polygonsymbolizer_init(): - p = mapnik.PolygonSymbolizer() - - eq_(p.fill, mapnik.Color('gray')) - eq_(p.fill_opacity, 1) +def test_point_symbolizer_init(): + p = mapnik.PointSymbolizer() eq_(p.placement, mapnik.point_placement.CENTROID) - p = mapnik.PolygonSymbolizer(mapnik.Color('blue')) + p = mapnik.PointSymbolizer() p.placement = mapnik.point_placement.INTERIOR - - eq_(p.fill, mapnik.Color('blue')) - eq_(p.fill_opacity, 1) eq_(p.placement, mapnik.point_placement.INTERIOR) # PointSymbolizer initialization @@ -189,8 +183,7 @@ def test_markersymbolizer_init(): #def test_pointsymbolizer_missing_image(): # p = mapnik.PointSymbolizer(mapnik.PathExpression("../data/images/broken.png")) -# PolygonSymbolizer initialization -def test_polygonsymbolizer_init(): +def test_polygon_symbolizer_init(): p = mapnik.PolygonSymbolizer() eq_(p.fill, mapnik.Color('gray')) @@ -201,7 +194,13 @@ def test_polygonsymbolizer_init(): eq_(p.fill, mapnik.Color('blue')) eq_(p.fill_opacity, 1) -# Stroke initialization +def test_building_symbolizer_init(): + p = mapnik.BuildingSymbolizer() + + eq_(p.fill, mapnik.Color('gray')) + eq_(p.fill_opacity, 1) + eq_(p.height,None) + def test_stroke_init(): s = mapnik.Stroke()