feature_collection_grammar : allow passing start_id at parse time - #2582

This commit is contained in:
artemp 2014-11-24 12:24:21 +01:00
parent 8567aa25e0
commit ee9481cb38
3 changed files with 15 additions and 12 deletions

View file

@ -42,18 +42,18 @@ using standard_wide::space_type;
template <typename Iterator, typename FeatureType>
struct feature_collection_grammar :
qi::grammar<Iterator, std::vector<feature_ptr>(context_ptr const&), space_type>
qi::grammar<Iterator, std::vector<feature_ptr>(context_ptr const&, std::size_t& ), space_type>
{
feature_collection_grammar(mapnik::transcoder const& tr);
feature_grammar<Iterator,FeatureType> feature_g;
geometry_grammar<Iterator> geometry_g;
phoenix::function<extract_geometry> extract_geometry_;
qi::rule<Iterator, std::vector<feature_ptr>(context_ptr const&), space_type> start; // START
qi::rule<Iterator, std::vector<feature_ptr>(context_ptr const&), space_type> feature_collection;
qi::rule<Iterator, std::vector<feature_ptr>(context_ptr const&, std::size_t&), space_type> start; // START
qi::rule<Iterator, std::vector<feature_ptr>(context_ptr const&, std::size_t&), space_type> feature_collection;
qi::rule<Iterator, space_type> type;
qi::rule<Iterator, qi::locals<std::size_t>, std::vector<feature_ptr>(context_ptr const&), space_type> features;
qi::rule<Iterator, std::vector<feature_ptr>(context_ptr const&, std::size_t&), space_type> features;
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::vector<feature_ptr>&, std::size_t), space_type> feature;
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::vector<feature_ptr>&), space_type> feature_from_geometry;
qi::rule<Iterator, qi::locals<feature_ptr,int>, void(context_ptr const& ctx, std::size_t, std::vector<feature_ptr>&), space_type> feature_from_geometry;
};
}}

View file

@ -51,19 +51,19 @@ feature_collection_grammar<Iterator,FeatureType>::feature_collection_grammar(map
using phoenix::new_;
using phoenix::val;
start = feature_collection(_r1) | feature_from_geometry(_r1, _val) | feature(_r1, _val, 1)
start = feature_collection(_r1, _r2) | feature_from_geometry(_r1, _r2, _val) | feature(_r1,_val, _r2)
;
feature_collection = lit('{') >> (type | features(_r1) | feature_g.json_.key_value) % lit(',') >> lit('}')
feature_collection = lit('{') >> (type | features(_r1, _r2) | feature_g.json_.key_value) % lit(',') >> lit('}')
;
type = lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"")
;
features = lit("\"features\"")[_a = 1]
features = lit("\"features\"")
>> lit(':')
>> lit('[')
>> -(feature(_r1, _val, _a) [_a +=1] % lit(','))
>> -(feature(_r1, _val, _r2) [_r2 +=1] % lit(','))
>> lit(']')
;
@ -72,8 +72,8 @@ feature_collection_grammar<Iterator,FeatureType>::feature_collection_grammar(map
;
feature_from_geometry =
eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(_r1, 1))]
>> geometry_g(extract_geometry_(*_a)) [push_back(_r2, _a)]
eps[_a = phoenix::construct<mapnik::feature_ptr>(new_<mapnik::feature_impl>(_r1, _r2))]
>> geometry_g(extract_geometry_(*_a)) [push_back(_r3, _a)]
;
start.name("start");

View file

@ -147,7 +147,10 @@ void geojson_datasource::parse_geojson(T const& buffer)
{
boost::spirit::standard_wide::space_type space;
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
bool result = boost::spirit::qi::phrase_parse(buffer.begin(), buffer.end(), (fc_grammar)(boost::phoenix::ref(ctx)), space, features_);
std::size_t start_id = 1;
bool result = boost::spirit::qi::phrase_parse(buffer.begin(), buffer.end(), (fc_grammar)
(boost::phoenix::ref(ctx),boost::phoenix::ref(start_id)),
space, features_);
if (!result)
{
if (!inline_string_.empty()) throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file from in-memory string");