Skip to content

Commit

Permalink
+ allow empty arrays in "coordinates" property
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed Jun 12, 2012
1 parent bca033e commit 1f15012
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions include/mapnik/json/feature_grammar.hpp
Expand Up @@ -162,7 +162,7 @@ struct feature_grammar :
using qi::_pass; using qi::_pass;
using qi::eps; using qi::eps;
using qi::raw; using qi::raw;

using phoenix::new_; using phoenix::new_;
using phoenix::push_back; using phoenix::push_back;
using phoenix::construct; using phoenix::construct;
Expand Down Expand Up @@ -197,7 +197,7 @@ struct feature_grammar :
unesc_char.add unesc_char.add
("\\\"", '\"') // quotation mark ("\\\"", '\"') // quotation mark
("\\\\", '\\') // reverse solidus ("\\\\", '\\') // reverse solidus
("\\/", '/') // solidus ("\\/", '/') // solidus
("\\b", '\b') // backspace ("\\b", '\b') // backspace
("\\f", '\f') // formfeed ("\\f", '\f') // formfeed
("\\n", '\n') // newline ("\\n", '\n') // newline
Expand All @@ -207,7 +207,7 @@ struct feature_grammar :


string_ %= lit('"') >> *(unesc_char | "\\u" >> hex4 | (char_ - lit('"'))) >> lit('"') string_ %= lit('"') >> *(unesc_char | "\\u" >> hex4 | (char_ - lit('"'))) >> lit('"')
; ;

// geojson types // geojson types


feature_type = lit("\"type\"") feature_type = lit("\"type\"")
Expand Down Expand Up @@ -244,17 +244,17 @@ struct feature_grammar :
// ; // ;
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////


geometry = (lit('{')[_a = 0 ] geometry = (lit('{')[_a = 0 ]
>> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1] // <---- should be Nabialek trick! >> lit("\"type\"") >> lit(':') >> geometry_dispatch[_a = _1] // <---- should be Nabialek trick!
>> lit(',') >> lit(',')
>> (lit("\"coordinates\"") > lit(':') > coordinates(_r1,_a) >> (lit("\"coordinates\"") > lit(':') > coordinates(_r1,_a)
| |
lit("\"geometries\"") > lit(':') lit("\"geometries\"") > lit(':')
>> lit('[') >> geometry_collection(_r1) >> lit(']')) >> lit('[') >> geometry_collection(_r1) >> lit(']'))
>> lit('}')) >> lit('}'))
| lit("null") | lit("null")
; ;

geometry_dispatch.add geometry_dispatch.add
("\"Point\"",1) ("\"Point\"",1)
("\"LineString\"",2) ("\"LineString\"",2)
Expand All @@ -265,54 +265,53 @@ struct feature_grammar :
("\"GeometryCollection\"",7) ("\"GeometryCollection\"",7)
// //
; ;

coordinates = (eps(_r2 == 1) > point_coordinates(extract_geometry_(_r1))) coordinates = (eps(_r2 == 1) > point_coordinates(extract_geometry_(_r1)))
| (eps(_r2 == 2) > linestring_coordinates(extract_geometry_(_r1))) | (eps(_r2 == 2) > linestring_coordinates(extract_geometry_(_r1)))
| (eps(_r2 == 3) > polygon_coordinates(extract_geometry_(_r1))) | (eps(_r2 == 3) > polygon_coordinates(extract_geometry_(_r1)))
| (eps(_r2 == 4) > multipoint_coordinates(extract_geometry_(_r1))) | (eps(_r2 == 4) > multipoint_coordinates(extract_geometry_(_r1)))
| (eps(_r2 == 5) > multilinestring_coordinates(extract_geometry_(_r1))) | (eps(_r2 == 5) > multilinestring_coordinates(extract_geometry_(_r1)))
| (eps(_r2 == 6) > multipolygon_coordinates(extract_geometry_(_r1))) | (eps(_r2 == 6) > multipolygon_coordinates(extract_geometry_(_r1)))
; ;

point_coordinates = eps[ _a = new_<geometry_type>(Point) ] point_coordinates = eps[ _a = new_<geometry_type>(Point) ]
> ( point(SEG_MOVETO,_a) [push_back(_r1,_a)] | eps[cleanup_(_a)][_pass = false] ) > ( point(SEG_MOVETO,_a) [push_back(_r1,_a)] | eps[cleanup_(_a)][_pass = false] )
; ;


linestring_coordinates = eps[ _a = new_<geometry_type>(LineString)] linestring_coordinates = eps[ _a = new_<geometry_type>(LineString)]
> (points(_a) [push_back(_r1,_a)] > -(points(_a) [push_back(_r1,_a)]
| eps[cleanup_(_a)][_pass = false]) | eps[cleanup_(_a)][_pass = false])
; ;


polygon_coordinates = eps[ _a = new_<geometry_type>(Polygon) ] polygon_coordinates = eps[ _a = new_<geometry_type>(Polygon) ]
> ((lit('[') > ((lit('[')
> points(_a) % lit(',') > -(points(_a) % lit(','))
> lit(']')) [push_back(_r1,_a)] > lit(']')) [push_back(_r1,_a)]
| eps[cleanup_(_a)][_pass = false]) | eps[cleanup_(_a)][_pass = false])
; ;

multipoint_coordinates = lit('[') multipoint_coordinates = lit('[')
> (point_coordinates(_r1) % lit(',')) > -(point_coordinates(_r1) % lit(','))
> lit(']') > lit(']')
; ;

multilinestring_coordinates = lit('[') multilinestring_coordinates = lit('[')
> (linestring_coordinates(_r1) % lit(',')) > -(linestring_coordinates(_r1) % lit(','))
> lit(']') > lit(']')
; ;

multipolygon_coordinates = lit('[') multipolygon_coordinates = lit('[')
> (polygon_coordinates(_r1) % lit(',')) > -(polygon_coordinates(_r1) % lit(','))
> lit(']') > lit(']')
; ;


geometry_collection = *geometry(_r1) >> *(lit(',') >> geometry(_r1)) geometry_collection = *geometry(_r1) >> *(lit(',') >> geometry(_r1))
; ;

// point // point
point = (lit('[') > double_ > lit(',') > double_ > lit(']')) [push_vertex_(_r1,_r2,_1,_2)]; point = lit('[') > -((double_ > lit(',') > double_)[push_vertex_(_r1,_r2,_1,_2)]) > lit(']');
// points // points
points = lit('[')[_a = SEG_MOVETO] > point (_a,_r1) % lit(',') [_a = SEG_LINETO] > lit(']'); points = lit('[')[_a = SEG_MOVETO] > -(point (_a,_r1) % lit(',')[_a = SEG_LINETO]) > lit(']');

on_error<fail> on_error<fail>
( (
feature feature
Expand Down Expand Up @@ -362,7 +361,7 @@ struct feature_grammar :
qi::rule<Iterator,qi::locals<geometry_type*>, qi::rule<Iterator,qi::locals<geometry_type*>,
void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> linestring_coordinates; void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> linestring_coordinates;
qi::rule<Iterator,qi::locals<geometry_type*>, qi::rule<Iterator,qi::locals<geometry_type*>,
void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> polygon_coordinates; void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> polygon_coordinates;


qi::rule<Iterator,void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> multipoint_coordinates; qi::rule<Iterator,void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> multipoint_coordinates;
qi::rule<Iterator,void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> multilinestring_coordinates; qi::rule<Iterator,void(boost::ptr_vector<mapnik::geometry_type>& ),space_type> multilinestring_coordinates;
Expand Down

0 comments on commit 1f15012

Please sign in to comment.