From ff5b632cf5c2072a9aef89d82ca0923c5c7f06ee Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 15 Sep 2014 17:56:57 -0700 Subject: [PATCH] MultiPoints are all movetos, no linetos --- Makefile | 2 +- geojson.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 74a9aca..6a69ae9 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ jsoncat: jsoncat.o jsonpull.o cc -g -Wall -o $@ $^ geojson: geojson.o jsonpull.o - cc -g -Wall -o $@ $^ + cc -g -Wall -o $@ $^ -lm jsoncat.o jsonpull.o: jsonpull.h diff --git a/geojson.c b/geojson.c index e198b72..12ff604 100644 --- a/geojson.c +++ b/geojson.c @@ -56,6 +56,15 @@ int mb_geometry[GEOM_TYPES] = { #define META_INTEGER JSON_NUMBER #define META_BOOLEAN JSON_TRUE +// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames +void latlon2tile(double lat, double lon, int zoom, unsigned int *x, unsigned int *y) { + double lat_rad = lat * M_PI / 180; + unsigned long long n = 1LL << zoom; + + *x = n * ((lon + 180) / 360); + *y = n * (1 - (log(tan(lat_rad) + 1/cos(lat_rad)) / M_PI)) / 2; +} + void parse_geometry(int t, json_object *j) { if (j == NULL || j->type != JSON_ARRAY) { fprintf(stderr, "expected array for type %d\n", t); @@ -68,7 +77,7 @@ void parse_geometry(int t, json_object *j) { int i; for (i = 0; i < j->length; i++) { if (within == GEOM_POINT) { - if (i == 0) { + if (i == 0 || t == GEOM_MULTIPOINT) { printf(" moveto "); } else { printf(" lineto ");