Merge pull request #34 from mapbox/warn-no-features

Warn if no Features have been seen after 50 JSON hashes are closed.
This commit is contained in:
Eric Fischer 2015-04-17 10:49:36 -07:00
commit 12fb2c969c

View File

@ -425,6 +425,8 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
json_pull *jp; json_pull *jp;
const char *reading; const char *reading;
FILE *fp; FILE *fp;
long long found_hashes = 0;
long long found_features = 0;
if (n >= argc) { if (n >= argc) {
reading = "standard input"; reading = "standard input";
@ -451,11 +453,22 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
break; 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"); json_object *type = json_hash_get(j, "type");
if (type == NULL || type->type != JSON_STRING || strcmp(type->string, "Feature") != 0) { if (type == NULL || type->type != JSON_STRING || strcmp(type->string, "Feature") != 0) {
continue; continue;
} }
found_features++;
json_object *geometry = json_hash_get(j, "geometry"); json_object *geometry = json_hash_get(j, "geometry");
if (geometry == NULL) { if (geometry == NULL) {
fprintf(stderr, "%s:%d: feature with no geometry\n", reading, jp->line); fprintf(stderr, "%s:%d: feature with no geometry\n", reading, jp->line);