From 1dcfca9d51b0cd7bc5b6521c3b893379279fb4a7 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 15 Sep 2014 17:33:54 -0700 Subject: [PATCH] Get closer to vector format --- geojson.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/geojson.c b/geojson.c index 631112e..e198b72 100644 --- a/geojson.c +++ b/geojson.c @@ -18,9 +18,12 @@ #define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */ #define GEOM_POLYGON 4 /* array of arrays of arrays of positions */ #define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */ - #define GEOM_TYPES 6 +#define MB_GEOM_POINT 1 +#define MB_GEOM_LINE 2 +#define MB_GEOM_POLYGON 3 + char *geometry_names[GEOM_TYPES] = { "Point", "MultiPoint", @@ -39,6 +42,15 @@ int geometry_within[GEOM_TYPES] = { GEOM_POLYGON, /* multipolygon */ }; +int mb_geometry[GEOM_TYPES] = { + MB_GEOM_POINT, + MB_GEOM_POINT, + MB_GEOM_LINE, + MB_GEOM_LINE, + MB_GEOM_POLYGON, + MB_GEOM_POLYGON, +}; + /* XXX */ #define META_STRING JSON_STRING #define META_INTEGER JSON_NUMBER @@ -55,6 +67,14 @@ void parse_geometry(int t, json_object *j) { printf("["); int i; for (i = 0; i < j->length; i++) { + if (within == GEOM_POINT) { + if (i == 0) { + printf(" moveto "); + } else { + printf(" lineto "); + } + } + parse_geometry(within, j->array[i]); } printf("]"); @@ -65,6 +85,10 @@ void parse_geometry(int t, json_object *j) { fprintf(stderr, "malformed point"); } } + + if (t == GEOM_POLYGON) { + printf(" closepath "); + } } void read_json(FILE *f) { @@ -152,6 +176,7 @@ void read_json(FILE *f) { } } + printf("%d: ", mb_geometry[t]); parse_geometry(t, coordinates); printf("\n"); }