EXPERIMENTAL feature to extract shared polygon borders into lines

This commit is contained in:
Eric Fischer 2018-05-29 16:20:44 -07:00
parent 38bca4a179
commit cf191ed8b9
4 changed files with 28 additions and 2 deletions

View File

@ -273,6 +273,7 @@ Example: to retain only major TIGER roads at low zoom levels:
### Attempts to improve shared polygon boundaries
* `-ab` or `--detect-shared-borders`: In the manner of [TopoJSON](https://github.com/mbostock/topojson/wiki/Introduction), detect borders that are shared between multiple polygons and simplify them identically in each polygon. This takes more time and memory than considering each polygon individually.
* `-aB` or `--extract-borders`: Detect borders that are shared between multiple polygons and turn them into new features. The original polygons and their attributes, and even which layer they come from, are lost.
* `-aL` or `--grid-low-zooms`: At all zoom levels below _maxzoom_, snap all lines and polygons to a stairstep grid instead of allowing diagonals. You will also want to specify a tile resolution, probably `-D8`. This option provides a way to display continuous parcel, gridded, or binned data at low zooms without overwhelming the tiles with tiny polygons, since features will either get stretched out to the grid unit or lost entirely, depending on how they happened to be aligned in the original data. You probably don't want to use this.
### Controlling clipping to tile boundaries

View File

@ -2534,6 +2534,7 @@ int main(int argc, char **argv) {
{"Attempts to improve shared polygon boundaries", 0, 0, 0},
{"detect-shared-borders", no_argument, &additional[A_DETECT_SHARED_BORDERS], 1},
{"extract-borders", no_argument, &additional[A_EXTRACT_BORDERS], 1},
{"grid-low-zooms", no_argument, &additional[A_GRID_LOW_ZOOMS], 1},
{"Controlling clipping to tile boundaries", 0, 0, 0},

View File

@ -8,6 +8,7 @@
#define A_DEBUG_POLYGON ((int) '@')
#define A_POLYGON_DROP ((int) 'p')
#define A_DETECT_SHARED_BORDERS ((int) 'b')
#define A_EXTRACT_BORDERS ((int) 'B')
#define A_PREFER_RADIX_SORT ((int) 'R')
#define A_CALCULATE_FEATURE_DENSITY ((int) 'g')
#define A_INCREASE_GAMMA_AS_NEEDED ((int) 'G')

View File

@ -459,7 +459,7 @@ void *partial_feature_worker(void *v) {
}
bool already_marked = false;
if (additional[A_DETECT_SHARED_BORDERS] && t == VT_POLYGON) {
if ((additional[A_DETECT_SHARED_BORDERS] || additional[A_EXTRACT_BORDERS]) && t == VT_POLYGON) {
already_marked = true;
}
@ -905,6 +905,29 @@ bool find_common_edges(std::vector<partial> &partials, int z, int line_detail, d
count++;
}
if (additional[A_EXTRACT_BORDERS]) {
// Get rid of the original polygons and replace them with one big new LineString feature
for (ssize_t i = (ssize_t) partials.size() - 1; i >= 0; i--) {
if (partials[i].t == VT_POLYGON) {
partials.erase(partials.begin() + i);
}
}
partial p;
p.t = VT_LINE;
p.z = z;
p.line_detail = line_detail;
// XXX Don't know layer, sequence, index, segment, etc.
for (size_t i = 0; i < simplified_arcs.size(); i++) {
p.geoms.push_back(simplified_arcs[i]);
}
partials.push_back(p);
return true;
}
// If necessary, merge some adjacent polygons into some other polygons
struct merge_order {
@ -2003,7 +2026,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
first_time = false;
bool merge_successful = true;
if (additional[A_DETECT_SHARED_BORDERS] || (additional[A_MERGE_POLYGONS_AS_NEEDED] && merge_fraction < 1)) {
if ((additional[A_DETECT_SHARED_BORDERS] || additional[A_EXTRACT_BORDERS]) || (additional[A_MERGE_POLYGONS_AS_NEEDED] && merge_fraction < 1)) {
merge_successful = find_common_edges(partials, z, line_detail, simplification, maxzoom, merge_fraction);
}