-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathmapnik_line_symbolizer.cpp
More file actions
146 lines (132 loc) · 6.05 KB
/
mapnik_line_symbolizer.cpp
File metadata and controls
146 lines (132 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2024 Artem Pavlenko
*
* 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
*
*****************************************************************************/
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/symbolizer_hash.hpp>
#include <mapnik/symbolizer_utils.hpp>
#include <mapnik/symbolizer_keys.hpp>
#include "mapnik_symbolizer.hpp"
//pybind11
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/native_enum.h>
namespace py = pybind11;
namespace {
std::string get_stroke_dasharray(mapnik::symbolizer_base & sym)
{
auto dash = mapnik::get<mapnik::dash_array>(sym, mapnik::keys::stroke_dasharray);
std::ostringstream os;
for (std::size_t i = 0; i < dash.size(); ++i)
{
os << dash[i].first << "," << dash[i].second;
if (i + 1 < dash.size())
os << ",";
}
return os.str();
}
void set_stroke_dasharray(mapnik::symbolizer_base & sym, std::string str)
{
mapnik::dash_array dash;
if (mapnik::util::parse_dasharray(str, dash))
{
mapnik::put(sym, mapnik::keys::stroke_dasharray, dash);
}
else
{
throw std::runtime_error("Can't parse dasharray");
}
}
}
void export_line_symbolizer(py::module const& m)
{
using namespace python_mapnik;
using mapnik::line_symbolizer;
py::native_enum<mapnik::line_rasterizer_enum>(m, "line_rasterizer", "enum.Enum")
.value("FULL",mapnik::line_rasterizer_enum::RASTERIZER_FULL)
.value("FAST",mapnik::line_rasterizer_enum::RASTERIZER_FAST)
.finalize()
;
py::native_enum<mapnik::line_cap_enum>(m, "stroke_linecap", "enum.Enum")
.value("BUTT_CAP",mapnik::line_cap_enum::BUTT_CAP)
.value("SQUARE_CAP",mapnik::line_cap_enum::SQUARE_CAP)
.value("ROUND_CAP",mapnik::line_cap_enum::ROUND_CAP)
.finalize()
;
py::native_enum<mapnik::line_join_enum>(m, "stroke_linejoin", "enum.Enum")
.value("MITER_JOIN",mapnik::line_join_enum::MITER_JOIN)
.value("MITER_REVERT_JOIN",mapnik::line_join_enum::MITER_REVERT_JOIN)
.value("ROUND_JOIN",mapnik::line_join_enum::ROUND_JOIN)
.value("BEVEL_JOIN",mapnik::line_join_enum::BEVEL_JOIN)
.finalize()
;
py::class_<line_symbolizer, symbolizer_base>(m, "LineSymbolizer")
.def(py::init<>(), "Default LineSymbolizer - 1px solid black")
.def("__hash__",hash_impl_2<line_symbolizer>)
.def_property("stroke",
&get_property<line_symbolizer, mapnik::keys::stroke>,
&set_color_property<line_symbolizer, mapnik::keys::stroke>,
"Stroke color")
.def_property("stroke_width",
&get_property<line_symbolizer,mapnik::keys::stroke_width>,
&set_double_property<line_symbolizer, mapnik::keys::stroke_width>,
"Stroke width")
.def_property("stroke_opacity",
&get_property<line_symbolizer,mapnik::keys::stroke_opacity>,
&set_double_property<line_symbolizer, mapnik::keys::stroke_opacity>,
"Stroke opacity")
.def_property("stroke_gamma",
&get_property<line_symbolizer,mapnik::keys::stroke_gamma>,
&set_double_property<line_symbolizer,mapnik::keys::stroke_gamma>,
"Stroke gamma")
.def_property("stroke_gamma_method",
&get<mapnik::gamma_method_enum, mapnik::keys::stroke_gamma_method>,
&set_enum_property<line_symbolizer, mapnik::gamma_method_enum, mapnik::keys::stroke_gamma_method>,
"Stroke gamma method")
.def_property("line_rasterizer",
&get<mapnik::line_rasterizer_enum, mapnik::keys::line_rasterizer>,
&set_enum_property<line_symbolizer, mapnik::line_rasterizer_enum, mapnik::keys::line_rasterizer>,
"Line rasterizer")
.def_property("stroke_linecap",
&get<mapnik::line_cap_enum, mapnik::keys::stroke_linecap>,
&set_enum_property<line_symbolizer, mapnik::line_cap_enum, mapnik::keys::stroke_linecap>,
"Stroke linecap")
.def_property("stroke_linejoin",
&get<mapnik::line_join_enum, mapnik::keys::stroke_linejoin>,
&set_enum_property<line_symbolizer, mapnik::line_join_enum, mapnik::keys::stroke_linejoin>,
"Stroke linejoin")
.def_property("stroke_dasharray",
&get_stroke_dasharray,
&set_stroke_dasharray,
"Stroke dasharray")
.def_property("stroke_dashoffset",
&get_property<line_symbolizer, mapnik::keys::stroke_dashoffset>,
&set_double_property<line_symbolizer,mapnik::keys::stroke_dashoffset>,
"Stroke dashoffset")
.def_property("stroke_miterlimit",
&get_property<line_symbolizer, mapnik::keys::stroke_miterlimit>,
&set_double_property<line_symbolizer, mapnik::keys::stroke_miterlimit>,
"Stroke miterlimit")
;
}