python bindings - restore from_wkt method

This commit is contained in:
artemp 2015-03-11 12:28:04 +01:00
parent 525cb60f0c
commit 26fdd0b680
2 changed files with 17 additions and 26 deletions

View file

@ -46,7 +46,7 @@
#include <mapnik/geometry_is_simple.hpp>
#include <mapnik/geometry_correct.hpp>
//#include <mapnik/wkt/wkt_factory.hpp> // from_wkt
#include <mapnik/wkt/wkt_factory.hpp> // from_wkt
//#include <mapnik/util/geometry_to_wkt.hpp>
#include <mapnik/json/geometry_parser.hpp> // from_geojson
#include <mapnik/util/geometry_to_geojson.hpp>
@ -101,6 +101,14 @@ namespace {
// return paths;
//}
std::shared_ptr<mapnik::new_geometry::geometry> from_wkt_impl(std::string const& wkt)
{
std::shared_ptr<mapnik::new_geometry::geometry> geom = std::make_shared<mapnik::new_geometry::geometry>();
if (!mapnik::from_wkt(wkt, *geom))
throw std::runtime_error("Failed to parse WKT geometry");
return geom;
}
std::shared_ptr<mapnik::new_geometry::geometry> from_geojson_impl(std::string const& json)
{
std::shared_ptr<mapnik::new_geometry::geometry> geom = std::make_shared<mapnik::new_geometry::geometry>();
@ -109,26 +117,6 @@ std::shared_ptr<mapnik::new_geometry::geometry> from_geojson_impl(std::string co
return geom;
}
//mapnik::box2d<double> envelope_impl2(mapnik::geometry_container & p)
//{
// mapnik::box2d<double> b;
// bool first = true;
// for (mapnik::geometry_type const& geom : p)
// {
// auto bbox = ::mapnik::envelope(geom);
// if (first)
// {
// b = bbox;
// first=false;
// }
// else
// {
// b.expand_to_include(bbox);
// }
// }
// return b;
//}
}
inline std::string boost_version()
@ -289,7 +277,9 @@ void export_geometry()
class_<geometry, std::shared_ptr<geometry>, boost::noncopyable>("Geometry",no_init)
.def("envelope",&geometry_envelope_impl)
.def("from_geojson", from_geojson_impl)
.def("from_wkt", from_wkt_impl)
.staticmethod("from_geojson")
.staticmethod("from_wkt")
// .def("__str__",&mapnik::geometry_type::to_string)
.def("type",&geometry_type_impl)
.def("is_valid", &geometry_is_valid_impl)

View file

@ -24,7 +24,7 @@
#define MAPNIK_WKT_FACTORY_HPP
// mapnik
#include <mapnik/geometry.hpp>
#include <mapnik/geometry_impl.hpp>
#include <mapnik/wkt/wkt_grammar.hpp>
#include <mapnik/wkt/wkt_generator_grammar.hpp>
@ -35,16 +35,17 @@
namespace mapnik {
inline bool from_wkt(std::string const& wkt, mapnik::geometry_container & paths)
inline bool from_wkt(std::string const& wkt, mapnik::new_geometry::geometry & geom)
{
using namespace boost::spirit;
static const mapnik::wkt::wkt_collection_grammar<std::string::const_iterator> g;
static const mapnik::wkt::wkt_grammar<std::string::const_iterator> g;
ascii::space_type space;
std::string::const_iterator first = wkt.begin();
std::string::const_iterator last = wkt.end();
return qi::phrase_parse(first, last, g, space, paths);
return qi::phrase_parse(first, last, (g)(boost::phoenix::ref(geom)), space);
}
#if 0 // FIXME
inline bool to_wkt(mapnik::geometry_container const& paths, std::string& wkt)
{
using sink_type = std::back_insert_iterator<std::string>;
@ -52,7 +53,7 @@ inline bool to_wkt(mapnik::geometry_container const& paths, std::string& wkt)
sink_type sink(wkt);
return boost::spirit::karma::generate(sink, generator, paths);
}
#endif
}