mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
The GeoJSON-producing part of prefiltering
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "options.hpp"
|
||||
#include "main.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "write_json.hpp"
|
||||
|
||||
#define CMD_BITS 3
|
||||
|
||||
@@ -142,7 +143,7 @@ mvt_value retrieve_string(long long off, char *stringpool, int *otype) {
|
||||
return stringified_to_mvt_value(type, s);
|
||||
}
|
||||
|
||||
void decode_meta(int m, std::vector<long long> &metakeys, std::vector<long long> &metavals, char *stringpool, mvt_layer &layer, mvt_feature &feature) {
|
||||
void decode_meta(int m, std::vector<long long> const &metakeys, std::vector<long long> const &metavals, char *stringpool, mvt_layer &layer, mvt_feature &feature) {
|
||||
int i;
|
||||
for (i = 0; i < m; i++) {
|
||||
int otype;
|
||||
@@ -1167,10 +1168,11 @@ struct write_tile_args {
|
||||
long long minextent_out;
|
||||
double fraction;
|
||||
double fraction_out;
|
||||
const char *filter;
|
||||
const char *prefilter;
|
||||
const char *postfilter;
|
||||
};
|
||||
|
||||
long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *stringpool, int z, unsigned tx, unsigned ty, int detail, int min_detail, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, volatile long long *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, volatile int *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t pass, size_t passes, unsigned long long mingap, long long minextent, double fraction, const char *filter, write_tile_args *arg) {
|
||||
long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *stringpool, int z, unsigned tx, unsigned ty, int detail, int min_detail, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, volatile long long *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, volatile int *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t pass, size_t passes, unsigned long long mingap, long long minextent, double fraction, const char *prefilter, const char *postfilter, write_tile_args *arg) {
|
||||
int line_detail;
|
||||
double merge_fraction = 1;
|
||||
double mingap_fraction = 1;
|
||||
@@ -1422,6 +1424,34 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefilter != NULL) {
|
||||
mvt_layer tmp_layer;
|
||||
tmp_layer.extent = 1LL << 32;
|
||||
tmp_layer.name = (*layer_unmaps)[segment][layer];
|
||||
|
||||
mvt_feature tmp_feature;
|
||||
tmp_feature.type = t;
|
||||
tmp_feature.geometry = to_feature(geom);
|
||||
tmp_feature.id = id;
|
||||
tmp_feature.has_id = id;
|
||||
|
||||
// Offset from tile coordinates back to world coordinates
|
||||
unsigned sx = 0, sy = 0;
|
||||
if (z != 0) {
|
||||
sx = tx << (32 - z);
|
||||
sy = ty << (32 - z);
|
||||
}
|
||||
for (size_t i = 0; i < tmp_feature.geometry.size(); i++) {
|
||||
tmp_feature.geometry[i].x += sx;
|
||||
tmp_feature.geometry[i].y += sy;
|
||||
}
|
||||
|
||||
decode_meta(m, metakeys, metavals, stringpool + pool_off[segment], tmp_layer, tmp_feature);
|
||||
tmp_layer.features.push_back(tmp_feature);
|
||||
|
||||
layer_to_geojson(stdout, tmp_layer, 0, 0, 0, false, true);
|
||||
}
|
||||
|
||||
if (gamma > 0) {
|
||||
if (manage_gap(index, &previndex, scale, gamma, &gap)) {
|
||||
continue;
|
||||
@@ -1691,8 +1721,8 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
|
||||
layer.features.push_back(feature);
|
||||
}
|
||||
|
||||
if (filter != NULL) {
|
||||
layer = filter_layer(filter, layer, z, tx, ty);
|
||||
if (postfilter != NULL) {
|
||||
layer = filter_layer(postfilter, layer, z, tx, ty);
|
||||
}
|
||||
|
||||
if (layer.features.size() > 0) {
|
||||
@@ -1921,7 +1951,7 @@ void *run_thread(void *vargs) {
|
||||
|
||||
// fprintf(stderr, "%d/%u/%u\n", z, x, y);
|
||||
|
||||
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->basezoom, arg->outdb, arg->droprate, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg->filter, arg);
|
||||
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->basezoom, arg->outdb, arg->droprate, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg->prefilter, arg->postfilter, arg);
|
||||
|
||||
if (len < 0) {
|
||||
int *err = &arg->err;
|
||||
@@ -1986,7 +2016,7 @@ void *run_thread(void *vargs) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *filter) {
|
||||
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *prefilter, const char *postfilter) {
|
||||
// Table to map segment and layer number back to layer name
|
||||
std::vector<std::vector<std::string>> layer_unmaps;
|
||||
for (size_t seg = 0; seg < layermaps.size(); seg++) {
|
||||
@@ -2153,7 +2183,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
|
||||
args[thread].initial_y = initial_y;
|
||||
args[thread].layermaps = &layermaps;
|
||||
args[thread].layer_unmaps = &layer_unmaps;
|
||||
args[thread].filter = filter;
|
||||
args[thread].prefilter = prefilter;
|
||||
args[thread].postfilter = postfilter;
|
||||
|
||||
args[thread].tasks = dispatches[thread].tasks;
|
||||
args[thread].running = &running;
|
||||
|
||||
Reference in New Issue
Block a user