JSON - optimise geometry grammar
This commit is contained in:
parent
ab7040d96a
commit
f3bed3a627
2 changed files with 10 additions and 14 deletions
|
@ -45,8 +45,8 @@ struct geometry_grammar :
|
|||
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::symbols<char, int> geometry_type_dispatch;
|
||||
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;
|
||||
// error handler
|
||||
|
|
|
@ -38,7 +38,6 @@ template <typename Iterator, typename ErrorHandler >
|
|||
geometry_grammar<Iterator, ErrorHandler>::geometry_grammar()
|
||||
: geometry_grammar::base_type(start,"geometry")
|
||||
{
|
||||
|
||||
qi::lit_type lit;
|
||||
qi::int_type int_;
|
||||
qi::double_type double_;
|
||||
|
@ -53,25 +52,21 @@ geometry_grammar<Iterator, ErrorHandler>::geometry_grammar()
|
|||
using qi::fail;
|
||||
using qi::on_error;
|
||||
using phoenix::push_back;
|
||||
start = geometry | geometry_collection;
|
||||
|
||||
start = geometry.alias(); // | geometry_collection;
|
||||
|
||||
geometry = (lit('{')[_a = 0 ]
|
||||
>> (-lit(',') >> lit("\"type\"") >> lit(':') >> geometry_type_dispatch[_a = _1]
|
||||
>> (-lit(',') >> (lit("\"type\"") >> lit(':') >> geometry_type_dispatch[_a = _1])
|
||||
^
|
||||
(-lit(',') >> lit("\"coordinates\"") >> lit(':') >> coordinates[_b = _1]))[create_geometry(_val,_a,_b)]
|
||||
(-lit(',') >> (lit("\"coordinates\"") > lit(':') > coordinates[_b = _1]))
|
||||
^
|
||||
(-lit(',') >> lit("\"geometries\"") >> lit(':') >> lit('[') >> geometry_collection[_val = _1] >> lit(']')))[create_geometry(_val,_a,_b)]
|
||||
>> lit('}'))
|
||||
| lit("null")
|
||||
;
|
||||
|
||||
geometry_collection = (lit('{')
|
||||
>> (-lit(',') >> lit("\"type\"") >> lit(':') >> lit("\"GeometryCollection\"")
|
||||
^
|
||||
-lit(',') >> lit("\"geometries\"") >> lit(':')
|
||||
>> lit('[') >> geometry[push_back(_val, _1)] % lit(',') >> lit(']'))
|
||||
>> lit('}'))
|
||||
| lit("null")
|
||||
geometry_collection = geometry[push_back(_val, _1)] % lit(',')
|
||||
;
|
||||
|
||||
geometry_type_dispatch.add
|
||||
("\"Point\"",1)
|
||||
("\"LineString\"",2)
|
||||
|
@ -79,12 +74,13 @@ geometry_grammar<Iterator, ErrorHandler>::geometry_grammar()
|
|||
("\"MultiPoint\"",4)
|
||||
("\"MultiLineString\"",5)
|
||||
("\"MultiPolygon\"",6)
|
||||
("\"GeometryCollection\"",7)
|
||||
;
|
||||
|
||||
// give some rules names
|
||||
geometry.name("Geometry");
|
||||
geometry_collection.name("GeometryCollection");
|
||||
geometry_type_dispatch.name("type");
|
||||
geometry_type_dispatch.name("type: (Point|LineString|Polygon|MultiPoint|MultiLineString|MultiPolygon|GeometryCollection)");
|
||||
coordinates.name("coordinates");
|
||||
// error handler
|
||||
on_error<fail>(start, error_handler(_1, _2, _3, _4));
|
||||
|
|
Loading…
Reference in a new issue