Skip to content

Commit

Permalink
Work in progress on inverse spatial ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Dec 15, 2023
1 parent fa5a7cd commit fdf230f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,7 @@ int main(int argc, char **argv) {
{"order-descending-by", required_argument, 0, '~'},
{"order-smallest-first", no_argument, 0, '~'},
{"order-largest-first", no_argument, 0, '~'},
{"order-spatial-inverse", no_argument, 0, '~'},

{"Adding calculated attributes", 0, 0, 0},
{"calculate-feature-density", no_argument, &additional[A_CALCULATE_FEATURE_DENSITY], 1},
Expand Down Expand Up @@ -3357,6 +3358,9 @@ int main(int argc, char **argv) {
} else if (strcmp(opt, "order-largest-first") == 0) {
order_by.push_back(order_field(ORDER_BY_SIZE, true));
order_by_size = true;
} else if (strcmp(opt, "order-spatial-inverse") == 0) {
order_by.push_back(order_field(ORDER_SPATIAL, false));
order_by.push_back(order_field(ORDER_BY_FEATURE_MINZOOM, false));
} else if (strcmp(opt, "simplification-at-maximum-zoom") == 0) {
maxzoom_simplification = atof_require(optarg, "Mazoom simplification");
if (maxzoom_simplification <= 0) {
Expand Down
3 changes: 3 additions & 0 deletions main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ extern std::vector<order_field> order_by;
#define ORDER_BY_SIZE "\200size"
extern bool order_by_size;

#define ORDER_SPATIAL "\200spatial"
#define ORDER_BY_FEATURE_MINZOOM "\200feature_minzoom"

int mkstemp_cloexec(char *name);
FILE *fopen_oflag(const char *name, const char *mode, int oflag);
bool progress_time();
Expand Down
3 changes: 3 additions & 0 deletions serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,14 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
}
}

#if 0
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED] || additional[A_INCREASE_GAMMA_AS_NEEDED] || additional[A_GENERATE_POLYGON_LABEL_POINTS] || sst->uses_gamma || cluster_distance != 0) {
sf.index = bbox_index;
} else {
sf.index = 0;
}
#endif
sf.index = bbox_index;

if (sst->layermap->count(sf.layername) == 0) {
sst->layermap->insert(std::pair<std::string, layermap_entry>(sf.layername, layermap_entry(sst->layermap->size())));
Expand Down
40 changes: 40 additions & 0 deletions tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct coalesce {
bool has_id = false;
unsigned long long id = 0;
long long extent = 0;
signed char feature_minzoom = 0;

bool operator<(const coalesce &o) const {
int cmp = coalindexcmp(this, &o);
Expand Down Expand Up @@ -253,13 +254,34 @@ static int metacmp(const std::vector<long long> &keys1, const std::vector<long l
}
}

static unsigned long long flop(unsigned long long v) {
unsigned long long out = 0;
for (size_t i = 0; i < 64; i++) {
out |= ((v >> i) & 1) << (63 - i);
}

return out;
}

static mvt_value find_attribute_value(const struct coalesce *c1, std::string key) {
if (key == ORDER_BY_SIZE) {
mvt_value v;
v.type = mvt_double;
v.numeric_value.double_value = c1->extent;
return v;
}
if (key == ORDER_SPATIAL) {
mvt_value v;
v.type = mvt_uint;
v.numeric_value.uint_value = flop(c1->index);
return v;
}
if (key == ORDER_BY_FEATURE_MINZOOM) {
mvt_value v;
v.type = mvt_double;
v.numeric_value.double_value = c1->feature_minzoom;
return v;
}

const std::vector<long long> &keys1 = c1->keys;
const std::vector<long long> &values1 = c1->values;
Expand Down Expand Up @@ -467,6 +489,7 @@ struct partial {
double spacing = 0;
double simplification = 0;
signed char t = 0;
signed char feature_minzoom = 0;
unsigned long long id = 0;
bool has_id = 0;
ssize_t renamed = 0;
Expand Down Expand Up @@ -2266,6 +2289,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
p.renamed = -1;
p.extent = sf.extent;
p.clustered = 0;
p.feature_minzoom = sf.feature_minzoom;

if (line_detail == detail && extra_detail >= 0 && z == maxzoom) {
p.extra_detail = extra_detail;
Expand Down Expand Up @@ -2312,6 +2336,21 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
for (size_t i = 0; i < partials.size(); i++) {
partial &p = partials[i];

{
std::string layername = (*layer_unmaps)[p.segment][p.layer];

serial_val sv, sv2;
p.full_keys.push_back("inverse_index");
sv.type = mvt_double;
sv.s = std::to_string(flop(p.index));
p.full_values.push_back(sv);

p.full_keys.push_back("feature_minzoom");
sv2.type = mvt_double;
sv2.s = std::to_string(p.feature_minzoom);
p.full_values.push_back(sv2);
}

if (p.clustered > 0) {
std::string layername = (*layer_unmaps)[p.segment][p.layer];
serial_val sv, sv2, sv3, sv4;
Expand Down Expand Up @@ -2456,6 +2495,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
c.id = partials[i].id;
c.has_id = partials[i].has_id;
c.extent = partials[i].extent;
c.feature_minzoom = partials[i].feature_minzoom;

// printf("segment %d layer %lld is %s\n", partials[i].segment, partials[i].layer, (*layer_unmaps)[partials[i].segment][partials[i].layer].c_str());

Expand Down

0 comments on commit fdf230f

Please sign in to comment.