Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,10 @@ drawvec polygon_to_anchor(const drawvec &geom) {
return drawvec();
}

drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point) {
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned wx, unsigned wy) {
drawvec out;

// anchor point in world coordinates
unsigned wx, wy;
decode_index(label_point, &wx, &wy);
// wx,wy is anchor point in world coordinates

// upper left of tile in world coordinates
long long tx1 = 0, ty1 = 0;
Expand Down
2 changes: 1 addition & 1 deletion geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void check_polygon(drawvec &geom);
double get_area(const drawvec &geom, size_t i, size_t j);
double get_mp_area(drawvec &geom);
drawvec polygon_to_anchor(const drawvec &geom);
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point);
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned label_x, unsigned label_y);

drawvec simple_clip_poly(drawvec &geom, int z, int buffer, drawvec &shared_nodes, bool prevent_simplify_shared_nodes);
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2, bool prevent_simplify_shared_nodes);
Expand Down
22 changes: 22 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ unsigned int drop_denser = 0;
std::map<std::string, serial_val> set_attributes;
unsigned long long preserve_point_density_threshold = 0;
unsigned long long preserve_multiplier_density_threshold = 0;
std::vector<int> preserve_multiplier_density_bits_by_zoom;
long long extend_zooms_max = 0;
int retain_points_multiplier = 1;
std::vector<std::string> unidecode_data;
size_t maximum_string_attribute_length = 0;
std::string accumulate_numeric;
std::string use_h3_index;

