GeoJSON - make geometry element stricter and throw on invalid input.

This commit is contained in:
artemp 2017-03-21 12:40:58 +00:00
parent 8a18ef93e0
commit d9063db0a0

View file

@ -44,7 +44,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_;
};
@ -55,11 +58,9 @@ struct create_linestring
: geom_(geom) {}
void operator() (ring const& points) const
{
std::size_t size = points.size();
if (size > 1)
{
mapnik::geometry::line_string<double> line;
std::size_t size = points.size();
line.reserve(size);
for (auto && pt : points)
{
@ -67,10 +68,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_;
};
@ -107,7 +110,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_;
};
@ -131,7 +137,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_;
};
@ -161,7 +170,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_;
};
@ -202,7 +214,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_;
};
@ -232,6 +247,7 @@ void create_geometry (Geometry & geom, int type, mapnik::json::positions const&
util::apply_visitor(create_multipolygon<Geometry>(geom), coords);
break;
default:
throw std::runtime_error("Failed to parse geojson geometry");
break;
}
}