port GeoJSON parser/generator logic from master

This commit is contained in:
artemp 2017-03-22 14:40:07 +00:00
parent c2fd522d0f
commit a1084e0c09
2 changed files with 37 additions and 24 deletions

View file

@ -56,26 +56,24 @@ geometry_generator_grammar<OutputIterator, Geometry>::geometry_generator_grammar
; ;
geometry_dispatch = eps[_a = geometry_type(_val)] << geometry_dispatch = eps[_a = geometry_type(_val)] <<
(&uint_(geometry::geometry_types::Point)[_1 = _a] (&uint_(geometry::geometry_types::Point)[_1 = _a] << point)
<< (point | lit("null")))
| |
(&uint_(geometry::geometry_types::LineString)[_1 = _a] (&uint_(geometry::geometry_types::LineString)[_1 = _a]
<< (linestring | lit("null"))) << (linestring | "{\"type\":\"LineString\",\"coordinates\":[]}"))
| |
(&uint_(geometry::geometry_types::Polygon)[_1 = _a] (&uint_(geometry::geometry_types::Polygon)[_1 = _a]
<< (polygon | lit("null"))) << (polygon | "{\"type\":\"Polygon\",\"coordinates\":[[]]}"))
| |
(&uint_(geometry::geometry_types::MultiPoint)[_1 = _a] (&uint_(geometry::geometry_types::MultiPoint)[_1 = _a]
<< (multi_point | lit("null"))) << (multi_point | "{\"type\":\"MultiPoint\",\"coordinates\":[]}"))
| |
(&uint_(geometry::geometry_types::MultiLineString)[_1 = _a] (&uint_(geometry::geometry_types::MultiLineString)[_1 = _a]
<< (multi_linestring | lit("null"))) << (multi_linestring | "{\"type\":\"MultiLineString\",\"coordinates\":[[]]}"))
| |
(&uint_(geometry::geometry_types::MultiPolygon)[_1 = _a] (&uint_(geometry::geometry_types::MultiPolygon)[_1 = _a]
<< (multi_polygon | lit("null"))) << (multi_polygon | "{\"type\":\"MultiPolygon\",\"coordinates\":[[[]]]}"))
| |
(&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a] (&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a] << geometry_collection)
<< (geometry_collection | lit("null")))
| |
lit("null") lit("null")
; ;
@ -96,7 +94,7 @@ geometry_generator_grammar<OutputIterator, Geometry>::geometry_generator_grammar
; ;
point_coord = lit('[') << coordinate << lit(',') << coordinate << lit(']') 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 polygon_coord = lit('[') << exterior_ring_coord << lit(']') << interior_ring_coord
; ;

View file

@ -43,7 +43,10 @@ struct create_point
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };
@ -55,21 +58,21 @@ struct create_linestring
void operator() (positions const& ring) const void operator() (positions const& ring) const
{ {
mapnik::geometry::line_string<double> line;
std::size_t size = ring.size(); std::size_t size = ring.size();
if (size > 1) line.reserve(size);
for (auto && pt : ring)
{ {
mapnik::geometry::line_string<double> line; line.emplace_back(std::move(pt));
line.reserve(size);
for (auto && pt : ring)
{
line.emplace_back(std::move(pt));
}
geom_ = std::move(line);
} }
geom_ = std::move(line);
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };
@ -106,7 +109,10 @@ struct create_polygon
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };
@ -130,7 +136,10 @@ struct create_multipoint
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };
@ -160,7 +169,10 @@ struct create_multilinestring
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };
@ -201,7 +213,10 @@ struct create_multipolygon
} }
template <typename T> template <typename T>
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_; Geometry & geom_;
}; };