Write string pool to tile

This commit is contained in:
Eric Fischer 2014-09-22 16:06:44 -07:00
parent b8e7d3edf8
commit baf364dd53
2 changed files with 18 additions and 32 deletions

View File

@ -12,6 +12,7 @@
#include <errno.h>
#include <limits.h>
#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) {

13
tile.cc
View File

@ -4,6 +4,10 @@
#include <zlib.h>
#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
}