diff --git a/bindings/python/mapnik_feature.cpp b/bindings/python/mapnik_feature.cpp index 196b30f03..e27152ae3 100644 --- a/bindings/python/mapnik_feature.cpp +++ b/bindings/python/mapnik_feature.cpp @@ -33,10 +33,12 @@ // mapnik #include +#include #include #include #include #include +#include #include namespace { @@ -62,6 +64,18 @@ void feature_add_geometries_from_wkt(Feature &feature, std::string wkt) if (!result) throw std::runtime_error("Failed to parse WKT"); } +mapnik::feature_ptr from_geojson_impl(std::string const& json, mapnik::context_ptr const& ctx) +{ + mapnik::transcoder tr("utf8"); + mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); + mapnik::json::feature_parser parser(tr); + if (!parser.parse(json.begin(), json.end(), *feature)) + { + throw std::runtime_error("Failed to parse geojson feature"); + } + return feature; +} + std::string feature_to_geojson(Feature const& feature) { std::string json; @@ -231,5 +245,7 @@ void export_feature() .def("__len__", &Feature::size) .def("context",&Feature::context) .def("to_geojson",&feature_to_geojson) + .def("from_geojson",from_geojson_impl) + .staticmethod("from_geojson") ; }