diff --git a/Makefile b/Makefile index ff68b63d..43fab398 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PG= jsoncat: jsoncat.o jsonpull.o cc $(PG) -g -Wall -o $@ $^ -geojson: geojson.o jsonpull.o vector_tile.pb.o +geojson: geojson.o jsonpull.o vector_tile.pb.o tile.o cc $(PG) -O3 -g -Wall -o $@ $^ -lm -lz -lprotobuf-lite jsoncat.o jsonpull.o: jsonpull.h @@ -27,4 +27,4 @@ libjsonpull.a: jsonpull.o cc $(PG) -O3 -g -Wall -c $< %.o: %.cc - g++ -g -Wall -O3 -c $< + g++ $(PG) -O3 -g -Wall -c $< diff --git a/tile.cc b/tile.cc new file mode 100644 index 00000000..b0785281 --- /dev/null +++ b/tile.cc @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include "vector_tile.pb.h" + +#define XMAX 4096 +#define YMAX 4096 + +// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp +static inline int compress(std::string const& input, std::string& output) { + z_stream deflate_s; + deflate_s.zalloc = Z_NULL; + deflate_s.zfree = Z_NULL; + deflate_s.opaque = Z_NULL; + deflate_s.avail_in = 0; + deflate_s.next_in = Z_NULL; + deflateInit(&deflate_s, Z_DEFAULT_COMPRESSION); + deflate_s.next_in = (Bytef *)input.data(); + deflate_s.avail_in = input.size(); + size_t length = 0; + do { + size_t increase = input.size() / 2 + 1024; + output.resize(length + increase); + deflate_s.avail_out = increase; + deflate_s.next_out = (Bytef *)(output.data() + length); + int ret = deflate(&deflate_s, Z_FINISH); + if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) { + return -1; + } + length += (increase - deflate_s.avail_out); + } while (deflate_s.avail_out == 0); + deflateEnd(&deflate_s); + output.resize(length); + return 0; +} + +void write_tile(char *name) { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + mapnik::vector::tile tile; + mapnik::vector::tile_layer *layer = tile.add_layers(); + + layer->set_name("name"); + layer->set_version(1); + layer->set_extent(XMAX); + + + + + + std::string s; + std::string compressed; + + tile.SerializeToString(&s); + compress(s, compressed); + std::cout << compressed; +} +