From 167ec690a0386cd23ba84d8c4e625d8508fe966b Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 17 Apr 2015 10:48:03 -0700 Subject: [PATCH] Warn if no Features have been seen after 50 JSON hashes are closed. --- geojson.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/geojson.c b/geojson.c index 304f0cbd..58d6f843 100644 --- a/geojson.c +++ b/geojson.c @@ -425,6 +425,8 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max json_pull *jp; const char *reading; FILE *fp; + long long found_hashes = 0; + long long found_features = 0; if (n >= argc) { reading = "standard input"; @@ -451,11 +453,22 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max break; } + if (j->type == JSON_HASH) { + found_hashes++; + + if (found_hashes == 50 && found_features == 0) { + fprintf(stderr, "%s:%d: Not finding any GeoJSON features in input. Is your file just bare geometries?\n", reading, jp->line); + break; + } + } + json_object *type = json_hash_get(j, "type"); if (type == NULL || type->type != JSON_STRING || strcmp(type->string, "Feature") != 0) { continue; } + found_features++; + json_object *geometry = json_hash_get(j, "geometry"); if (geometry == NULL) { fprintf(stderr, "%s:%d: feature with no geometry\n", reading, jp->line);