From 64312a8dc145e6544c4233024677c14bccb161be Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 27 Mar 2015 10:32:52 +0100 Subject: [PATCH] geojson bounding box grammar - don't require `"type": "Feature"` to appear in particular order --- .../extract_bounding_box_grammar_impl.hpp | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp index 49ac87cf8..55eb5a75e 100644 --- a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp +++ b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp @@ -62,6 +62,7 @@ extract_bounding_box_grammar::extract_bounding_box_gramm start = features(_r1) ; + features = iter_pos[_a = _1] >> -(lit('{') >> -lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"") >> *(lit(',') >> (json.key_value - lit("\"features\""))) @@ -69,45 +70,58 @@ extract_bounding_box_grammar::extract_bounding_box_gramm >> lit(':')) >> lit('[') >> (feature(_r1,_a) % lit(',')) >> lit(']') ; - feature = raw[lit('{')[_a = 1] >> lit("\"type\"") >> lit(':') >> lit("\"Feature\"") - >> *(eps(_a > 0) >> (lit('{')[_a += 1] - | - lit('}')[_a -=1] - | - coords[_b = _1] - | - char_))][push_box(_r1, _r2, _b, _1)] + + feature = raw[lit('{')[_a = 1] + >> *(eps(_a > 0) >> (lit('{')[_a += 1] + | + lit('}')[_a -=1] + | + coords[_b = _1] + | + 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] + + 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(']') ; // generic json types json.value = json.object | json.array | json.string_ | json.number ; + json.pairs = json.key_value % lit(',') ; + json.key_value = (json.string_ >> lit(':') >> json.value) ; + json.object = lit('{') >> *json.pairs >> lit('}') ; + json.array = lit('[') >> json.value >> *(lit(',') >> json.value) >> lit(']') ; + json.number = json.strict_double | json.int__ | lit("true") | lit("false") | lit("null") ; + coords.name("Coordinates"); pos.name("Position"); ring.name("Ring");