root/trunk/bindings/python/mapnik_raster_symbolizer.cpp

Revision 1814, 5.0 kB (checked in by artem, 2 months ago)

+ apply 'mapnik-format' to *.cpp *.hpp

Line 
1/*****************************************************************************
2 *
3 * This file is part of Mapnik (c++ mapping toolkit)
4 *
5 * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 *
21 *****************************************************************************/
22//$Id$
23
24#include <boost/python.hpp>
25#include <mapnik/raster_symbolizer.hpp>
26
27using mapnik::raster_symbolizer;
28
29struct raster_symbolizer_pickle_suite : boost::python::pickle_suite
30{
31    /*
32      static boost::python::tuple
33      getinitargs(const raster_symbolizer& r)
34      {
35      return boost::python::make_tuple(); 
36      }
37    */
38
39    static  boost::python::tuple
40    getstate(const raster_symbolizer& r)
41    {
42        return boost::python::make_tuple(r.get_mode(),r.get_scaling(),r.get_opacity());
43    }
44
45    static void
46    setstate (raster_symbolizer& r, boost::python::tuple state)
47    {
48        using namespace boost::python;
49        if (len(state) != 3)
50        {
51            PyErr_SetObject(PyExc_ValueError,
52                            ("expected 3-item tuple in call to __setstate__; got %s"
53                             % state).ptr()
54                );
55            throw_error_already_set();
56        }
57               
58        r.set_mode(extract<std::string>(state[0]));
59        r.set_scaling(extract<std::string>(state[1]));
60        r.set_opacity(extract<float>(state[2]));
61    }
62
63};
64
65void export_raster_symbolizer()
66{
67    using namespace boost::python;
68
69    class_<raster_symbolizer>("RasterSymbolizer",
70                              init<>("Default ctor"))
71                                   
72        .def_pickle(raster_symbolizer_pickle_suite())
73   
74        .add_property("mode",
75                      make_function(&raster_symbolizer::get_mode,return_value_policy<copy_const_reference>()),
76                      &raster_symbolizer::set_mode,
77                      "Get/Set merging mode.\n"
78                      "Possible values are:\n"
79                      "normal, grain_merge, grain_merge2, multiply,\n"
80                      "multiply2, divide, divide2, screen, and hard_light\n"
81                      "\n"
82                      "Usage:\n"
83                      "\n"
84                      ">>> from mapnik import RasterSymbolizer\n"
85                      ">>> r = RasterSymbolizer()\n"
86                      ">>> r.mode = 'grain_merge2'\n"
87            )
88           
89        .add_property("scaling",
90                      make_function(&raster_symbolizer::get_scaling,return_value_policy<copy_const_reference>()),
91                      &raster_symbolizer::set_scaling,
92                      "Get/Set scaling algorithm.\n"
93                      "Possible values are:\n"
94                      "fast, bilinear, and bilinear8\n"
95                      "\n"
96                      "Usage:\n"
97                      "\n"
98                      ">>> from mapnik import RasterSymbolizer\n"
99                      ">>> r = RasterSymbolizer()\n"
100                      ">>> r.scaling = 'bilinear8'\n"
101            )
102           
103        .add_property("opacity",
104                      &raster_symbolizer::get_opacity,
105                      &raster_symbolizer::set_opacity,
106                      "Get/Set opacity.\n"
107                      "\n"
108                      "Usage:\n"
109                      "\n"
110                      ">>> from mapnik import RasterSymbolizer\n"
111                      ">>> r = RasterSymbolizer()\n"
112                      ">>> r.opacity = .5\n"
113            )
114        .add_property("colorizer",
115                      &raster_symbolizer::get_colorizer,
116                      &raster_symbolizer::set_colorizer,
117                      "Get/Set the RasterColorizer used to color data rasters.\n"
118                      "\n"
119                      "Usage:\n"
120                      "\n"
121                      ">>> from mapnik import RasterSymbolizer, RasterColorizer\n"
122                      ">>> r = RasterSymbolizer()\n"
123                      ">>> r.colorizer = RasterColorizer()\n"
124                      ">>> for value, color in [\n"
125                      "...     (0, \"#000000\"),\n"
126                      "...     (10, \"#ff0000\"),\n"
127                      "...     (40, \"#00ff00\"),\n"
128                      "... ]:\n"
129                      "...      r.colorizer.append_band(value, color)\n"
130            )
131        ;   
132}
Note: See TracBrowser for help on using the browser.