Permalink
Browse files

expose svg output for geometries - refs #1437 (TODO: support svg_mult…

…i_generator)
  • Loading branch information...
1 parent fc63bd0 commit ce03b3599be601a0830c5623556a8d90be408ddb Dane Springmeyer committed Aug 23, 2012
Showing with 102 additions and 0 deletions.
  1. +38 −0 bindings/python/mapnik_geometry.cpp
  2. +64 −0 include/mapnik/util/geometry_to_svg.hpp
@@ -38,6 +38,7 @@
#if BOOST_VERSION >= 104700
#include <mapnik/util/geometry_to_wkb.hpp>
#include <mapnik/util/geometry_to_wkt.hpp>
+#include <mapnik/util/geometry_to_svg.hpp>
#endif
namespace {
@@ -224,6 +225,41 @@ std::string to_geojson( path_type const& geom)
return json;
}
+std::string to_svg( geometry_type const& geom)
+{
+#if BOOST_VERSION >= 104700
+ std::string svg; // Use Python String directly ?
+ bool result = mapnik::util::to_svg(svg,geom);
+ if (!result)
+ {
+ throw std::runtime_error("Generate WKT failed");
+ }
+ return svg;
+#else
+ throw std::runtime_error("mapnik::to_wkt() requires at least boost 1.47 while your build was compiled against boost "
+ + boost_version());
+#endif
+}
+
+/*
+// https://github.com/mapnik/mapnik/issues/1437
+std::string to_svg2( path_type const& geom)
+{
+#if BOOST_VERSION >= 104700
+ std::string svg; // Use Python String directly ?
+ bool result = mapnik::util::to_svg(svg,geom);
+ if (!result)
+ {
+ throw std::runtime_error("Generate WKT failed");
+ }
+ return svg;
+#else
+ throw std::runtime_error("mapnik::to_svg() requires at least boost 1.47 while your build was compiled against boost "
+ + boost_version());
+#endif
+}*/
+
+
void export_geometry()
{
using namespace boost::python;
@@ -248,6 +284,7 @@ void export_geometry()
.def("type",&geometry_type::type)
.def("to_wkb",&to_wkb)
.def("to_wkt",&to_wkt)
+ .def("to_svg",&to_svg)
// TODO add other geometry_type methods
;
@@ -259,6 +296,7 @@ void export_geometry()
.def("add_wkb",add_wkb_impl)
.def("add_geojson",add_geojson_impl)
.def("to_wkt",&to_wkt2)
+ //.def("to_svg",&to_svg2)
.def("to_wkb",&to_wkb2)
.def("from_wkt",from_wkt_impl)
.def("from_wkb",from_wkb_impl)
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2011 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+#ifndef MAPNIK_GEOMETRY_TO_SVG_HPP
+#define MAPNIK_GEOMETRY_TO_SVG_HPP
+
+// mapnik
+#include <mapnik/global.hpp>
+#include <mapnik/geometry.hpp>
+#include <mapnik/util/vertex_iterator.hpp>
+#include <mapnik/util/geometry_svg_generator.hpp>
+
+// boost
+#include <boost/spirit/include/karma.hpp>
+
+namespace mapnik { namespace util {
+
+namespace karma = boost::spirit::karma;
+
+bool to_svg(std::string & svg, mapnik::geometry_type const& geom)
+{
+ typedef std::back_insert_iterator<std::string> sink_type;
+ sink_type sink(svg);
+ svg_generator<sink_type> generator;
+ bool result = karma::generate(sink, generator, geom);
+ return result;
+}
+
+// TODO
+// https://github.com/mapnik/mapnik/issues/1437
+/*
+bool to_svg(std::string & svg, mapnik::geometry_container const& geom)
+{
+ typedef std::back_insert_iterator<std::string> sink_type;
+ sink_type sink(svg);
+ svg_multi_generator<sink_type> generator;
+ bool result = karma::generate(sink, generator, geom);
+ return result;
+}
+*/
+
+}}
+
+
+#endif // MAPNIK_GEOMETRY_TO_SVG_HPP

0 comments on commit ce03b35

Please sign in to comment.