+ add to_geojson method to mapnik.Feature
This commit is contained in:
parent
3953a94636
commit
68df26baba
1 changed files with 13 additions and 0 deletions
|
@ -38,6 +38,7 @@
|
|||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/json/geojson_generator.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -62,6 +63,17 @@ void feature_add_geometries_from_wkt(Feature &feature, std::string wkt)
|
|||
if (!result) throw std::runtime_error("Failed to parse WKT");
|
||||
}
|
||||
|
||||
std::string feature_to_geojson(Feature const& feature)
|
||||
{
|
||||
std::string json;
|
||||
mapnik::json::geojson_generator g;
|
||||
if (!g.generate(json,feature))
|
||||
{
|
||||
throw std::runtime_error("Failed to generate GeoJSON");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
mapnik::value __getitem__(Feature const& feature, std::string const& name)
|
||||
{
|
||||
return feature.get(name);
|
||||
|
@ -183,5 +195,6 @@ void export_feature()
|
|||
.def("__getitem__",&__getitem2__)
|
||||
.def("__len__", &Feature::size)
|
||||
.def("context",&Feature::context)
|
||||
.def("to_geojson",&feature_to_geojson)
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue