From a1084e0c0922bd5419629b460424b5a32328099f Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 22 Mar 2017 14:40:07 +0000 Subject: [PATCH] port GeoJSON parser/generator logic from master --- .../json/geometry_generator_grammar_impl.hpp | 18 ++++---- include/mapnik/json/geometry_util.hpp | 43 +++++++++++++------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/include/mapnik/json/geometry_generator_grammar_impl.hpp b/include/mapnik/json/geometry_generator_grammar_impl.hpp index 87a60db70..cd4c5d7ef 100644 --- a/include/mapnik/json/geometry_generator_grammar_impl.hpp +++ b/include/mapnik/json/geometry_generator_grammar_impl.hpp @@ -56,26 +56,24 @@ geometry_generator_grammar::geometry_generator_grammar ; geometry_dispatch = eps[_a = geometry_type(_val)] << - (&uint_(geometry::geometry_types::Point)[_1 = _a] - << (point | lit("null"))) + (&uint_(geometry::geometry_types::Point)[_1 = _a] << point) | (&uint_(geometry::geometry_types::LineString)[_1 = _a] - << (linestring | lit("null"))) + << (linestring | "{\"type\":\"LineString\",\"coordinates\":[]}")) | (&uint_(geometry::geometry_types::Polygon)[_1 = _a] - << (polygon | lit("null"))) + << (polygon | "{\"type\":\"Polygon\",\"coordinates\":[[]]}")) | (&uint_(geometry::geometry_types::MultiPoint)[_1 = _a] - << (multi_point | lit("null"))) + << (multi_point | "{\"type\":\"MultiPoint\",\"coordinates\":[]}")) | (&uint_(geometry::geometry_types::MultiLineString)[_1 = _a] - << (multi_linestring | lit("null"))) + << (multi_linestring | "{\"type\":\"MultiLineString\",\"coordinates\":[[]]}")) | (&uint_(geometry::geometry_types::MultiPolygon)[_1 = _a] - << (multi_polygon | lit("null"))) + << (multi_polygon | "{\"type\":\"MultiPolygon\",\"coordinates\":[[[]]]}")) | - (&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a] - << (geometry_collection | lit("null"))) + (&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a] << geometry_collection) | lit("null") ; @@ -96,7 +94,7 @@ geometry_generator_grammar::geometry_generator_grammar ; point_coord = lit('[') << coordinate << lit(',') << coordinate << lit(']') ; - linestring_coord = point_coord % lit(',') + linestring_coord = (point_coord % lit(',')) ; polygon_coord = lit('[') << exterior_ring_coord << lit(']') << interior_ring_coord ; diff --git a/include/mapnik/json/geometry_util.hpp b/include/mapnik/json/geometry_util.hpp index cf538ae73..ac5786f4a 100644 --- a/include/mapnik/json/geometry_util.hpp +++ b/include/mapnik/json/geometry_util.hpp @@ -43,7 +43,10 @@ struct create_point } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; }; @@ -55,21 +58,21 @@ struct create_linestring void operator() (positions const& ring) const { + mapnik::geometry::line_string line; std::size_t size = ring.size(); - if (size > 1) + line.reserve(size); + for (auto && pt : ring) { - mapnik::geometry::line_string line; - line.reserve(size); - for (auto && pt : ring) - { - line.emplace_back(std::move(pt)); - } - geom_ = std::move(line); + line.emplace_back(std::move(pt)); } + geom_ = std::move(line); } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; }; @@ -106,7 +109,10 @@ struct create_polygon } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; }; @@ -130,7 +136,10 @@ struct create_multipoint } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; }; @@ -160,7 +169,10 @@ struct create_multilinestring } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; }; @@ -201,7 +213,10 @@ struct create_multipolygon } template - void operator()(T const&) const {} // no-op - shouldn't get here + void operator()(T const&) const + { + throw std::runtime_error("Failed to parse geojson geometry"); + } Geometry & geom_; };