From c5e44cc7a660a145871a9b5c19897fdb04171d68 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 25 Nov 2016 17:16:13 +0100 Subject: [PATCH] add missing extract_bounding_boxes_x3.cpp back --- .../json}/extract_bounding_boxes_x3.cpp | 73 ++++++------------- 1 file changed, 21 insertions(+), 52 deletions(-) rename {utils/mapnik-index => src/json}/extract_bounding_boxes_x3.cpp (71%) diff --git a/utils/mapnik-index/extract_bounding_boxes_x3.cpp b/src/json/extract_bounding_boxes_x3.cpp similarity index 71% rename from utils/mapnik-index/extract_bounding_boxes_x3.cpp rename to src/json/extract_bounding_boxes_x3.cpp index da0827881..7ca64afc5 100644 --- a/utils/mapnik-index/extract_bounding_boxes_x3.cpp +++ b/src/json/extract_bounding_boxes_x3.cpp @@ -23,9 +23,10 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include namespace mapnik { namespace json { @@ -93,9 +94,9 @@ auto on_feature_callback = [] (auto const& ctx) namespace { auto const& geojson_value = geojson_grammar();} // import unicode string rule -//namespace { auto const& geojson_string = unicode_string_grammar(); } +namespace { auto const& geojson_string = unicode_string_grammar(); } // import positions rule -//namespace { auto const& positions_rule = positions_grammar(); } +namespace { auto const& positions_rule = positions_grammar(); } // extract bounding box from GeoJSON Feature @@ -134,11 +135,13 @@ auto extract_bounding_box = [](auto const& ctx) _val(ctx) = std::move(bbox); }; -auto const coordinates_rule = x3::rule > {} - = lit("\"coordinates\"") >> lit(':') >> positions_rule[extract_bounding_box]; +x3::rule > const coordinates_rule = "Coordinates"; +x3::rule,mapnik::box2d>> const bounding_box = "Bounding Box"; +x3::rule const feature_collection = "Feature Collection"; -auto const bounding_box = x3::rule,mapnik::box2d>> {} - = raw[lit('{')[open_bracket] >> *(eps[check_brackets] >> +auto const coordinates_rule_def = lit("\"coordinates\"") >> lit(':') >> positions_rule[extract_bounding_box]; + +auto const bounding_box_def = raw[lit('{')[open_bracket] >> *(eps[check_brackets] >> (lit("\"FeatureCollection\"") > eps(false) | lit('{')[open_bracket] @@ -161,45 +164,13 @@ auto const features = lit("\"features\"") auto const type = lit("\"type\"") > lit(':') > lit("\"FeatureCollection\""); -auto const feature_collection = x3::rule {} - = lit('{') > (( type | features | key_value_) % lit(',')) > lit('}'); - - -} - -namespace { -struct collect_features -{ - collect_features(std::vector & values) - : values_(values) {} - void operator() (mapnik::json::geojson_value && val) const - { - values_.push_back(std::move(val)); - } - std::vector & values_; -}; - -template -struct extract_positions -{ - extract_positions(Iterator start, Boxes & boxes) - : start_(start), - boxes_(boxes) {} - - template - void operator() (T const& val) const - { - auto const& r = std::get<0>(val); - mapnik::box2d const& bbox = std::get<1>(val); - auto offset = std::distance(start_, r.begin()); - auto size = std::distance(r.begin(), r.end()); - boxes_.emplace_back(std::make_pair(bbox,std::make_pair(offset, size))); - //boxes_.emplace_back(std::make_tuple(bbox,offset, size)); - } - Iterator start_; - Boxes & boxes_; -}; +auto const feature_collection_def = lit('{') > (( type | features | key_value_) % lit(',')) > lit('}'); +BOOST_SPIRIT_DEFINE ( + coordinates_rule, + bounding_box, + feature_collection + ); } template @@ -214,8 +185,8 @@ void extract_bounding_boxes(Iterator start, Iterator end, Boxes & boxes) auto keys = mapnik::json::get_keys(); std::size_t bracket_counter = 0; auto feature_collection_impl = x3::with(std::ref(bracket_counter)) - [x3::with(std::ref(keys)) - [x3::with(std::ref(callback)) + [x3::with(std::ref(callback)) + [x3::with(std::ref(keys)) [mapnik::json::grammar::feature_collection] ]]; @@ -225,9 +196,7 @@ void extract_bounding_boxes(Iterator start, Iterator end, Boxes & boxes) } } - -using box_type = mapnik::box2d; -using boxes_type = std::vector>>; using base_iterator_type = char const*; template void extract_bounding_boxes(base_iterator_type, base_iterator_type, boxes_type&); + }}