Add --reject-null-geometry and more GeoJSON geometry validation

This commit is contained in:
Erica Fischer
2023-11-21 10:21:47 -08:00
parent d359461e61
commit 3e0633323f
10 changed files with 66 additions and 1 deletions
+18
View File
@@ -103,6 +103,14 @@ void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fna
}
if (t == GEOM_POLYGON) {
if (out.size() < 3) {
fprintf(stderr, "%s:%d: polygon must contain at least three points: ", fname, line);
json_context(j);
fprintf(stderr, "%s:%d: polygon must contain at least three points: ", fname, line);
json_context(feature);
exit(EXIT_INCORRECT_GEOMETRY);
}
// Note that this is not using the correct meaning of closepath.
//
// We are using it here to close an entire Polygon, to distinguish
@@ -114,6 +122,16 @@ void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fna
out.push_back(draw(VT_CLOSEPATH, 0, 0));
}
if (t == GEOM_LINESTRING) {
if (out.size() < 2) {
fprintf(stderr, "%s:%d: linestring must contain at least two points: ", fname, line);
json_context(j);
fprintf(stderr, "%s:%d: linestring must contain at least two points: ", fname, line);
json_context(feature);
exit(EXIT_INCORRECT_GEOMETRY);
}
}
}
void stringify_value(json_object *value, int &type, std::string &stringified, const char *reading, int line, json_object *feature) {