extraxt_bounding_box_grammar - add generic json support to deal with arbitary key:value's in GeoJSON

This commit is contained in:
artemp 2015-01-20 12:05:35 +01:00
parent 9ba25cefe4
commit 5a7a285216
2 changed files with 37 additions and 3 deletions

View file

@ -24,9 +24,9 @@
#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 <iostream>
// boost
#pragma GCC diagnostic push
@ -95,7 +95,8 @@ struct extract_bounding_box_grammar :
qi::rule<Iterator, void(box2d<double>&), space_type> ring;
qi::rule<Iterator, void(box2d<double>&), space_type> rings;
qi::rule<Iterator, void(box2d<double>&), space_type> rings_array;
// generic JSON support
json::generic_json<Iterator> json;
// phoenix functions
boost::phoenix::function<push_box_impl> push_box;
boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;

View file

@ -48,6 +48,7 @@ extract_bounding_box_grammar<Iterator, ErrorHandler>::extract_bounding_box_gramm
qi::_2_type _2;
qi::_3_type _3;
qi::_4_type _4;
qi::no_skip_type no_skip;
qi::omit_type omit;
qi::_r1_type _r1;
qi::_r2_type _r2;
@ -60,11 +61,11 @@ extract_bounding_box_grammar<Iterator, ErrorHandler>::extract_bounding_box_gramm
using qi::fail;
using qi::on_error;
start = features(_r1)
;
features = iter_pos[_a = _1] >> -(lit('{') >> -lit("\"type\"")
>> lit(':') >> lit("\"FeatureCollection\"")
>> *(lit(',') >> (json.key_value - lit("\"features\"")))
>> lit(',') >> lit("\"features\"")
>> lit(':'))
>> lit('[') >> (feature(_r1,_a) % lit(',')) >> lit(']')
@ -89,6 +90,38 @@ extract_bounding_box_grammar<Iterator, ErrorHandler>::extract_bounding_box_gramm
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")
;
json.unesc_char.add
("\\\"", '\"') // quotation mark
("\\\\", '\\') // reverse solidus
("\\/", '/') // solidus
("\\b", '\b') // backspace
("\\f", '\f') // formfeed
("\\n", '\n') // newline
("\\r", '\r') // carrige return
("\\t", '\t') // tab
;
json.string_ %= lit('"') >> no_skip[*(json.unesc_char | "\\u" >> json.hex4 | (char_ - lit('"')))] >> lit('"')
;
coords.name("Coordinates");
pos.name("Position");
ring.name("Ring");