mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Rename pb_ prefixes to mvt_
This commit is contained in:
@@ -35,16 +35,16 @@ C = $(shell find . '(' -name '*.c' -o -name '*.cc' ')')
|
|||||||
INCLUDES = -I/usr/local/include
|
INCLUDES = -I/usr/local/include
|
||||||
LIBS = -L/usr/local/lib
|
LIBS = -L/usr/local/lib
|
||||||
|
|
||||||
tippecanoe: geojson.o jsonpull.o vector_tile.pb.o tile.o clip.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o protobuf.o
|
tippecanoe: geojson.o jsonpull.o vector_tile.pb.o tile.o clip.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o mvt.o
|
||||||
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3 -lpthread
|
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3 -lpthread
|
||||||
|
|
||||||
tippecanoe-enumerate: enumerate.o
|
tippecanoe-enumerate: enumerate.o
|
||||||
$(CC) $(PG) $(LIBS) -O3 -g -Wall $(CFLAGS) -o $@ $^ $(LDFLAGS) -lsqlite3
|
$(CC) $(PG) $(LIBS) -O3 -g -Wall $(CFLAGS) -o $@ $^ $(LDFLAGS) -lsqlite3
|
||||||
|
|
||||||
tippecanoe-decode: decode.o vector_tile.pb.o projection.o protobuf.o
|
tippecanoe-decode: decode.o vector_tile.pb.o projection.o mvt.o
|
||||||
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3
|
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3
|
||||||
|
|
||||||
tile-join: tile-join.o vector_tile.pb.o projection.o pool.o mbtiles.o protobuf.o
|
tile-join: tile-join.o vector_tile.pb.o projection.o pool.o mbtiles.o mvt.o
|
||||||
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3
|
$(CXX) $(PG) $(LIBS) -O3 -g -Wall $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lprotobuf-lite -lsqlite3
|
||||||
|
|
||||||
libjsonpull.a: jsonpull.o
|
libjsonpull.a: jsonpull.o
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||||
#include <google/protobuf/io/coded_stream.h>
|
#include <google/protobuf/io/coded_stream.h>
|
||||||
#include "protobuf.hh"
|
#include "mvt.hh"
|
||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ struct draw {
|
|||||||
|
|
||||||
void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
||||||
int within = 0;
|
int within = 0;
|
||||||
pb_tile tile;
|
mvt_tile tile;
|
||||||
|
|
||||||
if (!pb_decode(message, tile)) {
|
if (!mvt_decode(message, tile)) {
|
||||||
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", z, x, y);
|
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", z, x, y);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
printf(", \"features\": [\n");
|
printf(", \"features\": [\n");
|
||||||
|
|
||||||
for (int l = 0; l < tile.layers.size(); l++) {
|
for (int l = 0; l < tile.layers.size(); l++) {
|
||||||
pb_layer &layer = tile.layers[l];
|
mvt_layer &layer = tile.layers[l];
|
||||||
int extent = layer.extent;
|
int extent = layer.extent;
|
||||||
|
|
||||||
if (describe) {
|
if (describe) {
|
||||||
@@ -81,7 +81,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int f = 0; f < layer.features.size(); f++) {
|
for (int f = 0; f < layer.features.size(); f++) {
|
||||||
pb_feature &feat = layer.features[f];
|
mvt_feature &feat = layer.features[f];
|
||||||
|
|
||||||
if (within) {
|
if (within) {
|
||||||
printf(",\n");
|
printf(",\n");
|
||||||
@@ -106,16 +106,16 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *key = layer.keys[feat.tags[t]].c_str();
|
const char *key = layer.keys[feat.tags[t]].c_str();
|
||||||
pb_value const &val = layer.values[feat.tags[t + 1]];
|
mvt_value const &val = layer.values[feat.tags[t + 1]];
|
||||||
|
|
||||||
if (val.type == pb_string) {
|
if (val.type == mvt_string) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": ");
|
printf(": ");
|
||||||
printq(val.string_value.c_str());
|
printq(val.string_value.c_str());
|
||||||
} else if (val.type == pb_int) {
|
} else if (val.type == mvt_int) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %lld", (long long) val.numeric_value.int_value);
|
printf(": %lld", (long long) val.numeric_value.int_value);
|
||||||
} else if (val.type == pb_double) {
|
} else if (val.type == mvt_double) {
|
||||||
printq(key);
|
printq(key);
|
||||||
double v = val.numeric_value.double_value;
|
double v = val.numeric_value.double_value;
|
||||||
if (v == (long long) v) {
|
if (v == (long long) v) {
|
||||||
@@ -123,7 +123,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
} else {
|
} else {
|
||||||
printf(": %g", v);
|
printf(": %g", v);
|
||||||
}
|
}
|
||||||
} else if (val.type == pb_float) {
|
} else if (val.type == mvt_float) {
|
||||||
printq(key);
|
printq(key);
|
||||||
double v = val.numeric_value.float_value;
|
double v = val.numeric_value.float_value;
|
||||||
if (v == (long long) v) {
|
if (v == (long long) v) {
|
||||||
@@ -131,13 +131,13 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
} else {
|
} else {
|
||||||
printf(": %g", v);
|
printf(": %g", v);
|
||||||
}
|
}
|
||||||
} else if (val.type == pb_sint) {
|
} else if (val.type == mvt_sint) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %lld", (long long) val.numeric_value.sint_value);
|
printf(": %lld", (long long) val.numeric_value.sint_value);
|
||||||
} else if (val.type == pb_uint) {
|
} else if (val.type == mvt_uint) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %lld", (long long) val.numeric_value.uint_value);
|
printf(": %lld", (long long) val.numeric_value.uint_value);
|
||||||
} else if (val.type == pb_bool) {
|
} else if (val.type == mvt_bool) {
|
||||||
printq(key);
|
printq(key);
|
||||||
printf(": %s", val.numeric_value.bool_value ? "true" : "false");
|
printf(": %s", val.numeric_value.bool_value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -4,7 +4,7 @@
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||||
#include <google/protobuf/io/coded_stream.h>
|
#include <google/protobuf/io/coded_stream.h>
|
||||||
#include "protobuf.hh"
|
#include "mvt.hh"
|
||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/src/vector_tile_compression.hpp
|
||||||
@@ -75,7 +75,7 @@ int dezig(unsigned n) {
|
|||||||
return (n >> 1) ^ (-(n & 1));
|
return (n >> 1) ^ (-(n & 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pb_decode(std::string &message, pb_tile &out) {
|
bool mvt_decode(std::string &message, mvt_tile &out) {
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||||
|
|
||||||
// https://github.com/mapbox/mapnik-vector-tile/blob/master/examples/c%2B%2B/tileinfo.cpp
|
// https://github.com/mapbox/mapnik-vector-tile/blob/master/examples/c%2B%2B/tileinfo.cpp
|
||||||
@@ -97,7 +97,7 @@ bool pb_decode(std::string &message, pb_tile &out) {
|
|||||||
|
|
||||||
for (size_t l = 0; l < tile.layers_size(); l++) {
|
for (size_t l = 0; l < tile.layers_size(); l++) {
|
||||||
mapnik::vector::tile_layer layer = tile.layers(l);
|
mapnik::vector::tile_layer layer = tile.layers(l);
|
||||||
pb_layer pbl;
|
mvt_layer pbl;
|
||||||
pbl.extent = layer.extent();
|
pbl.extent = layer.extent();
|
||||||
pbl.name = layer.name();
|
pbl.name = layer.name();
|
||||||
|
|
||||||
@@ -107,28 +107,28 @@ bool pb_decode(std::string &message, pb_tile &out) {
|
|||||||
|
|
||||||
for (size_t i = 0; i < layer.values_size(); i++) {
|
for (size_t i = 0; i < layer.values_size(); i++) {
|
||||||
mapnik::vector::tile_value const &val = layer.values(i);
|
mapnik::vector::tile_value const &val = layer.values(i);
|
||||||
pb_value pbv;
|
mvt_value pbv;
|
||||||
|
|
||||||
if (val.has_string_value()) {
|
if (val.has_string_value()) {
|
||||||
pbv.type = pb_string;
|
pbv.type = mvt_string;
|
||||||
pbv.string_value = val.string_value();
|
pbv.string_value = val.string_value();
|
||||||
} else if (val.has_float_value()) {
|
} else if (val.has_float_value()) {
|
||||||
pbv.type = pb_float;
|
pbv.type = mvt_float;
|
||||||
pbv.numeric_value.float_value = val.float_value();
|
pbv.numeric_value.float_value = val.float_value();
|
||||||
} else if (val.has_double_value()) {
|
} else if (val.has_double_value()) {
|
||||||
pbv.type = pb_double;
|
pbv.type = mvt_double;
|
||||||
pbv.numeric_value.double_value = val.double_value();
|
pbv.numeric_value.double_value = val.double_value();
|
||||||
} else if (val.has_int_value()) {
|
} else if (val.has_int_value()) {
|
||||||
pbv.type = pb_int;
|
pbv.type = mvt_int;
|
||||||
pbv.numeric_value.int_value = val.int_value();
|
pbv.numeric_value.int_value = val.int_value();
|
||||||
} else if (val.has_uint_value()) {
|
} else if (val.has_uint_value()) {
|
||||||
pbv.type = pb_uint;
|
pbv.type = mvt_uint;
|
||||||
pbv.numeric_value.uint_value = val.uint_value();
|
pbv.numeric_value.uint_value = val.uint_value();
|
||||||
} else if (val.has_sint_value()) {
|
} else if (val.has_sint_value()) {
|
||||||
pbv.type = pb_sint;
|
pbv.type = mvt_sint;
|
||||||
pbv.numeric_value.sint_value = val.sint_value();
|
pbv.numeric_value.sint_value = val.sint_value();
|
||||||
} else if (val.has_bool_value()) {
|
} else if (val.has_bool_value()) {
|
||||||
pbv.type = pb_bool;
|
pbv.type = mvt_bool;
|
||||||
pbv.numeric_value.bool_value = val.bool_value();
|
pbv.numeric_value.bool_value = val.bool_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ bool pb_decode(std::string &message, pb_tile &out) {
|
|||||||
|
|
||||||
for (size_t f = 0; f < layer.features_size(); f++) {
|
for (size_t f = 0; f < layer.features_size(); f++) {
|
||||||
mapnik::vector::tile_feature feat = layer.features(f);
|
mapnik::vector::tile_feature feat = layer.features(f);
|
||||||
pb_feature pbf;
|
mvt_feature pbf;
|
||||||
pbf.type = feat.type();
|
pbf.type = feat.type();
|
||||||
|
|
||||||
for (size_t i = 0; i < feat.tags_size(); i++) {
|
for (size_t i = 0; i < feat.tags_size(); i++) {
|
||||||
@@ -150,16 +150,16 @@ bool pb_decode(std::string &message, pb_tile &out) {
|
|||||||
uint32_t op = geom & 7;
|
uint32_t op = geom & 7;
|
||||||
uint32_t count = geom >> 3;
|
uint32_t count = geom >> 3;
|
||||||
|
|
||||||
if (op == pb_moveto || op == pb_lineto) {
|
if (op == mvt_moveto || op == mvt_lineto) {
|
||||||
for (size_t k = 0; k < count; k++) {
|
for (size_t k = 0; k < count; k++) {
|
||||||
px += dezig(feat.geometry(g + 1));
|
px += dezig(feat.geometry(g + 1));
|
||||||
py += dezig(feat.geometry(g + 2));
|
py += dezig(feat.geometry(g + 2));
|
||||||
g += 2;
|
g += 2;
|
||||||
|
|
||||||
pbf.geometry.push_back(pb_geometry(op, px, py));
|
pbf.geometry.push_back(mvt_geometry(op, px, py));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pbf.geometry.push_back(pb_geometry(op, 0, 0));
|
pbf.geometry.push_back(mvt_geometry(op, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ bool pb_decode(std::string &message, pb_tile &out) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string pb_encode(pb_tile &in) {
|
std::string mvt_encode(mvt_tile &in) {
|
||||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||||
|
|
||||||
mapnik::vector::tile tile;
|
mapnik::vector::tile tile;
|
||||||
@@ -189,21 +189,21 @@ std::string pb_encode(pb_tile &in) {
|
|||||||
}
|
}
|
||||||
for (size_t v = 0; v < in.layers[i].values.size(); v++) {
|
for (size_t v = 0; v < in.layers[i].values.size(); v++) {
|
||||||
mapnik::vector::tile_value *tv = layer->add_values();
|
mapnik::vector::tile_value *tv = layer->add_values();
|
||||||
pb_value &pbv = in.layers[i].values[v];
|
mvt_value &pbv = in.layers[i].values[v];
|
||||||
|
|
||||||
if (pbv.type == pb_string) {
|
if (pbv.type == mvt_string) {
|
||||||
tv->set_string_value(pbv.string_value);
|
tv->set_string_value(pbv.string_value);
|
||||||
} else if (pbv.type == pb_float) {
|
} else if (pbv.type == mvt_float) {
|
||||||
tv->set_float_value(pbv.numeric_value.float_value);
|
tv->set_float_value(pbv.numeric_value.float_value);
|
||||||
} else if (pbv.type == pb_double) {
|
} else if (pbv.type == mvt_double) {
|
||||||
tv->set_double_value(pbv.numeric_value.double_value);
|
tv->set_double_value(pbv.numeric_value.double_value);
|
||||||
} else if (pbv.type == pb_int) {
|
} else if (pbv.type == mvt_int) {
|
||||||
tv->set_int_value(pbv.numeric_value.int_value);
|
tv->set_int_value(pbv.numeric_value.int_value);
|
||||||
} else if (pbv.type == pb_uint) {
|
} else if (pbv.type == mvt_uint) {
|
||||||
tv->set_uint_value(pbv.numeric_value.uint_value);
|
tv->set_uint_value(pbv.numeric_value.uint_value);
|
||||||
} else if (pbv.type == pb_sint) {
|
} else if (pbv.type == mvt_sint) {
|
||||||
tv->set_sint_value(pbv.numeric_value.sint_value);
|
tv->set_sint_value(pbv.numeric_value.sint_value);
|
||||||
} else if (pbv.type == pb_bool) {
|
} else if (pbv.type == mvt_bool) {
|
||||||
tv->set_bool_value(pbv.numeric_value.bool_value);
|
tv->set_bool_value(pbv.numeric_value.bool_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,11 +216,11 @@ std::string pb_encode(pb_tile &in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int type = in.layers[i].features[f].type;
|
int type = in.layers[i].features[f].type;
|
||||||
if (type == pb_point) {
|
if (type == mvt_point) {
|
||||||
feature->set_type(mapnik::vector::tile::Point);
|
feature->set_type(mapnik::vector::tile::Point);
|
||||||
} else if (type == pb_linestring) {
|
} else if (type == mvt_linestring) {
|
||||||
feature->set_type(mapnik::vector::tile::LineString);
|
feature->set_type(mapnik::vector::tile::LineString);
|
||||||
} else if (type == pb_polygon) {
|
} else if (type == mvt_polygon) {
|
||||||
feature->set_type(mapnik::vector::tile::Polygon);
|
feature->set_type(mapnik::vector::tile::Polygon);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Corrupt geometry type\n");
|
fprintf(stderr, "Corrupt geometry type\n");
|
||||||
@@ -236,7 +236,7 @@ std::string pb_encode(pb_tile &in) {
|
|||||||
int cmd = -1;
|
int cmd = -1;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
|
||||||
std::vector<pb_geometry> &geom = in.layers[i].features[f].geometry;
|
std::vector<mvt_geometry> &geom = in.layers[i].features[f].geometry;
|
||||||
|
|
||||||
for (size_t g = 0; g < geom.size(); g++) {
|
for (size_t g = 0; g < geom.size(); g++) {
|
||||||
int op = geom[g].op;
|
int op = geom[g].op;
|
||||||
@@ -252,7 +252,7 @@ std::string pb_encode(pb_tile &in) {
|
|||||||
feature->add_geometry(0);
|
feature->add_geometry(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op == pb_moveto || op == pb_lineto) {
|
if (op == mvt_moveto || op == mvt_lineto) {
|
||||||
long long wwx = geom[g].x;
|
long long wwx = geom[g].x;
|
||||||
long long wwy = geom[g].y;
|
long long wwy = geom[g].y;
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ std::string pb_encode(pb_tile &in) {
|
|||||||
px = wwx;
|
px = wwx;
|
||||||
py = wwy;
|
py = wwy;
|
||||||
length++;
|
length++;
|
||||||
} else if (op == pb_closepath) {
|
} else if (op == mvt_closepath) {
|
||||||
length++;
|
length++;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "\nInternal error: corrupted geometry\n");
|
fprintf(stderr, "\nInternal error: corrupted geometry\n");
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
bool is_compressed(std::string const &data);
|
||||||
|
int decompress(std::string const &input, std::string &output);
|
||||||
|
int compress(std::string const &input, std::string &output);
|
||||||
|
int dezig(unsigned n);
|
||||||
|
|
||||||
|
enum mvt_geometry_type {
|
||||||
|
mvt_point = 1, mvt_linestring = 2, mvt_polygon = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mvt_operation {
|
||||||
|
mvt_moveto = 1, mvt_lineto = 2, mvt_closepath = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mvt_value_type {
|
||||||
|
mvt_string, mvt_float, mvt_double, mvt_int, mvt_uint, mvt_sint, mvt_bool
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mvt_value {
|
||||||
|
mvt_value_type type;
|
||||||
|
std::string string_value;
|
||||||
|
union {
|
||||||
|
float float_value;
|
||||||
|
double double_value;
|
||||||
|
long long int_value;
|
||||||
|
unsigned long long uint_value;
|
||||||
|
long long sint_value;
|
||||||
|
bool bool_value;
|
||||||
|
} numeric_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mvt_geometry {
|
||||||
|
int /* mvt_operation */ op;
|
||||||
|
long long x;
|
||||||
|
long long y;
|
||||||
|
|
||||||
|
mvt_geometry(int op, long long x, long long y) {
|
||||||
|
this->op = op;
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mvt_feature {
|
||||||
|
std::vector<unsigned> tags;
|
||||||
|
int /* mvt_geometry_type */ type;
|
||||||
|
std::vector<mvt_geometry> geometry;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mvt_layer {
|
||||||
|
int version;
|
||||||
|
std::string name;
|
||||||
|
std::vector<mvt_feature> features;
|
||||||
|
std::vector<std::string> keys;
|
||||||
|
std::vector<mvt_value> values;
|
||||||
|
int extent;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mvt_tile {
|
||||||
|
std::vector<mvt_layer> layers;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool mvt_decode(std::string &message, mvt_tile &out);
|
||||||
|
std::string mvt_encode(mvt_tile &in);
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
bool is_compressed(std::string const &data);
|
|
||||||
int decompress(std::string const &input, std::string &output);
|
|
||||||
int compress(std::string const &input, std::string &output);
|
|
||||||
int dezig(unsigned n);
|
|
||||||
|
|
||||||
enum pb_geometry_type {
|
|
||||||
pb_point = 1, pb_linestring = 2, pb_polygon = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
enum pb_operation {
|
|
||||||
pb_moveto = 1, pb_lineto = 2, pb_closepath = 7
|
|
||||||
};
|
|
||||||
|
|
||||||
enum pb_value_type {
|
|
||||||
pb_string, pb_float, pb_double, pb_int, pb_uint, pb_sint, pb_bool
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pb_value {
|
|
||||||
pb_value_type type;
|
|
||||||
std::string string_value;
|
|
||||||
union {
|
|
||||||
float float_value;
|
|
||||||
double double_value;
|
|
||||||
long long int_value;
|
|
||||||
unsigned long long uint_value;
|
|
||||||
long long sint_value;
|
|
||||||
bool bool_value;
|
|
||||||
} numeric_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pb_geometry {
|
|
||||||
int /* pb_operation */ op;
|
|
||||||
long long x;
|
|
||||||
long long y;
|
|
||||||
|
|
||||||
pb_geometry(int op, long long x, long long y) {
|
|
||||||
this->op = op;
|
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pb_feature {
|
|
||||||
std::vector<unsigned> tags;
|
|
||||||
int /* pb_geometry_type */ type;
|
|
||||||
std::vector<pb_geometry> geometry;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pb_layer {
|
|
||||||
int version;
|
|
||||||
std::string name;
|
|
||||||
std::vector<pb_feature> features;
|
|
||||||
std::vector<std::string> keys;
|
|
||||||
std::vector<pb_value> values;
|
|
||||||
int extent;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pb_tile {
|
|
||||||
std::vector<pb_layer> layers;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool pb_decode(std::string &message, pb_tile &out);
|
|
||||||
std::string pb_encode(pb_tile &in);
|
|
||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "protobuf.hh"
|
#include "mvt.hh"
|
||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "protobuf.hh"
|
#include "mvt.hh"
|
||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
#include "geometry.hh"
|
#include "geometry.hh"
|
||||||
|
|
||||||
@@ -38,11 +38,11 @@ extern "C" {
|
|||||||
pthread_mutex_t db_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t db_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_t var_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t var_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
std::vector<pb_geometry> to_feature(drawvec &geom) {
|
std::vector<mvt_geometry> to_feature(drawvec &geom) {
|
||||||
std::vector<pb_geometry> out;
|
std::vector<mvt_geometry> out;
|
||||||
|
|
||||||
for (size_t i = 0; i < geom.size(); i++) {
|
for (size_t i = 0; i < geom.size(); i++) {
|
||||||
out.push_back(pb_geometry(geom[i].op, geom[i].x, geom[i].y));
|
out.push_back(mvt_geometry(geom[i].op, geom[i].x, geom[i].y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@@ -203,8 +203,8 @@ static int is_integer(const char *s, long long *v) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pb_tile create_tile(char **layernames, int line_detail, std::vector<std::vector<coalesce> > &features, long long *count, struct pool **keys, struct pool **values, int nlayers) {
|
mvt_tile create_tile(char **layernames, int line_detail, std::vector<std::vector<coalesce> > &features, long long *count, struct pool **keys, struct pool **values, int nlayers) {
|
||||||
pb_tile tile;
|
mvt_tile tile;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < nlayers; i++) {
|
for (i = 0; i < nlayers; i++) {
|
||||||
@@ -212,7 +212,7 @@ pb_tile create_tile(char **layernames, int line_detail, std::vector<std::vector<
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pb_layer layer;
|
mvt_layer layer;
|
||||||
|
|
||||||
layer.name = layernames[i];
|
layer.name = layernames[i];
|
||||||
layer.version = 1;
|
layer.version = 1;
|
||||||
@@ -223,7 +223,7 @@ pb_tile create_tile(char **layernames, int line_detail, std::vector<std::vector<
|
|||||||
features[i][x].geom = remove_noop(features[i][x].geom, features[i][x].type, 0);
|
features[i][x].geom = remove_noop(features[i][x].geom, features[i][x].type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pb_feature pbf;
|
mvt_feature pbf;
|
||||||
pbf.type = features[i][x].type;
|
pbf.type = features[i][x].type;
|
||||||
|
|
||||||
pbf.geometry = to_feature(features[i][x].geom);
|
pbf.geometry = to_feature(features[i][x].geom);
|
||||||
@@ -241,27 +241,27 @@ pb_tile create_tile(char **layernames, int line_detail, std::vector<std::vector<
|
|||||||
layer.keys.push_back(std::string(pv->s, strlen(pv->s)));
|
layer.keys.push_back(std::string(pv->s, strlen(pv->s)));
|
||||||
}
|
}
|
||||||
for (pv = values[i]->head; pv != NULL; pv = pv->next) {
|
for (pv = values[i]->head; pv != NULL; pv = pv->next) {
|
||||||
pb_value tv;
|
mvt_value tv;
|
||||||
|
|
||||||
if (pv->type == VT_NUMBER) {
|
if (pv->type == VT_NUMBER) {
|
||||||
long long v;
|
long long v;
|
||||||
if (is_integer(pv->s, &v)) {
|
if (is_integer(pv->s, &v)) {
|
||||||
if (v >= 0) {
|
if (v >= 0) {
|
||||||
tv.type = pb_int;
|
tv.type = mvt_int;
|
||||||
tv.numeric_value.int_value = v;
|
tv.numeric_value.int_value = v;
|
||||||
} else {
|
} else {
|
||||||
tv.type = pb_sint;
|
tv.type = mvt_sint;
|
||||||
tv.numeric_value.sint_value = v;
|
tv.numeric_value.sint_value = v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tv.type = pb_double;
|
tv.type = mvt_double;
|
||||||
tv.numeric_value.double_value = atof(pv->s);
|
tv.numeric_value.double_value = atof(pv->s);
|
||||||
}
|
}
|
||||||
} else if (pv->type == VT_BOOLEAN) {
|
} else if (pv->type == VT_BOOLEAN) {
|
||||||
tv.type = pb_bool;
|
tv.type = mvt_bool;
|
||||||
tv.numeric_value.bool_value = (pv->s[0] == 't');
|
tv.numeric_value.bool_value = (pv->s[0] == 't');
|
||||||
} else {
|
} else {
|
||||||
tv.type = pb_string;
|
tv.type = mvt_string;
|
||||||
tv.string_value = pv->s;
|
tv.string_value = pv->s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,7 +944,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pb_tile tile = create_tile(layernames, line_detail, features, &count, keys, values, nlayers);
|
mvt_tile tile = create_tile(layernames, line_detail, features, &count, keys, values, nlayers);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < nlayers; i++) {
|
for (i = 0; i < nlayers; i++) {
|
||||||
@@ -952,7 +952,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
|
|||||||
pool_free(&values1[i]);
|
pool_free(&values1[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string compressed = pb_encode(tile);
|
std::string compressed = mvt_encode(tile);
|
||||||
|
|
||||||
if (compressed.size() > 500000 && !prevent[P_KILOBYTE_LIMIT]) {
|
if (compressed.size() > 500000 && !prevent[P_KILOBYTE_LIMIT]) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user