+ add to_geojson() method to mapnik.Path

This commit is contained in:
Artem Pavlenko 2012-02-20 12:05:11 +00:00
parent 6e498ad062
commit f20007a965
2 changed files with 13 additions and 1 deletions

View file

@ -66,7 +66,7 @@ void feature_add_geometries_from_wkt(Feature &feature, std::string wkt)
std::string feature_to_geojson(Feature const& feature)
{
std::string json;
mapnik::json::geojson_generator g;
mapnik::json::feature_generator g;
if (!g.generate(json,feature))
{
throw std::runtime_error("Failed to generate GeoJSON");

View file

@ -32,6 +32,7 @@
#include <mapnik/geometry.hpp>
#include <mapnik/wkt/wkt_factory.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/json/geojson_generator.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 104700
@ -163,6 +164,16 @@ std::string to_wkt2( path_type const& geom)
#endif
}
std::string to_geojson( path_type const& geom)
{
std::string json;
mapnik::json::geometry_generator g;
if (!g.generate(json,geom))
{
throw std::runtime_error("Failed to generate GeoJSON");
}
return json;
}
void export_geometry()
{
@ -200,6 +211,7 @@ void export_geometry()
.def("to_wkb",&to_wkb2)
.def("from_wkt",from_wkt_impl)
.def("from_wkb",from_wkb_impl)
.def("to_geojson",to_geojson)
.staticmethod("from_wkt")
.staticmethod("from_wkb")
;