remove spirit::qi usage from (Geo)JSON
This commit is contained in:
parent
0ec510025d
commit
941a025682
17 changed files with 0 additions and 1373 deletions
|
@ -1,64 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
|
||||
#define MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/json/generic_json.hpp>
|
||||
#include <mapnik/json/error_handler.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator, typename Boxes, typename ErrorHandler = error_handler<Iterator> >
|
||||
struct extract_bounding_box_grammar :
|
||||
qi::grammar<Iterator, void(Boxes&), space_type>
|
||||
{
|
||||
using position_type = mapnik::geometry::point<double>;
|
||||
using boxes_type = Boxes;
|
||||
using box_type = typename Boxes::value_type::first_type;
|
||||
extract_bounding_box_grammar();
|
||||
// rules
|
||||
qi::rule<Iterator, void(boxes_type&), space_type> start;
|
||||
qi::rule<Iterator, qi::locals<Iterator>, void(boxes_type&), space_type> features;
|
||||
qi::rule<Iterator, qi::locals<int, box_type>, void(boxes_type&, Iterator const&), space_type> feature;
|
||||
qi::rule<Iterator, qi::locals<box_type>, box_type(), space_type> coords;
|
||||
qi::rule<Iterator, boost::optional<position_type>(), space_type> pos;
|
||||
qi::rule<Iterator, void(box_type&), space_type> ring;
|
||||
qi::rule<Iterator, void(box_type&), space_type> rings;
|
||||
qi::rule<Iterator, void(box_type&), space_type> rings_array;
|
||||
// generic JSON support
|
||||
json::generic_json<Iterator> json;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOX_GRAMMAR_HPP
|
|
@ -1,157 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/json/extract_bounding_box_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/qi_omit.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
#include <boost/spirit/include/phoenix_stl.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
// stl
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
struct calculate_bounding_box_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename T0, typename T1>
|
||||
result_type operator() (T0 & bbox, T1 const& pos) const
|
||||
{
|
||||
if (pos)
|
||||
{
|
||||
typename T0::value_type x = pos->x;
|
||||
typename T0::value_type y = pos->y;
|
||||
if (!bbox.valid())
|
||||
{
|
||||
bbox.init(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
bbox.expand_to_include(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct push_box_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const
|
||||
{
|
||||
if (box.valid()) boxes.emplace_back(box,
|
||||
std::make_pair(std::distance(begin,
|
||||
range.begin()),
|
||||
std::distance(range.begin(), range.end())));
|
||||
}
|
||||
};
|
||||
|
||||
namespace repo = boost::spirit::repository;
|
||||
|
||||
template <typename Iterator, typename Boxes, typename ErrorHandler>
|
||||
extract_bounding_box_grammar<Iterator, Boxes, ErrorHandler>::extract_bounding_box_grammar()
|
||||
: extract_bounding_box_grammar::base_type(start, "GeoJSON bounding boxes")
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
qi::_val_type _val;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::omit_type omit;
|
||||
qi::_r1_type _r1;
|
||||
qi::_r2_type _r2;
|
||||
qi::_a_type _a;
|
||||
qi::_b_type _b;
|
||||
qi::eps_type eps;
|
||||
qi::raw_type raw;
|
||||
qi::char_type char_;
|
||||
qi::no_skip_type no_skip;
|
||||
boost::spirit::repository::qi::iter_pos_type iter_pos;
|
||||
using qi::fail;
|
||||
using qi::on_error;
|
||||
|
||||
// phoenix functions
|
||||
boost::phoenix::function<push_box_impl> push_box;
|
||||
boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;
|
||||
// error handler
|
||||
boost::phoenix::function<ErrorHandler> const error_handler;
|
||||
|
||||
start = features(_r1)
|
||||
;
|
||||
|
||||
features = no_skip[iter_pos[_a = _1]] >> -(lit('{')
|
||||
>> *((json.key_value - lit("\"features\"")) >> lit(','))
|
||||
>> lit("\"features\"")
|
||||
>> lit(':'))
|
||||
>> lit('[') >> -(feature(_r1,_a) % lit(',')) >> lit(']')
|
||||
;
|
||||
|
||||
feature = raw[lit('{')[_a = 1]
|
||||
>> *(eps(_a > 0) >> (
|
||||
lit("\"FeatureCollection\"") > eps(false) // fail if nested FeatureCollection
|
||||
|
|
||||
lit('{')[_a += 1]
|
||||
|
|
||||
lit('}')[_a -= 1]
|
||||
|
|
||||
coords[_b = _1]
|
||||
|
|
||||
json.string_
|
||||
|
|
||||
char_))][push_box(_r1, _r2, _b, _1)]
|
||||
;
|
||||
|
||||
coords = lit("\"coordinates\"")
|
||||
>> lit(':') >> (rings_array(_a) | rings (_a) | ring(_a) | pos[calculate_bounding_box(_a,_1)])[_val = _a]
|
||||
;
|
||||
|
||||
pos = lit('[') > -(double_ > lit(',') > double_) > omit[*(lit(',') > double_)] > lit(']')
|
||||
;
|
||||
|
||||
ring = lit('[') >> pos[calculate_bounding_box(_r1,_1)] % lit(',') > lit(']')
|
||||
;
|
||||
|
||||
rings = lit('[') >> ring(_r1) % lit(',') > lit(']')
|
||||
;
|
||||
|
||||
rings_array = lit('[') >> rings(_r1) % lit(',') > lit(']')
|
||||
;
|
||||
|
||||
coords.name("Coordinates");
|
||||
pos.name("Position");
|
||||
ring.name("Ring");
|
||||
rings.name("Rings");
|
||||
rings_array.name("Rings array");
|
||||
|
||||
// error handler
|
||||
on_error<fail>(coords, error_handler(_1, _2, _3, _4));
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,103 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_FEATURE_COLLECTION_GRAMMAR_HPP
|
||||
#define MAPNIK_FEATURE_COLLECTION_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
#include <mapnik/json/feature_grammar.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
|
||||
// spirit::qi
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
namespace phoenix = boost::phoenix;
|
||||
|
||||
struct default_feature_callback
|
||||
{
|
||||
default_feature_callback(std::vector<feature_ptr> & features)
|
||||
: features_(features) {}
|
||||
void operator() (feature_ptr const& feature)
|
||||
{
|
||||
features_.push_back(feature);
|
||||
}
|
||||
std::vector<feature_ptr> & features_;
|
||||
};
|
||||
|
||||
struct apply_feature_callback
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename Callback, typename Feature>
|
||||
void operator() (Callback & callback, Feature const& feature) const
|
||||
{
|
||||
callback(feature);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename FeatureCallback = default_feature_callback, typename ErrorHandler = error_handler<Iterator> >
|
||||
struct feature_collection_grammar :
|
||||
qi::grammar<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback &), space_type>
|
||||
{
|
||||
feature_collection_grammar(mapnik::transcoder const& tr);
|
||||
// grammars
|
||||
feature_grammar<Iterator, FeatureType, ErrorHandler> feature_g;
|
||||
// rules
|
||||
qi::rule<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback&), space_type> start; // START
|
||||
qi::rule<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback&), space_type> feature_collection;
|
||||
qi::rule<Iterator, space_type> type;
|
||||
qi::rule<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback&), space_type> features;
|
||||
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature;
|
||||
// phoenix functions
|
||||
phoenix::function<apply_feature_callback> on_feature;
|
||||
// error handler
|
||||
boost::phoenix::function<ErrorHandler> const error_handler;
|
||||
};
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename FeatureCallback = default_feature_callback, typename ErrorHandler = error_handler<Iterator> >
|
||||
struct feature_grammar_callback :
|
||||
qi::grammar<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback &), space_type>
|
||||
{
|
||||
feature_grammar_callback(mapnik::transcoder const& tr);
|
||||
// grammars
|
||||
feature_grammar<Iterator, FeatureType> feature_g;
|
||||
geometry_grammar<Iterator> geometry_g;
|
||||
// rules
|
||||
qi::rule<Iterator, void(context_ptr const&, std::size_t&, FeatureCallback&), space_type> start; // START
|
||||
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature;
|
||||
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::size_t, FeatureCallback&), space_type> feature_from_geometry;
|
||||
// phoenix functions
|
||||
phoenix::function<json::set_geometry_impl> set_geometry;
|
||||
phoenix::function<apply_feature_callback> on_feature;
|
||||
// error handler
|
||||
boost::phoenix::function<ErrorHandler> const error_handler;
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_FEATURE_COLLECTION_GRAMMAR_HPP
|
|
@ -1,122 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/json/error_handler.hpp>
|
||||
#include <mapnik/json/feature_collection_grammar.hpp>
|
||||
|
||||
// spirit::qi
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename FeatureCallback, typename ErrorHandler>
|
||||
feature_collection_grammar<Iterator,FeatureType, FeatureCallback,ErrorHandler>::feature_collection_grammar(mapnik::transcoder const& tr)
|
||||
: feature_collection_grammar::base_type(start,"start"),
|
||||
feature_g(tr)
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::eps_type eps;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_a_type _a;
|
||||
qi::_r1_type _r1;
|
||||
qi::_r2_type _r2;
|
||||
qi::_r3_type _r3;
|
||||
using phoenix::construct;
|
||||
using phoenix::new_;
|
||||
using phoenix::val;
|
||||
using qi::on_error;
|
||||
using qi::fail;
|
||||
start = feature_collection(_r1, _r2, _r3)
|
||||
;
|
||||
|
||||
feature_collection = lit('{') > (type | features(_r1, _r2, _r3) | feature_g.json_.key_value) % lit(',') > lit('}')
|
||||
;
|
||||
|
||||
type = lit("\"type\"") > lit(':') > lit("\"FeatureCollection\"")
|
||||
;
|
||||
|
||||
features = lit("\"features\"")
|
||||
> lit(':') > lit('[') >
|
||||
( lit(']') | ((feature(_r1, _r2, _r3) [_r2 +=1] % lit(',')) > lit(']')))
|
||||
;
|
||||
|
||||
feature = eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(_r1, _r2))]
|
||||
> feature_g(*_a)[on_feature(_r3,_a)]
|
||||
;
|
||||
|
||||
start.name("start");
|
||||
feature_collection.name("FeatureCollection");
|
||||
type.name("type");
|
||||
features.name("features");
|
||||
feature.name("feature");
|
||||
feature_g.name("feature-grammar");
|
||||
on_error<fail>(feature_collection, error_handler(_1, _2, _3, _4));
|
||||
}
|
||||
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename FeatureCallback, typename ErrorHandler>
|
||||
feature_grammar_callback<Iterator,FeatureType, FeatureCallback,ErrorHandler>::feature_grammar_callback(mapnik::transcoder const& tr)
|
||||
: feature_grammar_callback::base_type(start,"start"),
|
||||
feature_g(tr)
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::eps_type eps;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_a_type _a;
|
||||
qi::_r1_type _r1;
|
||||
qi::_r2_type _r2;
|
||||
qi::_r3_type _r3;
|
||||
using phoenix::construct;
|
||||
using phoenix::new_;
|
||||
using phoenix::val;
|
||||
using qi::on_error;
|
||||
using qi::fail;
|
||||
start = feature_from_geometry(_r1, _r2, _r3) | feature(_r1, _r2, _r3)
|
||||
;
|
||||
|
||||
feature = eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(_r1, _r2))]
|
||||
>> feature_g(*_a)[on_feature(_r3,_a)]
|
||||
;
|
||||
|
||||
feature_from_geometry =
|
||||
eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(_r1, _r2))]
|
||||
>> geometry_g[set_geometry(*_a, _1)] [on_feature(_r3, _a)]
|
||||
;
|
||||
|
||||
start.name("start");
|
||||
feature.name("feature");
|
||||
feature_from_geometry.name("feature-from-geometry");
|
||||
feature_g.name("feature-grammar");
|
||||
geometry_g.name("geometry-grammar");
|
||||
on_error<fail>(feature, error_handler(_1, _2, _3, _4));
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,91 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_FEATURE_GRAMMAR_HPP
|
||||
#define MAPNIK_FEATURE_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
#include <mapnik/json/attribute_value_visitor.hpp>
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix.hpp>
|
||||
#include <boost/spirit/include/support_line_pos_iterator.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
namespace phoenix = boost::phoenix;
|
||||
namespace fusion = boost::fusion;
|
||||
|
||||
struct put_property
|
||||
{
|
||||
using result_type = void;
|
||||
explicit put_property(mapnik::transcoder const& tr)
|
||||
: tr_(tr) {}
|
||||
template <typename T0,typename T1, typename T2>
|
||||
result_type operator() (T0 & feature, T1 const& key, T2 && val) const
|
||||
{
|
||||
feature.put_new(key, mapnik::util::apply_visitor(attribute_value_visitor(tr_),val));
|
||||
}
|
||||
mapnik::transcoder const& tr_;
|
||||
};
|
||||
|
||||
struct set_geometry_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename T0, typename T1>
|
||||
result_type operator() (T0 & feature, T1 && geom) const
|
||||
{
|
||||
return feature.set_geometry(std::move(geom));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename ErrorHandler = error_handler<Iterator>>
|
||||
struct feature_grammar : qi::grammar<Iterator, void(FeatureType&), space_type>
|
||||
{
|
||||
explicit feature_grammar(mapnik::transcoder const& tr);
|
||||
// generic JSON
|
||||
generic_json<Iterator> json_;
|
||||
// geoJSON
|
||||
qi::rule<Iterator, void(FeatureType&),space_type> start;
|
||||
qi::rule<Iterator, qi::locals<bool>, void(FeatureType&), space_type> feature;
|
||||
qi::rule<Iterator, void(FeatureType&, bool&), space_type> feature_part;
|
||||
qi::rule<Iterator, space_type> feature_type;
|
||||
qi::rule<Iterator,void(FeatureType &),space_type> properties;
|
||||
qi::rule<Iterator,qi::locals<std::string>, void(FeatureType &),space_type> attributes;
|
||||
// functions
|
||||
phoenix::function<put_property> put_property_;
|
||||
phoenix::function<set_geometry_impl> set_geometry;
|
||||
// error handler
|
||||
boost::phoenix::function<ErrorHandler> const error_handler;
|
||||
// geometry
|
||||
geometry_grammar<Iterator> geometry_grammar_;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_FEATURE_GRAMMAR_HPP
|
|
@ -1,87 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/json/feature_grammar.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
template <typename Iterator, typename FeatureType, typename ErrorHandler>
|
||||
feature_grammar<Iterator,FeatureType,ErrorHandler>::feature_grammar(mapnik::transcoder const& tr)
|
||||
: feature_grammar::base_type(start,"feature"),
|
||||
json_(),
|
||||
put_property_(put_property(tr))
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::long_long_type long_long;
|
||||
qi::double_type double_;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_a_type _a;
|
||||
qi::_r1_type _r1;
|
||||
qi::_r2_type _r2;
|
||||
qi::eps_type eps;
|
||||
qi::char_type char_;
|
||||
using qi::fail;
|
||||
using qi::on_error;
|
||||
using phoenix::new_;
|
||||
using phoenix::construct;
|
||||
|
||||
// geojson types
|
||||
feature_type = lit("\"type\"") > lit(':') > lit("\"Feature\"")
|
||||
;
|
||||
|
||||
start = feature(_r1);
|
||||
|
||||
feature = eps[_a = false] > lit('{') >
|
||||
feature_part(_r1, _a) % lit(',')
|
||||
> eps(_a) > lit('}')
|
||||
;
|
||||
|
||||
feature_part = feature_type[_r2 = true]
|
||||
|
|
||||
(lit("\"geometry\"") > lit(':') > geometry_grammar_[set_geometry(_r1, _1)])
|
||||
|
|
||||
properties(_r1)
|
||||
|
|
||||
json_.key_value
|
||||
;
|
||||
|
||||
properties = lit("\"properties\"")
|
||||
> lit(':') > ((lit('{') > -attributes(_r1) > lit('}')) | lit("null"))
|
||||
;
|
||||
|
||||
attributes = (json_.string_ [_a = _1] > lit(':') > json_.value [put_property_(_r1,_a,_1)]) % lit(',')
|
||||
;
|
||||
|
||||
feature.name("Feature");
|
||||
feature_type.name("type");
|
||||
properties.name("properties");
|
||||
attributes.name("Attributes");
|
||||
on_error<fail>(feature, error_handler(_1, _2, _3, _4));
|
||||
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,65 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_GRAMMAR_HPP
|
||||
#define MAPNIK_GEOMETRY_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp> // for geometry_type
|
||||
#include <mapnik/make_unique.hpp>
|
||||
#include <mapnik/json/generic_json.hpp>
|
||||
#include <mapnik/json/positions_grammar.hpp>
|
||||
#include <mapnik/json/geometry_util.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
|
||||
struct geometry_grammar :
|
||||
qi::grammar<Iterator, mapnik::geometry::geometry<double>() ,space_type>
|
||||
{
|
||||
geometry_grammar();
|
||||
qi::rule<Iterator, mapnik::geometry::geometry<double>(), space_type> start;
|
||||
qi::rule<Iterator, qi::locals<int, mapnik::json::coordinates>, mapnik::geometry::geometry<double>(), space_type> geometry;
|
||||
qi::rule<Iterator, void(int&, mapnik::json::coordinates&, mapnik::geometry::geometry<double>&), space_type> geometry_part;
|
||||
qi::rule<Iterator, mapnik::geometry::geometry_collection<double>(), space_type> geometry_collection;
|
||||
qi::symbols<char, int> geometry_type_dispatch;
|
||||
positions_grammar<Iterator> coordinates;
|
||||
boost::phoenix::function<create_geometry_impl> create_geometry;
|
||||
// generic JSON
|
||||
generic_json<Iterator> json_;
|
||||
// error handler
|
||||
ErrorHandler error_handler;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_GRAMMAR_HPP
|
|
@ -1,94 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/json/error_handler.hpp>
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/phoenix_stl.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
template <typename Iterator, typename ErrorHandler >
|
||||
geometry_grammar<Iterator, ErrorHandler>::geometry_grammar()
|
||||
: geometry_grammar::base_type(start,"geometry"),
|
||||
coordinates(error_handler)
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::int_type int_;
|
||||
qi::double_type double_;
|
||||
qi::_val_type _val;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_a_type _a;
|
||||
qi::_b_type _b;
|
||||
qi::_r1_type _r1;
|
||||
qi::_r2_type _r2;
|
||||
qi::_r3_type _r3;
|
||||
qi::eps_type eps;
|
||||
using qi::fail;
|
||||
using qi::on_error;
|
||||
using phoenix::push_back;
|
||||
|
||||
start = geometry.alias() | lit("null");
|
||||
|
||||
geometry = lit('{')[_a = 0]
|
||||
> (geometry_part(_a, _b, _val) % lit(','))[create_geometry(_val, _a, _b)]
|
||||
> lit('}');
|
||||
|
||||
geometry_part = ((lit("\"type\"") > lit(':') > geometry_type_dispatch[_r1 = _1])
|
||||
|
|
||||
(lit("\"coordinates\"") > lit(':') > coordinates[_r2 = _1])
|
||||
|
|
||||
(lit("\"geometries\"") > lit(':') > lit('[') > geometry_collection[_r3 = _1] > lit(']'))
|
||||
|
|
||||
json_.key_value)
|
||||
;
|
||||
|
||||
geometry_collection = geometry[push_back(_val, _1)] % lit(',')
|
||||
;
|
||||
geometry_type_dispatch.add
|
||||
("\"Point\"",1)
|
||||
("\"LineString\"",2)
|
||||
("\"Polygon\"",3)
|
||||
("\"MultiPoint\"",4)
|
||||
("\"MultiLineString\"",5)
|
||||
("\"MultiPolygon\"",6)
|
||||
("\"GeometryCollection\"",7)
|
||||
;
|
||||
|
||||
// give some rules names
|
||||
geometry.name("Geometry");
|
||||
geometry_collection.name("GeometryCollection");
|
||||
geometry_type_dispatch.name("type: (Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon|GeometryCollection)");
|
||||
coordinates.name("coordinates");
|
||||
// error handler
|
||||
auto error_handler_function = boost::phoenix::function<ErrorHandler>(error_handler);
|
||||
on_error<fail>(start, error_handler_function(_1, _2, _3, _4));
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,244 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_JSON_GEOMETRY_UTIL_HPP
|
||||
#define MAPNIK_JSON_GEOMETRY_UTIL_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/correct.hpp>
|
||||
#include <mapnik/json/positions.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
// geometries
|
||||
template <typename Geometry>
|
||||
struct create_point
|
||||
{
|
||||
explicit create_point(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator() (position const& pos) const
|
||||
{
|
||||
mapnik::geometry::point<double> point(pos.x, pos.y);
|
||||
geom_ = std::move(point);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct create_linestring
|
||||
{
|
||||
explicit create_linestring(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator() (positions const& ring) const
|
||||
{
|
||||
std::size_t size = ring.size();
|
||||
if (size > 1)
|
||||
{
|
||||
mapnik::geometry::line_string<double> line;
|
||||
line.reserve(size);
|
||||
for (auto && pt : ring)
|
||||
{
|
||||
line.emplace_back(std::move(pt));
|
||||
}
|
||||
geom_ = std::move(line);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct create_polygon
|
||||
{
|
||||
explicit create_polygon(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator() (std::vector<positions> const& rings) const
|
||||
{
|
||||
mapnik::geometry::polygon<double> poly;
|
||||
std::size_t num_rings = rings.size();
|
||||
if (num_rings > 1)
|
||||
{
|
||||
poly.interior_rings.reserve(num_rings - 1);
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0; i < num_rings; ++i)
|
||||
{
|
||||
std::size_t size = rings[i].size();
|
||||
mapnik::geometry::linear_ring<double> ring;
|
||||
ring.reserve(size);
|
||||
for ( auto && pt : rings[i])
|
||||
{
|
||||
ring.emplace_back(std::move(pt));
|
||||
}
|
||||
if (i == 0) poly.set_exterior_ring(std::move(ring));
|
||||
else poly.add_hole(std::move(ring));
|
||||
}
|
||||
geom_ = std::move(poly);
|
||||
mapnik::geometry::correct(geom_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
// multi-geometries
|
||||
template <typename Geometry>
|
||||
struct create_multipoint
|
||||
{
|
||||
explicit create_multipoint(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator() (positions const& points) const
|
||||
{
|
||||
mapnik::geometry::multi_point<double> multi_point;
|
||||
multi_point.reserve(points.size());
|
||||
for (auto && pos : points)
|
||||
{
|
||||
multi_point.emplace_back(std::move(pos));
|
||||
}
|
||||
geom_ = std::move(multi_point);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct create_multilinestring
|
||||
{
|
||||
explicit create_multilinestring(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator() (std::vector<positions> const& rings) const
|
||||
{
|
||||
mapnik::geometry::multi_line_string<double> multi_line;
|
||||
multi_line.reserve(rings.size());
|
||||
|
||||
for (auto const& ring : rings)
|
||||
{
|
||||
mapnik::geometry::line_string<double> line;
|
||||
line.reserve(ring.size());
|
||||
for (auto && pt : ring)
|
||||
{
|
||||
line.emplace_back(std::move(pt));
|
||||
}
|
||||
multi_line.emplace_back(std::move(line));
|
||||
}
|
||||
geom_ = std::move(multi_line);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct create_multipolygon
|
||||
{
|
||||
explicit create_multipolygon(Geometry & geom)
|
||||
: geom_(geom) {}
|
||||
|
||||
void operator()(std::vector<std::vector<positions> > const& rings_array) const
|
||||
{
|
||||
mapnik::geometry::multi_polygon<double> multi_poly;
|
||||
multi_poly.reserve(rings_array.size());
|
||||
for (auto const& rings : rings_array)
|
||||
{
|
||||
mapnik::geometry::polygon<double> poly;
|
||||
std::size_t num_rings = rings.size();
|
||||
if ( num_rings > 1)
|
||||
poly.interior_rings.reserve(num_rings - 1);
|
||||
|
||||
for ( std::size_t i = 0; i < num_rings; ++i)
|
||||
{
|
||||
std::size_t size = rings[i].size();
|
||||
mapnik::geometry::linear_ring<double> ring;
|
||||
ring.reserve(size);
|
||||
for ( auto && pt : rings[i])
|
||||
{
|
||||
ring.emplace_back(std::move(pt));
|
||||
}
|
||||
if (i == 0) poly.set_exterior_ring(std::move(ring));
|
||||
else poly.add_hole(std::move(ring));
|
||||
}
|
||||
multi_poly.emplace_back(std::move(poly));
|
||||
}
|
||||
geom_ = std::move(multi_poly);
|
||||
mapnik::geometry::correct(geom_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T const&) const {} // no-op - shouldn't get here
|
||||
|
||||
Geometry & geom_;
|
||||
};
|
||||
|
||||
struct create_geometry_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename Geometry>
|
||||
void operator() (Geometry & geom, int type, mapnik::json::coordinates const& coords) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 1 ://Point
|
||||
util::apply_visitor(create_point<Geometry>(geom), coords);
|
||||
break;
|
||||
case 2 ://LineString
|
||||
util::apply_visitor(create_linestring<Geometry>(geom), coords);
|
||||
break;
|
||||
case 3 ://Polygon
|
||||
util::apply_visitor(create_polygon<Geometry>(geom), coords);
|
||||
break;
|
||||
case 4 ://MultiPoint
|
||||
util::apply_visitor(create_multipoint<Geometry>(geom), coords);
|
||||
break;
|
||||
case 5 ://MultiLineString
|
||||
util::apply_visitor(create_multilinestring<Geometry>(geom), coords);
|
||||
break;
|
||||
case 6 ://MultiPolygon
|
||||
util::apply_visitor(create_multipolygon<Geometry>(geom), coords);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_JSON_GEOMETRY_UTIL_HPP
|
|
@ -1,40 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_JSON_POSITIONS_HPP
|
||||
#define MAPNIK_JSON_POSITIONS_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
struct empty {};
|
||||
|
||||
using position = mapnik::geometry::point<double>;
|
||||
using positions = std::vector<position>;
|
||||
using coordinates = util::variant<empty, position, positions, std::vector<positions>, std::vector<std::vector<positions> > > ;
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_JSON_POSITIONS_HPP
|
|
@ -1,55 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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_JSON_POSITIONS_GRAMMAR_HPP
|
||||
#define MAPNIK_JSON_POSITIONS_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/json/positions.hpp>
|
||||
#include <mapnik/json/error_handler.hpp>
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
namespace standard = boost::spirit::standard;
|
||||
using space_type = standard::space_type;
|
||||
|
||||
template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
|
||||
struct positions_grammar :
|
||||
qi::grammar<Iterator,coordinates(),space_type>
|
||||
{
|
||||
positions_grammar(ErrorHandler & error_handler);
|
||||
qi::rule<Iterator, coordinates(),space_type> coords;
|
||||
qi::rule<Iterator, boost::optional<position>(), space_type> pos;
|
||||
qi::rule<Iterator, positions(), space_type> ring;
|
||||
qi::rule<Iterator, std::vector<positions>(), space_type> rings;
|
||||
qi::rule<Iterator, std::vector<std::vector<positions> >(), space_type> rings_array;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_JSON_POSITIONS_GRAMMAR_HPP
|
|
@ -1,97 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/json/positions_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/qi_omit.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
#include <boost/spirit/include/phoenix_stl.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
// stl
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
struct set_position_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename T0,typename T1>
|
||||
result_type operator() (T0 & coords, T1 const& pos) const
|
||||
{
|
||||
if (pos) coords = *pos;
|
||||
}
|
||||
};
|
||||
|
||||
struct push_position_impl
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename T0, typename T1>
|
||||
result_type operator() (T0 & coords, T1 const& pos) const
|
||||
{
|
||||
if (pos) coords.emplace_back(*pos);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename ErrorHandler>
|
||||
positions_grammar<Iterator, ErrorHandler>::positions_grammar(ErrorHandler & error_handler)
|
||||
: positions_grammar::base_type(coords,"coordinates")
|
||||
{
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
qi::_val_type _val;
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::omit_type omit;
|
||||
using qi::fail;
|
||||
using qi::on_error;
|
||||
|
||||
boost::phoenix::function<set_position_impl> set_position;
|
||||
boost::phoenix::function<push_position_impl> push_position;
|
||||
|
||||
coords = rings_array[_val = _1] | rings [_val = _1] | ring[_val = _1] | pos[set_position(_val,_1)]
|
||||
;
|
||||
pos = lit('[') > -(double_ > lit(',') > double_) > omit[*(lit(',') > double_)] > lit(']')
|
||||
;
|
||||
ring = lit('[') >> pos[push_position(_val,_1)] % lit(',') > lit(']')
|
||||
;
|
||||
rings = lit('[') >> ring % lit(',') > lit(']')
|
||||
;
|
||||
rings_array = lit('[') >> rings % lit(',') > lit(']')
|
||||
;
|
||||
coords.name("Coordinates");
|
||||
pos.name("Position");
|
||||
ring.name("Ring");
|
||||
rings.name("Rings");
|
||||
rings_array.name("Rings array");
|
||||
|
||||
// error handler
|
||||
auto error_handler_function = boost::phoenix::function<ErrorHandler>(error_handler);
|
||||
on_error<fail>(coords, error_handler_function(_1, _2, _3, _4));
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,29 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/json/feature_collection_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
using iterator_type = char const*;
|
||||
template struct mapnik::json::feature_collection_grammar<iterator_type,mapnik::feature_impl, mapnik::json::default_feature_callback> ;
|
||||
template struct mapnik::json::feature_grammar_callback<iterator_type,mapnik::feature_impl, mapnik::json::default_feature_callback> ;
|
|
@ -1,28 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/json/feature_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
using iterator_type = char const*;
|
||||
template struct mapnik::json::feature_grammar<iterator_type,mapnik::feature_impl>;
|
|
@ -1,27 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/json/geometry_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
using iterator_type = char const*;
|
||||
template struct mapnik::json::geometry_grammar<iterator_type>;
|
|
@ -1,43 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2016 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#include <mapnik/json/geometry_parser.hpp>
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
|
||||
namespace mapnik { namespace json {
|
||||
|
||||
bool from_geojson(std::string const& json, mapnik::geometry::geometry<double> & geom)
|
||||
{
|
||||
using namespace boost::spirit;
|
||||
static const geometry_grammar<char const*> g;
|
||||
standard::space_type space;
|
||||
char const* start = json.c_str();
|
||||
char const* end = start + json.length();
|
||||
return qi::phrase_parse(start, end, g, space, geom);
|
||||
}
|
||||
|
||||
}}
|
|
@ -1,27 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/json/positions_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
using iterator_type = char const*;
|
||||
template struct mapnik::json::positions_grammar<iterator_type>;
|
Loading…
Reference in a new issue