mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Reviving multi-source-tile overzoom: the clip.cpp side
This commit is contained in:
@@ -755,24 +755,36 @@ static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<d
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string overzoom(const std::string &s, int oz, int ox, int oy, int nz, int nx, int ny,
|
std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
|
||||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||||
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::vector<std::string> const &unidecode_data) {
|
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::vector<std::string> const &unidecode_data) {
|
||||||
|
std::vector<source_tile> decoded;
|
||||||
|
|
||||||
|
for (auto const &t : tiles) {
|
||||||
mvt_tile tile;
|
mvt_tile tile;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bool was_compressed;
|
bool was_compressed;
|
||||||
if (!tile.decode(s, was_compressed)) {
|
if (!tile.decode(t.tile, was_compressed)) {
|
||||||
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", oz, ox, oy);
|
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", t.z, t.x, t.y);
|
||||||
exit(EXIT_MVT);
|
exit(EXIT_MVT);
|
||||||
}
|
}
|
||||||
} catch (std::exception const &e) {
|
} catch (std::exception const &e) {
|
||||||
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", oz, ox, oy);
|
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", t.z, t.x, t.y);
|
||||||
exit(EXIT_PROTOBUF);
|
exit(EXIT_PROTOBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
return overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data);
|
source_tile out;
|
||||||
|
out.tile = tile;
|
||||||
|
out.z = t.z;
|
||||||
|
out.x = t.x;
|
||||||
|
out.y = t.y;
|
||||||
|
|
||||||
|
decoded.push_back(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
return overzoom(decoded, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tile_feature {
|
struct tile_feature {
|
||||||
@@ -870,24 +882,38 @@ static struct preservecmp {
|
|||||||
}
|
}
|
||||||
} preservecmp;
|
} preservecmp;
|
||||||
|
|
||||||
std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int nx, int ny,
|
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||||
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::vector<std::string> const &unidecode_data) {
|
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::vector<std::string> const &unidecode_data) {
|
||||||
mvt_tile outtile;
|
mvt_tile outtile;
|
||||||
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
|
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
|
||||||
|
|
||||||
for (auto const &layer : tile.layers) {
|
for (auto const &tile : tiles) {
|
||||||
mvt_layer outlayer = mvt_layer();
|
for (auto const &layer : tile.tile.layers) {
|
||||||
|
mvt_layer *outlayer = NULL;
|
||||||
|
|
||||||
int det = detail;
|
int det = detail;
|
||||||
if (det <= 0) {
|
if (det <= 0) {
|
||||||
det = std::round(log(layer.extent) / log(2));
|
det = std::round(log(layer.extent) / log(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
outlayer.name = layer.name;
|
for (size_t i = 0; i < outtile.layers.size(); i++) {
|
||||||
outlayer.version = layer.version;
|
if (outtile.layers[i].name == layer.name) {
|
||||||
outlayer.extent = 1LL << det;
|
outlayer = &outtile.layers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outlayer == NULL) {
|
||||||
|
mvt_layer newlayer = mvt_layer();
|
||||||
|
|
||||||
|
newlayer.name = layer.name;
|
||||||
|
newlayer.version = layer.version;
|
||||||
|
newlayer.extent = 1LL << det;
|
||||||
|
|
||||||
|
outtile.layers.push_back(newlayer);
|
||||||
|
outlayer = &outtile.layers.back();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<tile_feature> pending_tile_features;
|
std::vector<tile_feature> pending_tile_features;
|
||||||
|
|
||||||
@@ -916,7 +942,7 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
|
|||||||
|
|
||||||
if (flush_multiplier_cluster) {
|
if (flush_multiplier_cluster) {
|
||||||
if (pending_tile_features.size() > 0) {
|
if (pending_tile_features.size() > 0) {
|
||||||
feature_out(pending_tile_features, outlayer, keep, attribute_accum, tile_stringpool);
|
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
|
||||||
pending_tile_features.clear();
|
pending_tile_features.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -931,18 +957,17 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
|
|||||||
|
|
||||||
// Convert feature geometry to world coordinates
|
// Convert feature geometry to world coordinates
|
||||||
|
|
||||||
long long tilesize = 1LL << (32 - oz); // source tile size in world coordinates
|
long long tilesize = 1LL << (32 - tile.z); // source tile size in world coordinates
|
||||||
draw ring_closure(0, 0, 0);
|
draw ring_closure(0, 0, 0);
|
||||||
bool sametile = (nz == oz && nx == ox && ny == oy && outlayer.extent >= layer.extent);
|
bool sametile = (nz == tile.z && nx == tile.x && ny == tile.y && outlayer->extent >= layer.extent);
|
||||||
|
|
||||||
for (auto const &g : feature.geometry) {
|
for (auto const &g : feature.geometry) {
|
||||||
if (g.op == mvt_closepath) {
|
if (g.op == mvt_closepath) {
|
||||||
geom.push_back(ring_closure);
|
geom.push_back(ring_closure);
|
||||||
} else {
|
} else {
|
||||||
geom.emplace_back(g.op,
|
geom.emplace_back(g.op,
|
||||||
g.x * tilesize / layer.extent + ox * tilesize,
|
g.x * tilesize / layer.extent + tile.x * tilesize,
|
||||||
g.y * tilesize / layer.extent + oy * tilesize);
|
g.y * tilesize / layer.extent + tile.y * tilesize);
|
||||||
|
|
||||||
if (g.op == mvt_moveto) {
|
if (g.op == mvt_moveto) {
|
||||||
ring_closure = geom.back();
|
ring_closure = geom.back();
|
||||||
ring_closure.op = mvt_lineto;
|
ring_closure.op = mvt_lineto;
|
||||||
@@ -1019,16 +1044,13 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pending_tile_features.size() > 0) {
|
if (pending_tile_features.size() > 0) {
|
||||||
feature_out(pending_tile_features, outlayer, keep, attribute_accum, tile_stringpool);
|
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
|
||||||
pending_tile_features.clear();
|
pending_tile_features.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preserve_input_order) {
|
if (preserve_input_order) {
|
||||||
std::stable_sort(outlayer.features.begin(), outlayer.features.end(), preservecmp);
|
std::stable_sort(outlayer->features.begin(), outlayer->features.end(), preservecmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outlayer.features.size() > 0) {
|
|
||||||
outtile.layers.push_back(std::move(outlayer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1043,7 +1065,16 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
|
|||||||
if (outtile.layers.size() > 0) {
|
if (outtile.layers.size() > 0) {
|
||||||
for (size_t x = 0; x < 2; x++) {
|
for (size_t x = 0; x < 2; x++) {
|
||||||
for (size_t y = 0; y < 2; y++) {
|
for (size_t y = 0; y < 2; y++) {
|
||||||
std::string child = overzoom(outtile, nz, nx, ny,
|
source_tile st;
|
||||||
|
st.tile = outtile;
|
||||||
|
st.z = nz;
|
||||||
|
st.x = nx;
|
||||||
|
st.y = ny;
|
||||||
|
|
||||||
|
std::vector<source_tile> sts;
|
||||||
|
sts.push_back(st);
|
||||||
|
|
||||||
|
std::string child = overzoom(sts,
|
||||||
nz + 1, nx * 2 + x, ny * 2 + y,
|
nz + 1, nx * 2 + x, ny * 2 + y,
|
||||||
detail, buffer, keep, false, NULL,
|
detail, buffer, keep, false, NULL,
|
||||||
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data);
|
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data);
|
||||||
@@ -1055,6 +1086,12 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ssize_t i = outtile.layers.size() - 1; i >= 0; i--) {
|
||||||
|
if (outtile.layers[i].features.size() == 0) {
|
||||||
|
outtile.layers.erase(outtile.layers.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (outtile.layers.size() > 0) {
|
if (outtile.layers.size() > 0) {
|
||||||
std::string pbf = outtile.encode();
|
std::string pbf = outtile.encode();
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -100,14 +100,28 @@ void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t
|
|||||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
||||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
||||||
|
|
||||||
std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int nx, int ny,
|
struct input_tile {
|
||||||
|
std::string tile;
|
||||||
|
int z;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct source_tile {
|
||||||
|
mvt_tile tile;
|
||||||
|
int z;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||||
std::vector<std::string> const &unidecode_data);
|
std::vector<std::string> const &unidecode_data);
|
||||||
|
|
||||||
std::string overzoom(const std::string &s, int oz, int ox, int oy, int nz, int nx, int ny,
|
std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
|
||||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||||
|
|||||||
+34
-22
@@ -125,33 +125,45 @@ int main(int argc, char **argv) {
|
|||||||
usage(argv);
|
usage(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tile;
|
|
||||||
char buf[1000];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
FILE *f = fopen(infile, "rb");
|
|
||||||
if (f == NULL) {
|
|
||||||
perror(infile);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((len = fread(buf, sizeof(char), 1000, f)) > 0) {
|
|
||||||
tile.append(std::string(buf, len));
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
f = fopen(outfile, "wb");
|
|
||||||
if (f == NULL) {
|
|
||||||
perror(outfile);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
json_object *json_filter = NULL;
|
json_object *json_filter = NULL;
|
||||||
if (filter.size() > 0) {
|
if (filter.size() > 0) {
|
||||||
json_filter = parse_filter(filter.c_str());
|
json_filter = parse_filter(filter.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data);
|
std::string out;
|
||||||
|
{
|
||||||
|
FILE *fi = fopen(infile, "rb");
|
||||||
|
if (fi == NULL) {
|
||||||
|
perror(infile);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string tile;
|
||||||
|
char buf[1000];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
while ((len = fread(buf, sizeof(char), 1000, fi)) > 0) {
|
||||||
|
tile.append(std::string(buf, len));
|
||||||
|
}
|
||||||
|
fclose(fi);
|
||||||
|
|
||||||
|
std::vector<input_tile> tv;
|
||||||
|
input_tile t;
|
||||||
|
t.tile = std::move(tile);
|
||||||
|
t.z = oz;
|
||||||
|
t.x = ox;
|
||||||
|
t.y = oy;
|
||||||
|
tv.push_back(std::move(t));
|
||||||
|
|
||||||
|
out = overzoom(tv, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *f = fopen(outfile, "wb");
|
||||||
|
if (f == NULL) {
|
||||||
|
perror(outfile);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(out.c_str(), sizeof(char), out.size(), f);
|
fwrite(out.c_str(), sizeof(char), out.size(), f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -704,7 +704,15 @@ struct tileset_reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (source.layers.size() != 0) {
|
if (source.layers.size() != 0) {
|
||||||
std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data);
|
std::vector<source_tile> tv;
|
||||||
|
source_tile t;
|
||||||
|
t.tile = std::move(source);
|
||||||
|
t.z = parent_tile.z;
|
||||||
|
t.x = parent_tile.x;
|
||||||
|
t.y = parent_tile.y;
|
||||||
|
tv.push_back(std::move(t));
|
||||||
|
|
||||||
|
std::string ret = overzoom(tv, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user