Skip to content

Commit

Permalink
Add keys() method returning boost::python::list e.g
Browse files Browse the repository at this point in the history
```
>>> import mapnik
>>> sym = mapnik.PolygonSymbolizer()
>>> sym.keys()
[]
>>> sym.fill = mapnik.Color("skyblue")
>>> sym.fill_opacity = 0.7
>>> sym.keys()
['fill', 'fill-opacity']

```
  • Loading branch information
artemp committed Feb 1, 2023
1 parent f61bfeb commit 114bab7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mapnik_symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ boost::python::object __getitem__(mapnik::symbolizer_base const& sym, std::strin
return boost::python::object();
}

boost::python::object symbolizer_keys(mapnik::symbolizer_base const& sym)
{
using const_iterator = symbolizer_base::cont_type::const_iterator;
boost::python::list keys;
for (auto const& kv : sym.properties)
{
std::string name = std::get<0>(mapnik::get_meta(kv.first));
keys.append(name);
}
return keys;
}
/*
std::string __str__(mapnik::symbolizer const& sym)
{
Expand Down Expand Up @@ -268,6 +279,7 @@ void export_symbolizer()
.def("__setattr__",&__setitem__)
.def("__getitem__",&__getitem__)
.def("__getattr__",&__getitem__)
.def("keys", &symbolizer_keys)
//.def("__str__", &__str__)
.def(self == self) // __eq__
;
Expand Down

0 comments on commit 114bab7

Please sign in to comment.