diff --git a/decode.cpp b/decode.cpp index ecc7232..dca817a 100644 --- a/decode.cpp +++ b/decode.cpp @@ -54,9 +54,10 @@ struct lonlat { void handle(std::string message, int z, unsigned x, unsigned y, int describe, std::set const &to_decode) { int within = 0; mvt_tile tile; + bool was_compressed; try { - if (!tile.decode(message)) { + if (!tile.decode(message, was_compressed)) { fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", z, x, y); exit(EXIT_FAILURE); } @@ -68,7 +69,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe, st printf("{ \"type\": \"FeatureCollection\""); if (describe) { - printf(", \"properties\": { \"zoom\": %d, \"x\": %d, \"y\": %d }", z, x, y); + printf(", \"properties\": { \"zoom\": %d, \"x\": %d, \"y\": %d", z, x, y); + if (!was_compressed) { + printf(", \"compressed\": false"); + } + + printf(" }"); if (projection != projections) { printf(", \"crs\": { \"type\": \"name\", \"properties\": { \"name\": "); diff --git a/mvt.cpp b/mvt.cpp index 22198e9..a7bf259 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -79,7 +79,7 @@ int compress(std::string const &input, std::string &output) { return 0; } -bool mvt_tile::decode(std::string &message) { +bool mvt_tile::decode(std::string &message, bool &was_compressed) { layers.clear(); std::string src; @@ -87,8 +87,10 @@ bool mvt_tile::decode(std::string &message) { std::string uncompressed; decompress(message, uncompressed); src = uncompressed; + was_compressed = true; } else { src = message; + was_compressed = false; } protozero::pbf_reader reader(src); diff --git a/mvt.hpp b/mvt.hpp index 6e9d792..7d5f334 100644 --- a/mvt.hpp +++ b/mvt.hpp @@ -91,7 +91,7 @@ struct mvt_tile { std::vector layers; std::string encode(); - bool decode(std::string &message); + bool decode(std::string &message, bool &was_compressed); }; bool is_compressed(std::string const &data); diff --git a/tile-join.cpp b/tile-join.cpp index 3454e5e..3677337 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -32,8 +32,9 @@ struct stats { void handle(std::string message, int z, unsigned x, unsigned y, std::map &layermap, std::vector &header, std::map> &mapping, std::set &exclude, std::set &keep_layers, std::set &remove_layers, int ifmatched, mvt_tile &outtile) { mvt_tile tile; int features_added = 0; + bool was_compressed; - if (!tile.decode(message)) { + if (!tile.decode(message, was_compressed)) { fprintf(stderr, "Couldn't decompress tile %d/%u/%u\n", z, x, y); exit(EXIT_FAILURE); } @@ -402,7 +403,9 @@ void *join_worker(void *v) { } if (anything) { - std::string compressed = tile.encode(); + std::string pbf = tile.encode(); + std::string compressed; + compress(pbf, compressed); if (!pk && compressed.size() > 500000) { fprintf(stderr, "Tile %lld/%lld/%lld size is %lld, >500000. Skipping this tile\n.", ai->first.z, ai->first.x, ai->first.y, (long long) compressed.size());