mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Some work toward letting features have sub-geometries
This commit is contained in:
@@ -155,7 +155,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
|
|||||||
}
|
}
|
||||||
sqlite3_free(sql);
|
sqlite3_free(sql);
|
||||||
|
|
||||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('version', %d);", 1);
|
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('version', %d);", 2);
|
||||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||||
fprintf(stderr, "set version : %s\n", err);
|
fprintf(stderr, "set version : %s\n", err);
|
||||||
if (!forcetable) {
|
if (!forcetable) {
|
||||||
|
|||||||
@@ -468,7 +468,7 @@ void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct partial {
|
struct partial {
|
||||||
drawvec geom;
|
std::vector<drawvec> geoms;
|
||||||
long long layer;
|
long long layer;
|
||||||
char *meta;
|
char *meta;
|
||||||
signed char t;
|
signed char t;
|
||||||
@@ -495,8 +495,8 @@ void *partial_feature_worker(void *v) {
|
|||||||
std::vector<struct partial> *partials = a->partials;
|
std::vector<struct partial> *partials = a->partials;
|
||||||
|
|
||||||
for (unsigned i = a->task; i < (*partials).size(); i += a->tasks) {
|
for (unsigned i = a->task; i < (*partials).size(); i += a->tasks) {
|
||||||
drawvec geom = (*partials)[i].geom;
|
drawvec geom = (*partials)[i].geoms[0]; // XXX assumption of a single geometry at the beginning
|
||||||
(*partials)[i].geom.clear(); // avoid keeping two copies in memory
|
(*partials)[i].geoms.clear(); // avoid keeping two copies in memory
|
||||||
signed char t = (*partials)[i].t;
|
signed char t = (*partials)[i].t;
|
||||||
int z = (*partials)[i].z;
|
int z = (*partials)[i].z;
|
||||||
int line_detail = (*partials)[i].line_detail;
|
int line_detail = (*partials)[i].line_detail;
|
||||||
@@ -526,17 +526,28 @@ void *partial_feature_worker(void *v) {
|
|||||||
|
|
||||||
to_tile_scale(geom, z, line_detail);
|
to_tile_scale(geom, z, line_detail);
|
||||||
|
|
||||||
|
std::vector<drawvec> geoms;
|
||||||
|
geoms.push_back(geom);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (t == VT_POLYGON) {
|
||||||
|
geoms = chop_geometry(geoms); // XXX
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (t == VT_POLYGON) {
|
if (t == VT_POLYGON) {
|
||||||
// Scaling may have made the polygon degenerate.
|
// Scaling may have made the polygon degenerate.
|
||||||
// Give Clipper a chance to try to fix it.
|
// Give Clipper a chance to try to fix it.
|
||||||
geom = clean_or_clip_poly(geom, 0, 0, 0, false);
|
for (unsigned i = 0; i < geoms.size(); i++) {
|
||||||
geom = close_poly(geom);
|
geoms[i] = clean_or_clip_poly(geoms[i], 0, 0, 0, false);
|
||||||
|
geoms[i] = close_poly(geoms[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Worth skipping this if not coalescing anyway?
|
// Worth skipping this if not coalescing anyway?
|
||||||
if (geom.size() > 0) {
|
if (geoms.size() > 0 && geoms[0].size() > 0) {
|
||||||
(*partials)[i].index = encode(geom[0].x, geom[0].y);
|
(*partials)[i].index = encode(geoms[0][0].x, geoms[0][0].y);
|
||||||
(*partials)[i].index2 = encode(geom[geom.size() - 1].x, geom[geom.size() - 1].y);
|
(*partials)[i].index2 = encode(geoms[0][geoms[0].size() - 1].x, geoms[0][geoms[0].size() - 1].y);
|
||||||
|
|
||||||
// Anything numbered below the start of the line
|
// Anything numbered below the start of the line
|
||||||
// can't possibly be the next feature.
|
// can't possibly be the next feature.
|
||||||
@@ -549,7 +560,7 @@ void *partial_feature_worker(void *v) {
|
|||||||
(*partials)[i].index2 = 0;
|
(*partials)[i].index2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*partials)[i].geom = geom;
|
(*partials)[i].geoms = geoms;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -801,7 +812,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
|||||||
|
|
||||||
if (geom.size() > 0) {
|
if (geom.size() > 0) {
|
||||||
partial p;
|
partial p;
|
||||||
p.geom = geom;
|
p.geoms.push_back(geom);
|
||||||
p.layer = layer;
|
p.layer = layer;
|
||||||
p.meta = meta;
|
p.meta = meta;
|
||||||
p.t = t;
|
p.t = t;
|
||||||
@@ -851,21 +862,24 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
|||||||
|
|
||||||
// This is serial because decode_meta() unifies duplicates
|
// This is serial because decode_meta() unifies duplicates
|
||||||
for (unsigned i = 0; i < partials.size(); i++) {
|
for (unsigned i = 0; i < partials.size(); i++) {
|
||||||
drawvec geom = partials[i].geom;
|
std::vector<drawvec> geoms = partials[i].geoms;
|
||||||
partials[i].geom.clear(); // avoid keeping two copies in memory
|
partials[i].geoms.clear(); // avoid keeping two copies in memory
|
||||||
long long layer = partials[i].layer;
|
long long layer = partials[i].layer;
|
||||||
char *meta = partials[i].meta;
|
|
||||||
signed char t = partials[i].t;
|
signed char t = partials[i].t;
|
||||||
int segment = partials[i].segment;
|
int segment = partials[i].segment;
|
||||||
long long original_seq = partials[i].original_seq;
|
long long original_seq = partials[i].original_seq;
|
||||||
|
|
||||||
if (t == VT_POINT || to_feature(geom, NULL)) {
|
// A complex polygon may have been split up into multiple geometries.
|
||||||
|
// Break them out into multiple features if necessary.
|
||||||
|
for (unsigned j = 0; j < geoms.size(); j++) {
|
||||||
|
if (t == VT_POINT || to_feature(geoms[j], NULL)) {
|
||||||
struct coalesce c;
|
struct coalesce c;
|
||||||
|
char *meta = partials[i].meta;
|
||||||
|
|
||||||
c.type = t;
|
c.type = t;
|
||||||
c.index = partials[i].index;
|
c.index = partials[i].index;
|
||||||
c.index2 = partials[i].index2;
|
c.index2 = partials[i].index2;
|
||||||
c.geom = geom;
|
c.geom = geoms[j];
|
||||||
c.metasrc = meta;
|
c.metasrc = meta;
|
||||||
c.coalesced = false;
|
c.coalesced = false;
|
||||||
c.original_seq = original_seq;
|
c.original_seq = original_seq;
|
||||||
@@ -874,6 +888,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
|||||||
features[layer].push_back(c);
|
features[layer].push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < child_shards; j++) {
|
for (j = 0; j < child_shards; j++) {
|
||||||
@@ -899,7 +914,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 20000 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
|
if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 700 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
|
||||||
unsigned z;
|
unsigned z;
|
||||||
for (z = 0; z < features[j][x].geom.size(); z++) {
|
for (z = 0; z < features[j][x].geom.size(); z++) {
|
||||||
out[y].geom.push_back(features[j][x].geom[z]);
|
out[y].geom.push_back(features[j][x].geom[z]);
|
||||||
@@ -909,6 +924,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
|
|||||||
out.push_back(features[j][x]);
|
out.push_back(features[j][x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
features[j] = out;
|
features[j] = out;
|
||||||
|
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user