mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-21 20:08:20 +00:00
Warn if the GeoJSON specifies a different projection
This commit is contained in:
parent
2578781a37
commit
a504840bd5
21
geojson.cpp
21
geojson.cpp
@ -90,7 +90,7 @@ long long parse_geometry(int t, json_object *j, long long *bbox, long long *fpos
|
||||
long long x, y;
|
||||
double lon = j->array[0]->number;
|
||||
double lat = j->array[1]->number;
|
||||
projection(lon, lat, 32, &x, &y);
|
||||
projection->project(lon, lat, 32, &x, &y);
|
||||
|
||||
if (j->length > 2) {
|
||||
static int warned = 0;
|
||||
@ -405,6 +405,21 @@ int serialize_geometry(json_object *geometry, json_object *properties, const cha
|
||||
return 1;
|
||||
}
|
||||
|
||||
void check_crs(json_object *j, const char *reading) {
|
||||
json_object *crs = json_hash_get(j, "crs");
|
||||
if (crs != NULL) {
|
||||
json_object *properties = json_hash_get(crs, "properties");
|
||||
if (properties != NULL) {
|
||||
json_object *name = json_hash_get(properties, "name");
|
||||
if (name->type == JSON_STRING) {
|
||||
if (strcmp(name->string, projection->alias) != 0) {
|
||||
fprintf(stderr, "%s: Warning: GeoJSON specified projection \"%s\", not \"%s\".\n", reading, name->string, projection->alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom) {
|
||||
long long found_hashes = 0;
|
||||
long long found_features = 0;
|
||||
@ -476,6 +491,10 @@ void parse_json(json_pull *jp, const char *reading, volatile long long *layer_se
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(type->string, "FeatureCollection") == 0) {
|
||||
check_crs(j, reading);
|
||||
}
|
||||
|
||||
if (strcmp(type->string, "Feature") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
18
main.cpp
18
main.cpp
@ -58,7 +58,6 @@ int geometry_scale = 0;
|
||||
|
||||
int prevent[256];
|
||||
int additional[256];
|
||||
void (*projection)(double ix, double iy, int zoom, long long *ox, long long *oy) = lonlat2tile;
|
||||
|
||||
struct source {
|
||||
std::string layer;
|
||||
@ -1706,17 +1705,14 @@ static bool has_name(struct option *long_options, int *pl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct projection {
|
||||
const char *name;
|
||||
void (*project)(double ix, double iy, int zoom, long long *ox, long long *oy);
|
||||
};
|
||||
|
||||
struct projection projections[] = {
|
||||
{"EPSG:4326", lonlat2tile},
|
||||
{"EPSG:3857", epsg3857totile},
|
||||
{"EPSG:4326", lonlat2tile, "urn:ogc:def:crs:OGC:1.3:CRS84"},
|
||||
{"EPSG:3857", epsg3857totile, "urn:ogc:def:crs:EPSG::3857"},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
struct projection *projection = &projections[0];
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef MTRACE
|
||||
mtrace();
|
||||
@ -1995,7 +1991,11 @@ int main(int argc, char **argv) {
|
||||
struct projection *p;
|
||||
for (p = projections; p->name != NULL; p++) {
|
||||
if (strcmp(p->name, optarg) == 0) {
|
||||
projection = p->project;
|
||||
projection = p;
|
||||
break;
|
||||
}
|
||||
if (strcmp(p->alias, optarg) == 0) {
|
||||
projection = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
2
main.hpp
2
main.hpp
@ -13,5 +13,3 @@ extern int quiet;
|
||||
|
||||
extern int CPUS;
|
||||
extern int TEMP_FILES;
|
||||
|
||||
extern void (*projection)(double ix, double iy, int zoom, long long *ox, long long *oy);
|
||||
|
@ -3,3 +3,11 @@ void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y);
|
||||
void tile2lonlat(long long x, long long y, int zoom, double *lon, double *lat);
|
||||
unsigned long long encode(unsigned int wx, unsigned int wy);
|
||||
void decode(unsigned long long index, unsigned *wx, unsigned *wy);
|
||||
|
||||
struct projection {
|
||||
const char *name;
|
||||
void (*project)(double ix, double iy, int zoom, long long *ox, long long *oy);
|
||||
const char *alias;
|
||||
};
|
||||
|
||||
extern struct projection *projection;
|
||||
|
Loading…
Reference in New Issue
Block a user