std::vector<order_field> order_by;
bool order_reverse;
Expand Down Expand Up @@ -2498,6 +2500,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
long long ip;
for (ip = 0; ip < indices; ip++) {
unsigned xx, yy;
// XXX this will behave oddly if the index is actually H3
decode_index(map[ip].ix, &xx, &yy);

long long nprogress = 100 * ip / indices;
Expand Down Expand Up @@ -3087,6 +3090,7 @@ int main(int argc, char **argv) {
{"cluster-maxzoom", required_argument, 0, 'k'},
{"preserve-point-density-threshold", required_argument, 0, '~'},
{"preserve-multiplier-density-threshold", required_argument, 0, '~'},
{"preserve-multiplier-density-bits-by-zoom", required_argument, 0, '~'},

{"Dropping or merging a fraction of features to keep under tile size limits", 0, 0, 0},
{"drop-densest-as-needed", no_argument, &additional[A_DROP_DENSEST_AS_NEEDED], 1},
Expand Down Expand Up @@ -3128,6 +3132,7 @@ int main(int argc, char **argv) {
{"coalesce", no_argument, &additional[A_COALESCE], 1},
{"reverse", no_argument, &additional[A_REVERSE], 1},
{"hilbert", no_argument, &additional[A_HILBERT], 1},
{"use-h3-index", required_argument, 0, '~'},
{"order-by", required_argument, 0, '~'},
{"order-descending-by", required_argument, 0, '~'},
{"order-smallest-first", no_argument, 0, '~'},
Expand Down Expand Up @@ -3269,6 +3274,8 @@ int main(int argc, char **argv) {
fprintf(stderr, "%s: --extra-detail can be at most 30\n", argv[0]);
exit(EXIT_ARGS);
}
} else if (strcmp(opt, "use-h3-index") == 0) {
use_h3_index = optarg;
} else if (strcmp(opt, "order-by") == 0) {
order_by.push_back(order_field(optarg, false));
} else if (strcmp(opt, "order-descending-by") == 0) {
Expand Down Expand Up @@ -3300,6 +3307,21 @@ int main(int argc, char **argv) {
preserve_point_density_threshold = atoll_require(optarg, "Preserve point density threshold");
} else if (strcmp(opt, "preserve-multiplier-density-threshold") == 0) {
preserve_multiplier_density_threshold = atoll_require(optarg, "Preserve multiplier density threshold");
} else if (strcmp(opt, "preserve-multiplier-density-bits-by-zoom") == 0) {
const char *cp = optarg;
while (*cp != '\0') {
if (!isdigit(*cp)) {
fprintf(stderr, "%s: unexpected multiplier density bits by zoom %s\n", argv[0], cp);
exit(EXIT_ARGS);
}
preserve_multiplier_density_bits_by_zoom.push_back(atoi(cp));
while (isdigit(*cp)) {
cp++;
}
if (*cp == ',') {
cp++;
}
}
} else if (strcmp(opt, "extend-zooms-if-still-dropping-maximum") == 0) {
extend_zooms_max = atoll_require(optarg, "Maximum number by which to extend zooms");
} else if (strcmp(opt, "retain-points-multiplier") == 0) {
Expand Down
2 changes: 2 additions & 0 deletions main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ extern long long extend_zooms_max;
extern int retain_points_multiplier;
extern size_t maximum_string_attribute_length;
extern std::string accumulate_numeric;
extern std::string use_h3_index;
extern unsigned long long preserve_multiplier_density_threshold;
extern std::vector<int> preserve_multiplier_density_bits_by_zoom;

struct order_field {
std::string name;
Expand Down
37 changes: 31 additions & 6 deletions serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {

long long layer = 0;
layer |= sf->layer << FLAG_LAYER;
layer |= (sf->label_point != 0) << FLAG_LABEL_POINT;
layer |= ((sf->label_x | sf->label_y) != 0) << FLAG_LABEL_POINT;
layer |= (sf->index != 0) << FLAG_INDEX;
layer |= (sf->extent != 0) << FLAG_EXTENT;
layer |= sf->has_id << FLAG_ID;
Expand All @@ -211,10 +211,13 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {

if (sf->index != 0) {
serialize_ulong_long(s, sf->index);
serialize_uint(s, sf->wx);
serialize_uint(s, sf->wy);
serialize_ulong_long(s, sf->gap);
}
if (sf->label_point != 0) {
serialize_ulong_long(s, sf->label_point);
if ((sf->label_x | sf->label_y) != 0) {
serialize_uint(s, sf->label_x);
serialize_uint(s, sf->label_y);
}
if (sf->extent != 0) {
serialize_long_long(s, sf->extent);
Expand Down Expand Up @@ -261,17 +264,21 @@ serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigne

sf.index = 0;
sf.gap = 0;
sf.label_point = 0;
sf.label_x = 0;
sf.label_y = 0;
sf.extent = 0;

sf.geometry = decode_geometry(&cp, z, tx, ty, sf.bbox, initial_x[sf.segment], initial_y[sf.segment]);

if (sf.layer & (1 << FLAG_INDEX)) {
deserialize_ulong_long(&cp, &sf.index);
deserialize_uint(&cp, &sf.wx);
deserialize_uint(&cp, &sf.wy);
deserialize_ulong_long(&cp, &sf.gap);
}
if (sf.layer & (1 << FLAG_LABEL_POINT)) {
deserialize_ulong_long(&cp, &sf.label_point);
deserialize_uint(&cp, &sf.label_x);
deserialize_uint(&cp, &sf.label_y);
}
if (sf.layer & (1 << FLAG_EXTENT)) {
deserialize_long_long(&cp, &sf.extent);
Expand Down Expand Up @@ -714,6 +721,19 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
}

bbox_index = encode_index(midx, midy);

if (use_h3_index.size() > 0) {
for (size_t i = 0; i < sf.full_keys.size(); i++) {
if (*(sf.full_keys[i]) == use_h3_index) {
unsigned long long h3_index = atoll(sf.full_values[i].s.c_str());
// the top 52 bits of the feature index are the H3 index;
// the bottom 12 bits are retained from what otherwise would have been the index.
bbox_index = ((h3_index & ((1LL << 52) - 1)) << 12) | (bbox_index & ((1 << 12) - 1));
break;
}
}
}

if (additional[A_CALCULATE_INDEX]) {
sf.full_keys.push_back(key_pool.pool("tippecanoe:index"));

Expand All @@ -728,7 +748,8 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
if (dv.size() > 0) {
dv[0].x = SHIFT_LEFT(dv[0].x) & ((1LL << 32) - 1);
dv[0].y = SHIFT_LEFT(dv[0].y) & ((1LL << 32) - 1);
sf.label_point = encode_index(dv[0].x, dv[0].y);
sf.label_x = dv[0].x;
sf.label_y = dv[0].y;
}
}

Expand All @@ -748,8 +769,12 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
preserve_multiplier_density_threshold > 0 ||
cluster_distance != 0) {
sf.index = bbox_index;
sf.wx = midx;
sf.wy = midy;
} else {
sf.index = 0;
sf.wx = 0;
sf.wy = 0;
}

if (sst->layermap->count(layername) == 0) {
Expand Down
7 changes: 6 additions & 1 deletion serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ struct serial_val {
s = milo::dtoa_milo(val);
}

std::string toString() const {
return s;
}

double to_double() const {
return atof(s.c_str());
}
Expand Down Expand Up @@ -118,8 +122,9 @@ struct serial_feature {

drawvec geometry = drawvec();
unsigned long long index = 0;
unsigned wx = 0, wy = 0;
unsigned long long gap = 0; // filled in during z0. square of planar distance
unsigned long long label_point = 0;
unsigned label_x = 0, label_y = 0;
long long extent = 0;

// These fields are not directly serialized, but are used
Expand Down
Loading