From baf364dd53fbf45e05642489e77c54ae08a3ece0 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 22 Sep 2014 16:06:44 -0700 Subject: [PATCH] Write string pool to tile --- geojson.c | 37 ++++++------------------------------- tile.cc | 13 ++++++++++++- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/geojson.c b/geojson.c index f33993d0..83e81c4f 100644 --- a/geojson.c +++ b/geojson.c @@ -12,6 +12,7 @@ #include #include #include "jsonpull.h" +#include "tile.h" #define GEOM_POINT 0 /* array of positions */ #define GEOM_MULTIPOINT 1 /* array of arrays of positions */ @@ -21,19 +22,6 @@ #define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */ #define GEOM_TYPES 6 -#define VT_END 0 -#define VT_POINT 1 -#define VT_LINE 2 -#define VT_POLYGON 3 - -#define VT_MOVETO 1 -#define VT_LINETO 2 -#define VT_CLOSEPATH 7 - -#define VT_STRING 1 -#define VT_NUMBER 2 -#define VT_BOOLEAN 7 - char *geometry_names[GEOM_TYPES] = { "Point", "MultiPoint", @@ -146,19 +134,6 @@ int indexcmp(const void *v1, const void *v2) { } } -struct pool_val { - char *s; - int type; - int n; - - struct pool_val *next; -}; - -struct pool { - struct pool_val *vals; - int n; -}; - struct pool_val *pool(struct pool *p, char *s, int type) { struct pool_val **v = &(p->vals); @@ -315,9 +290,9 @@ void range_search(struct index *ix, long long n, unsigned long long start, unsig } void check_range(struct index *start, struct index *end, char *metabase, unsigned *file_bbox) { - struct pool keys, values; - keys.n = values.n = 0; - keys.vals = values.vals = NULL; + struct pool keys; + keys.n = 0; + keys.vals = NULL; struct index *i; printf("tile -----------------------------------------------\n"); @@ -334,7 +309,7 @@ void check_range(struct index *start, struct index *end, char *metabase, unsigne int t; deserialize_int(&meta, &t); struct pool_val *key = deserialize_string(&meta, &keys, VT_STRING); - struct pool_val *value = deserialize_string(&meta, &values, t); + struct pool_val *value = deserialize_string(&meta, &keys, t); printf("%s (%d) = %s (%d)\n", key->s, key->n, value->s, value->n); } @@ -366,8 +341,8 @@ void check_range(struct index *start, struct index *end, char *metabase, unsigne printf("\n"); } + write_tile("layer", &keys); pool_free(&keys); - pool_free(&values); } void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox) { diff --git a/tile.cc b/tile.cc index b0785281..ad61631d 100644 --- a/tile.cc +++ b/tile.cc @@ -4,6 +4,10 @@ #include #include "vector_tile.pb.h" +extern "C" { + #include "tile.h" +} + #define XMAX 4096 #define YMAX 4096 @@ -35,7 +39,7 @@ static inline int compress(std::string const& input, std::string& output) { return 0; } -void write_tile(char *name) { +void write_tile(char *name, struct pool *keys) { GOOGLE_PROTOBUF_VERIFY_VERSION; mapnik::vector::tile tile; @@ -45,6 +49,10 @@ void write_tile(char *name) { layer->set_version(1); layer->set_extent(XMAX); + struct pool_val *pv; + for (pv = keys->vals; pv != NULL; pv = pv->next) { + layer->add_keys(pv->s, strlen(pv->s)); + } @@ -53,7 +61,10 @@ void write_tile(char *name) { std::string compressed; tile.SerializeToString(&s); + std::cout << s; +#if 0 compress(s, compressed); std::cout << compressed; +#endif }