mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-02 01:08:14 +00:00
Start toward actually writing out tiles
This commit is contained in:
parent
41981ec8e9
commit
b8e7d3edf8
4
Makefile
4
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 $<
|
||||
|
59
tile.cc
Normal file
59
tile.cc
Normal file
@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user