GeoJSON generator - implement using geometry<double> karma adapters

This commit is contained in:
artemp 2016-09-20 11:01:38 +02:00 committed by Mickey Rose
parent b770db56c3
commit ab86171c2b
6 changed files with 50 additions and 86 deletions

View file

@ -63,17 +63,6 @@ struct end_container<mapnik::feature_impl const>
}
};
template <>
struct transform_attribute<const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>,
mapnik::geometry::geometry<double> const& , karma::domain>
{
using type = mapnik::geometry::geometry<double> const&;
static type pre(const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>& f)
{
return boost::fusion::at<mpl::int_<0> >(f).get_geometry();
}
};
}}}
namespace mapnik { namespace json {
@ -91,6 +80,15 @@ struct get_id
}
};
struct extract_geometry
{
using result_type = mapnik::geometry::geometry<double> const&;
template <typename T>
result_type operator() (T const& f) const
{
return f.get_geometry();
}
};
template <typename OutputIterator, typename FeatureType>
struct feature_generator_grammar :
@ -101,6 +99,7 @@ struct feature_generator_grammar :
geometry_generator_grammar<OutputIterator, mapnik::geometry::geometry<double> > geometry;
properties_generator_grammar<OutputIterator, FeatureType> properties;
boost::phoenix::function<get_id<FeatureType> > id_;
boost::phoenix::function<extract_geometry> geom_;
};
}}

View file

@ -40,7 +40,7 @@ feature_generator_grammar<OutputIterator, FeatureType>::feature_generator_gramma
feature = lit("{\"type\":\"Feature\",\"id\":")
<< uint_[_1 = id_(_val)]
<< lit(",\"geometry\":") << geometry
<< lit(",\"geometry\":") << geometry[_1 = geom_(_val)]
<< lit(",\"properties\":") << properties
<< lit('}')
;

View file

@ -26,13 +26,10 @@
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/geometry/geometry_type.hpp>
// boost
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/math/special_functions/trunc.hpp> // for vc++ and android whose c++11 libs lack std::trunc
#include <boost/spirit/home/karma/domain.hpp>
#pragma GCC diagnostic pop
@ -43,18 +40,6 @@ namespace karma = boost::spirit::karma;
namespace detail {
template <typename Geometry>
struct get_type
{
using result_type = mapnik::geometry::geometry_types;
template <typename T>
result_type operator() (T const& geom) const
{
auto type = mapnik::geometry::geometry_type(geom);
return type;
}
};
template <typename T>
struct json_coordinate_policy : karma::real_policies<T>
{
@ -88,29 +73,29 @@ struct json_coordinate_policy : karma::real_policies<T>
template <typename OutputIterator, typename Geometry>
struct geometry_generator_grammar :
karma::grammar<OutputIterator, Geometry const&()>
karma::grammar<OutputIterator, Geometry()>
{
using coord_type = typename Geometry::coord_type;
geometry_generator_grammar();
karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, geometry::polygon<double>::rings_container const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<double> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<double> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<double> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::real_generator<double, detail::json_coordinate_policy<double> > coordinate;
karma::rule<OutputIterator, Geometry()> geometry;
karma::rule<OutputIterator, geometry::point<coord_type>()> point;
karma::rule<OutputIterator, geometry::point<coord_type>()> point_coord;
karma::rule<OutputIterator, geometry::line_string<coord_type>()> linestring;
karma::rule<OutputIterator, geometry::line_string<coord_type>()> linestring_coord;
karma::rule<OutputIterator, geometry::polygon<coord_type>()> polygon;
karma::rule<OutputIterator, geometry::polygon<coord_type>()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<coord_type>()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<coord_type> >()> interior_ring_coord;
karma::rule<OutputIterator, geometry::multi_point<coord_type>()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<coord_type>()> multi_point_coord;
karma::rule<OutputIterator, geometry::multi_line_string<coord_type>()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<coord_type> ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::multi_polygon<coord_type>()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<coord_type>()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry_collection<coord_type>()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<coord_type>()> geometries;
//
karma::real_generator<coord_type, detail::json_coordinate_policy<coord_type> > coordinate;
};

View file

@ -22,60 +22,33 @@
// mapnik
#include <mapnik/json/geometry_generator_grammar.hpp>
#include <mapnik/util/spirit_transform_attribute.hpp>
#include <mapnik/geometry/geometry_types.hpp>
#include <mapnik/geometry/fusion_adapted.hpp>
// boost
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/fusion/include/at.hpp>
#pragma GCC diagnostic pop
namespace mapnik { namespace json {
namespace karma = boost::spirit::karma;
namespace phoenix = boost::phoenix;
template <typename OutputIterator, typename Geometry>
geometry_generator_grammar<OutputIterator, Geometry>::geometry_generator_grammar()
: geometry_generator_grammar::base_type(geometry)
{
boost::spirit::karma::_val_type _val;
boost::spirit::karma::_1_type _1;
boost::spirit::karma::_a_type _a;
boost::spirit::karma::lit_type lit;
boost::spirit::karma::uint_type uint_;
boost::spirit::karma::eps_type eps;
geometry = geometry_dispatch.alias()
;
geometry_dispatch = eps[_a = geometry_type(_val)] <<
(&uint_(geometry::geometry_types::Point)[_1 = _a]
<< (point | lit("null")))
geometry =
point
|
(&uint_(geometry::geometry_types::LineString)[_1 = _a]
<< (linestring | lit("null")))
linestring
|
(&uint_(geometry::geometry_types::Polygon)[_1 = _a]
<< (polygon | lit("null")))
polygon
|
(&uint_(geometry::geometry_types::MultiPoint)[_1 = _a]
<< (multi_point | lit("null")))
multi_point
|
(&uint_(geometry::geometry_types::MultiLineString)[_1 = _a]
<< (multi_linestring | lit("null")))
multi_linestring
|
(&uint_(geometry::geometry_types::MultiPolygon)[_1 = _a]
<< (multi_polygon | lit("null")))
multi_polygon
|
(&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a]
<< (geometry_collection | lit("null")))
geometry_collection
|
lit("null")
;

View file

@ -23,6 +23,14 @@
#include <mapnik/json/properties_generator_grammar.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop
namespace mapnik { namespace json {
namespace karma = boost::spirit::karma;

View file

@ -20,8 +20,7 @@
*
*****************************************************************************/
#include <mapnik/geometry.hpp>
#include <mapnik/geometry/boost_spirit_karma_adapter.hpp>
#include <mapnik/json/geometry_generator_grammar_impl.hpp>
#include <mapnik/json/properties_generator_grammar_impl.hpp>
#include <mapnik/json/feature_generator_grammar_impl.hpp>
@ -31,5 +30,5 @@
using sink_type = std::back_insert_iterator<std::string>;
template struct mapnik::json::properties_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::feature_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry<double> >;
template struct mapnik::json::feature_generator_grammar<sink_type, mapnik::feature_impl>;