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)] <<
(&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<OutputIterator, Geometry>::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
;

View file

@ -43,7 +43,10 @@ struct create_point
}
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_;
};
@ -54,11 +57,9 @@ struct create_linestring
: geom_(geom) {}
void operator() (positions const& ring) const
{
std::size_t size = ring.size();
if (size > 1)
{
mapnik::geometry::line_string<double> line;
std::size_t size = ring.size();
line.reserve(size);
for (auto && pt : ring)
{
@ -66,10 +67,12 @@ struct create_linestring
}
geom_ = std::move(line);
}
}
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_;
};
@ -106,7 +109,10 @@ struct create_polygon
}
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_;
};
@ -130,7 +136,10 @@ struct create_multipoint
}
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_;
};
@ -160,7 +169,10 @@ struct create_multilinestring
}
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_;
};
@ -201,7 +213,10 @@ struct create_multipolygon
}
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_;
};