mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Look up the attribute value for ordering
This commit is contained in:
@@ -755,7 +755,7 @@ static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<d
|
||||
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
size_t multiplier, std::string const &filter) {
|
||||
size_t multiplier, std::string const &order_by) {
|
||||
mvt_tile tile;
|
||||
|
||||
try {
|
||||
@@ -769,7 +769,7 @@ std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int
|
||||
exit(EXIT_PROTOBUF);
|
||||
}
|
||||
|
||||
return overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, multiplier, filter);
|
||||
return overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, multiplier, order_by);
|
||||
}
|
||||
|
||||
struct tile_feature {
|
||||
@@ -781,6 +781,12 @@ struct tile_feature {
|
||||
mvt_layer const *layer;
|
||||
|
||||
mvt_value value(std::string const &attr) const {
|
||||
for (size_t i = 0; i + 1 < tags.size(); i += 2) {
|
||||
if (layer->keys[tags[i]] == attr) {
|
||||
return layer->values[tags[i + 1]];
|
||||
}
|
||||
}
|
||||
|
||||
mvt_value v;
|
||||
v.type = mvt_null;
|
||||
return v;
|
||||
@@ -798,12 +804,12 @@ struct sorter {
|
||||
mvt_value av = a.value(attr);
|
||||
mvt_value bv = b.value(attr);
|
||||
|
||||
av = av.promote_for_comparison_with(bv);
|
||||
bv = bv.promote_for_comparison_with(av);
|
||||
if (av.type != bv.type) {
|
||||
fprintf(stderr, "Sorter: can't happen\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
av = av.promote_for_comparison_with(bv);
|
||||
bv = bv.promote_for_comparison_with(av);
|
||||
if (av.type != bv.type) {
|
||||
fprintf(stderr, "Sorter: can't happen\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
return av < bv;
|
||||
}
|
||||
@@ -839,7 +845,7 @@ void feature_out(tile_feature const &feature, mvt_layer &outlayer, std::set<std:
|
||||
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
size_t multiplier, std::string const &filter) {
|
||||
size_t multiplier, std::string const &order_by) {
|
||||
mvt_tile outtile;
|
||||
|
||||
for (auto const &layer : tile.layers) {
|
||||
@@ -940,14 +946,14 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int
|
||||
tile_features.push_back(tf);
|
||||
|
||||
if (tile_features.size() >= multiplier) {
|
||||
std::sort(tile_features.begin(), tile_features.end(), sorter(filter));
|
||||
std::sort(tile_features.begin(), tile_features.end(), sorter(order_by));
|
||||
feature_out(tile_features[0], outlayer, keep);
|
||||
tile_features.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (tile_features.size() > 0) {
|
||||
std::sort(tile_features.begin(), tile_features.end(), sorter(filter));
|
||||
std::sort(tile_features.begin(), tile_features.end(), sorter(order_by));
|
||||
feature_out(tile_features[0], outlayer, keep);
|
||||
tile_features.clear();
|
||||
}
|
||||
@@ -971,7 +977,7 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int
|
||||
std::string child = overzoom(outtile, nz, nx, ny,
|
||||
nz + 1, nx * 2 + x, ny * 2 + y,
|
||||
detail, buffer, keep, false, NULL,
|
||||
multiplier, filter);
|
||||
multiplier, order_by);
|
||||
if (child.size() > 0) {
|
||||
next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y);
|
||||
}
|
||||
|
||||
+2
-2
@@ -101,11 +101,11 @@ double distance_from_line(long long point_x, long long point_y, long long segA_x
|
||||
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
size_t multiplier, std::string const &filter);
|
||||
size_t multiplier, std::string const &order_by);
|
||||
|
||||
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
size_t multiplier, std::string const &filter);
|
||||
size_t multiplier, std::string const &order_by);
|
||||
|
||||
#endif
|
||||
|
||||
+5
-5
@@ -13,7 +13,7 @@ extern int optind;
|
||||
int detail = 12; // tippecanoe-style: mvt extent == 1 << detail
|
||||
int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256;
|
||||
int multiplier = 1;
|
||||
std::string filter;
|
||||
std::string order_by;
|
||||
|
||||
std::set<std::string> keep;
|
||||
|
||||
@@ -27,7 +27,7 @@ int main(int argc, char **argv) {
|
||||
int i;
|
||||
const char *outfile = NULL;
|
||||
|
||||
while ((i = getopt(argc, argv, "y:o:d:b:f:m:")) != -1) {
|
||||
while ((i = getopt(argc, argv, "y:o:d:b:O:m:")) != -1) {
|
||||
switch (i) {
|
||||
case 'y':
|
||||
keep.insert(optarg);
|
||||
@@ -49,8 +49,8 @@ int main(int argc, char **argv) {
|
||||
multiplier = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
filter = optarg;
|
||||
case 'O':
|
||||
order_by = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -101,7 +101,7 @@ int main(int argc, char **argv) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, true, NULL, multiplier, filter);
|
||||
std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep, true, NULL, multiplier, order_by);
|
||||
fwrite(out.c_str(), sizeof(char), out.size(), f);
|
||||
fclose(f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user