Compare commits

..
25 changed files with 371 additions and 22922 deletions
-7
View File
@@ -1,10 +1,3 @@
# 2.41.3
* Performance optimizations to tile reading, writing, and overzooming
* Automatically vary the tile size limit by zoom level to match the intended retain-points-multiplier multiplication
* Fix decompression error when bailing out because a tile can't be made small enough
* Search harder for a feature size threshold to make the tile small enough before giving up
# 2.41.2
* Add --accumulate-attribute to tippecanoe-overzoom
+1 -3
View File
@@ -34,9 +34,7 @@ Installation
The easiest way to install tippecanoe on OSX is with [Homebrew](http://brew.sh/):
```sh
$ brew install tippecanoe
```
On Ubuntu it will usually be easiest to build from the source repository:
@@ -461,7 +459,7 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
If you use `-Bg`, it will guess a zoom level that will keep at most 50,000 features in the densest tile.
You can also specify a marker-width with `-Bg`*width* to allow fewer features in the densest tile to
compensate for the larger marker, or `-Bf`*number* to allow at most *number* features in the densest tile.
* `--retain-points-multiplier=`_multiple_: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the `-m` option to `tippecanoe-overzoom`. The start of each cluster is marked in the feature sequence by the `tippecanoe:retain_points_multiplier_first` attribute. The `--tile-size-limit` will also be extended at low zoom levels to allow for the multiplied features.
* `--retain-points-multiplier=`_multiple_: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the `-m` option to `tippecanoe-overzoom`. The start of each cluster is marked in the feature sequence by the `tippecanoe:retain_points_multiplier_first` attribute.
* `--drop-denser=`_percentage_: When dropping dots at zoom levels below the base zoom, give the specified _percentage_
preference to retaining points in sparse areas and dropping points in dense areas.
* `--limit-base-zoom-to-maximum-zoom` or `-Pb`: Limit the guessed base zoom not to exceed the maxzoom, even if this would put more than the requested number of features in a base zoom tile.
+4 -4
View File
@@ -1,12 +1,12 @@
#include <string>
#include <unordered_map>
#include <map>
#include "attribute.hpp"
#include "errors.hpp"
#include "serial.hpp"
#include "jsonpull/jsonpull.h"
#include "milo/dtoa_milo.h"
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, std::string name, std::string type) {
void set_attribute_accum(std::map<std::string, attribute_op> &attribute_accum, std::string name, std::string type) {
attribute_op t;
if (type == "sum") {
@@ -31,7 +31,7 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
attribute_accum.insert(std::pair<std::string, attribute_op>(name, t));
}
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv) {
void set_attribute_accum(std::map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv) {
if (*arg == '{') {
json_pull *jp = json_begin_string(arg);
json_object *o = json_read_tree(jp);
@@ -79,7 +79,7 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
set_attribute_accum(attribute_accum, name, type);
}
void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::unordered_map<std::string, accum_state> &attribute_accum_state) {
void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::map<std::string, accum_state> &attribute_accum_state) {
for (size_t i = 0; i < full_keys.size(); i++) {
if (key == full_keys[i]) {
switch (op) {
+4 -4
View File
@@ -2,7 +2,7 @@
#define ATTRIBUTE_HPP
#include <vector>
#include <unordered_map>
#include <map>
enum attribute_op {
op_sum,
@@ -21,8 +21,8 @@ struct accum_state {
struct serial_val;
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, std::string name, std::string type);
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv);
void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::unordered_map<std::string, accum_state> &attribute_accum_state);
void set_attribute_accum(std::map<std::string, attribute_op> &attribute_accum, std::string name, std::string type);
void set_attribute_accum(std::map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv);
void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::map<std::string, accum_state> &attribute_accum_state);
#endif
+41 -61
View File
@@ -755,10 +755,10 @@ static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<d
return out;
}
std::string overzoom(const std::string &s, int oz, int ox, int oy, int nz, int nx, int ny,
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum) {
bool demultiply, json_object *filter, bool preserve_input_order, std::map<std::string, attribute_op> const &attribute_accum) {
mvt_tile tile;
try {
@@ -785,7 +785,7 @@ struct tile_feature {
size_t seq = 0;
};
static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer, std::set<std::string> const &keep, std::unordered_map<std::string, attribute_op> const &attribute_accum) {
static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer, std::set<std::string> const &keep, std::map<std::string, attribute_op> const &attribute_accum) {
// Add geometry to output feature
mvt_feature outfeature;
@@ -810,22 +810,13 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
// attributes from the other features of the
// multiplier cluster accumulated onto them
std::unordered_map<std::string, accum_state> attribute_accum_state;
std::map<std::string, accum_state> attribute_accum_state;
std::vector<std::string> full_keys;
std::vector<serial_val> full_values;
for (size_t i = 0; i + 1 < features[0].tags.size(); i += 2) {
auto f = attribute_accum.find(features[0].layer->keys[features[0].tags[i]]);
if (f != attribute_accum.end()) {
// this attribute has an accumulator, so convert it
full_keys.push_back(features[0].layer->keys[features[0].tags[i]]);
full_values.push_back(mvt_value_to_serial_val(features[0].layer->values[features[0].tags[i + 1]]));
} else {
// otherwise just tag it directly onto the output feature
if (keep.size() == 0 || keep.find(features[0].layer->keys[features[0].tags[i]]) != keep.end()) {
outlayer.tag(outfeature, features[0].layer->keys[features[0].tags[i]], features[0].layer->values[features[0].tags[i + 1]]);
}
}
full_keys.push_back(features[0].layer->keys[features[0].tags[i]]);
full_values.push_back(mvt_value_to_serial_val(features[0].layer->values[features[0].tags[i + 1]]));
}
// accumulate whatever attributes are specified to be accumulated
@@ -860,7 +851,7 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
}
}
outlayer.features.push_back(std::move(outfeature));
outlayer.features.push_back(outfeature);
}
}
@@ -870,10 +861,10 @@ static struct preservecmp {
}
} preservecmp;
std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int nx, int ny,
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map<std::string, attribute_op> const &attribute_accum) {
bool demultiply, json_object *filter, bool preserve_input_order, std::map<std::string, attribute_op> const &attribute_accum) {
mvt_tile outtile;
for (auto const &layer : tile.layers) {
@@ -890,14 +881,11 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
std::vector<tile_feature> pending_tile_features;
static const std::string retain_points_multiplier_first = "tippecanoe:retain_points_multiplier_first";
static const std::string retain_points_multiplier_sequence = "tippecanoe:retain_points_multiplier_sequence";
for (auto feature : layer.features) {
bool flush_multiplier_cluster = false;
if (demultiply) {
for (ssize_t i = feature.tags.size() - 2; i >= 0; i -= 2) {
if (layer.keys[feature.tags[i]] == retain_points_multiplier_first) {
if (layer.keys[feature.tags[i]] == "tippecanoe:retain_points_multiplier_first") {
mvt_value v = layer.values[feature.tags[i + 1]];
if (v.type == mvt_bool && v.numeric_value.bool_value) {
flush_multiplier_cluster = true;
@@ -905,9 +893,9 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
}
}
if (layer.keys[feature.tags[i]] == retain_points_multiplier_sequence) {
if (layer.keys[feature.tags[i]] == "tippecanoe:retain_points_multiplier_sequence") {
mvt_value v = layer.values[feature.tags[i + 1]];
feature.seq = mvt_value_to_long_long(v);
feature.seq = atoll(mvt_value_to_serial_val(v).s.c_str());
feature.tags.erase(feature.tags.begin() + i, feature.tags.begin() + i + 2);
}
}
@@ -923,7 +911,7 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
}
std::set<std::string> exclude_attributes;
if (filter != NULL && !evaluate(feature, layer, filter, exclude_attributes, nz)) {
if (!evaluate(feature, layer, filter, exclude_attributes, nz)) {
continue;
}
@@ -934,7 +922,6 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
long long tilesize = 1LL << (32 - oz); // source tile size in world coordinates
draw ring_closure(0, 0, 0);
bool sametile = (nz == oz && nx == ox && ny == oy && outlayer.extent >= layer.extent);
for (auto const &g : feature.geometry) {
if (g.op == mvt_closepath) {
@@ -960,59 +947,52 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
g.y -= ny * outtilesize;
}
if (!sametile) {
// Clip to output tile
// Clip to output tile
long long xmin = LLONG_MAX;
long long ymin = LLONG_MAX;
long long xmax = LLONG_MIN;
long long ymax = LLONG_MIN;
long long xmin = LLONG_MAX;
long long ymin = LLONG_MAX;
long long xmax = LLONG_MIN;
long long ymax = LLONG_MIN;
for (auto const &g : geom) {
xmin = std::min(xmin, g.x);
ymin = std::min(ymin, g.y);
xmax = std::max(xmax, g.x);
ymax = std::max(ymax, g.y);
}
for (auto const &g : geom) {
xmin = std::min(xmin, g.x);
ymin = std::min(ymin, g.y);
xmax = std::max(xmax, g.x);
ymax = std::max(ymax, g.y);
}
long long b = outtilesize * buffer / 256;
if (xmax < -b || ymax < -b || xmin > outtilesize + b || ymin > outtilesize + b) {
continue;
}
long long b = outtilesize * buffer / 256;
if (xmax < -b || ymax < -b || xmin > outtilesize + b || ymin > outtilesize + b) {
continue;
}
if (t == VT_LINE) {
geom = clip_lines(geom, nz, buffer);
} else if (t == VT_POLYGON) {
drawvec dv;
geom = simple_clip_poly(geom, nz, buffer, dv, false);
} else if (t == VT_POINT) {
geom = clip_point(geom, nz, buffer);
}
if (t == VT_LINE) {
geom = clip_lines(geom, nz, buffer);
} else if (t == VT_POLYGON) {
drawvec dv;
geom = simple_clip_poly(geom, nz, buffer, dv, false);
} else if (t == VT_POINT) {
geom = clip_point(geom, nz, buffer);
}
// Scale to output tile extent
to_tile_scale(geom, nz, det);
if (!sametile) {
// Clean geometries
geom = remove_noop(geom, t, 0);
if (t == VT_POLYGON) {
geom = clean_or_clip_poly(geom, 0, 0, false, false);
}
}
// Clean geometries
geom = remove_noop(geom, t, 0);
if (t == VT_POLYGON) {
geom = clean_or_clip_poly(geom, 0, 0, false, false);
geom = close_poly(geom);
}
tile_feature tf;
tf.geom = std::move(geom);
tf.geom = geom;
tf.t = t;
tf.has_id = feature.has_id;
tf.id = feature.id;
tf.tags = std::move(feature.tags);
tf.tags = feature.tags;
tf.layer = &layer;
tf.seq = feature.seq;
@@ -1029,7 +1009,7 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
}
if (outlayer.features.size() > 0) {
outtile.layers.push_back(std::move(outlayer));
outtile.layers.push_back(outlayer);
}
}
+1 -1
View File
@@ -277,7 +277,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
struct stat st;
std::vector<zxy> tiles;
char *pmtiles_map = NULL;
char *pmtiles_map;
std::vector<pmtiles::entry_zxy> entries;
bool is_pmtiles = false;
+104 -160
View File
@@ -1,40 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <functional>
#include <map>
#include "mvt.hpp"
#include "evaluator.hpp"
#include "errors.hpp"
#include "milo/dtoa_milo.h"
static std::string mvt_value_to_string(mvt_value const &one, bool &fail) {
switch (one.type) {
case mvt_string:
return one.get_string_value();
case mvt_float:
static std::string mvt_value_to_string(mvt_value one, bool &fail) {
if (one.type == mvt_string) {
return one.string_value;
} else if (one.type == mvt_float) {
return milo::dtoa_milo(one.numeric_value.float_value);
case mvt_double:
} else if (one.type == mvt_double) {
return milo::dtoa_milo(one.numeric_value.double_value);
case mvt_int:
} else if (one.type == mvt_int) {
return std::to_string(one.numeric_value.int_value);
case mvt_uint:
} else if (one.type == mvt_uint) {
return std::to_string(one.numeric_value.uint_value);
case mvt_sint:
} else if (one.type == mvt_sint) {
return std::to_string(one.numeric_value.sint_value);
case mvt_bool:
} else if (one.type == mvt_bool) {
return one.numeric_value.bool_value ? "true" : "false";
case mvt_null:
} else if (one.type == mvt_null) {
fail = true; // null op string => null
return "";
case mvt_no_such_key:
default:
} else {
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
}
int compare_fsl(mvt_value const &one, json_object *two, bool &fail) {
int compare_fsl(mvt_value one, json_object *two, bool &fail) {
// In FSL expressions, the attribute value is coerced to the type
// of the JSON literal value it is being compared to.
//
@@ -50,38 +47,30 @@ int compare_fsl(mvt_value const &one, json_object *two, bool &fail) {
if (two->type == JSON_NUMBER) {
double lhs;
switch (one.type) {
case mvt_string: {
if (one.type == mvt_string) {
char *endptr = NULL;
const char *s = one.c_str();
const char *s = one.string_value.c_str();
lhs = strtod(s, &endptr);
if (endptr == s) {
fail = true; // non-numeric-string op number => null
return 0;
}
} break;
case mvt_float:
} else if (one.type == mvt_float) {
lhs = one.numeric_value.float_value;
break;
case mvt_double:
} else if (one.type == mvt_double) {
lhs = one.numeric_value.double_value;
break;
case mvt_int:
} else if (one.type == mvt_int) {
lhs = one.numeric_value.int_value;
break;
case mvt_uint:
} else if (one.type == mvt_uint) {
lhs = one.numeric_value.uint_value;
break;
case mvt_sint:
} else if (one.type == mvt_sint) {
lhs = one.numeric_value.sint_value;
break;
case mvt_bool:
} else if (one.type == mvt_bool) {
lhs = one.numeric_value.bool_value;
break;
case mvt_null:
} else if (one.type == mvt_null) {
fail = true; // null op number => null
return 0;
default:
} else {
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
@@ -104,34 +93,24 @@ int compare_fsl(mvt_value const &one, json_object *two, bool &fail) {
if (two->type == JSON_TRUE || two->type == JSON_FALSE) {
bool lhs;
switch (one.type) {
case mvt_string:
lhs = one.get_string_view().size() > 0;
break;
case mvt_float:
if (one.type == mvt_string) {
lhs = one.string_value.size() > 0;
} else if (one.type == mvt_float) {
lhs = one.numeric_value.float_value != 0;
break;
case mvt_double:
} else if (one.type == mvt_double) {
lhs = one.numeric_value.double_value != 0;
break;
case mvt_int:
} else if (one.type == mvt_int) {
lhs = one.numeric_value.int_value != 0;
break;
case mvt_uint:
} else if (one.type == mvt_uint) {
lhs = one.numeric_value.uint_value != 0;
break;
case mvt_sint:
} else if (one.type == mvt_sint) {
lhs = one.numeric_value.sint_value != 0;
break;
case mvt_bool:
} else if (one.type == mvt_bool) {
lhs = one.numeric_value.bool_value;
break;
case mvt_null:
} else if (one.type == mvt_null) {
fail = true; // null op bool => null
return 0;
case mvt_no_such_key:
default:
} else {
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
@@ -144,45 +123,34 @@ int compare_fsl(mvt_value const &one, json_object *two, bool &fail) {
exit(EXIT_IMPOSSIBLE);
}
int compare(mvt_value const &one, json_object *two, bool &fail) {
switch (one.type) {
case mvt_string:
int compare(mvt_value one, json_object *two, bool &fail) {
if (one.type == mvt_string) {
if (two->type != JSON_STRING) {
fail = true;
return false; // string vs non-string
}
return strcmp(one.c_str(), two->value.string.string);
return strcmp(one.string_value.c_str(), two->value.string.string);
}
case mvt_double:
case mvt_float:
case mvt_int:
case mvt_uint:
case mvt_sint:
if (one.type == mvt_double || one.type == mvt_float || one.type == mvt_int || one.type == mvt_uint || one.type == mvt_sint) {
if (two->type != JSON_NUMBER) {
fail = true;
return false; // number vs non-number
}
double v;
switch (one.type) {
case mvt_double:
if (one.type == mvt_double) {
v = one.numeric_value.double_value;
break;
case mvt_float:
} else if (one.type == mvt_float) {
v = one.numeric_value.float_value;
break;
case mvt_int:
} else if (one.type == mvt_int) {
v = one.numeric_value.int_value;
break;
case mvt_uint:
} else if (one.type == mvt_uint) {
v = one.numeric_value.uint_value;
break;
case mvt_sint:
} else if (one.type == mvt_sint) {
v = one.numeric_value.sint_value;
break;
case mvt_no_such_key:
default:
} else {
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
@@ -194,29 +162,25 @@ int compare(mvt_value const &one, json_object *two, bool &fail) {
} else {
return 0;
}
}
case mvt_bool:
if (one.type == mvt_bool) {
if (two->type != JSON_TRUE && two->type != JSON_FALSE) {
fail = true;
return false; // bool vs non-bool
}
{
bool b = two->type != JSON_FALSE;
return one.numeric_value.bool_value > b;
}
bool b = two->type != JSON_FALSE;
return one.numeric_value.bool_value > b;
}
case mvt_null:
if (one.type == mvt_null) {
if (two->type != JSON_NULL) {
fail = true;
return false; // null vs non-null
}
return 0; // null equals null
case mvt_no_such_key:
default:
break;
}
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
@@ -226,7 +190,7 @@ int compare(mvt_value const &one, json_object *two, bool &fail) {
// 0: false
// 1: true
// -1: incomparable (sql null), treated as false in final output
static int eval(std::function<mvt_value(std::string const &)> feature, json_object *f, std::set<std::string> &exclude_attributes) {
static int eval(std::map<std::string, mvt_value> const &feature, json_object *f, std::set<std::string> &exclude_attributes) {
if (f != NULL) {
if (f->type == JSON_TRUE) {
return 1;
@@ -272,10 +236,10 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
if (f->value.array.array[0]->type == JSON_STRING) {
// if LHS of a boolean conjunction is a string, it is an attribute reference
mvt_value ff = feature(std::string(f->value.array.array[0]->value.string.string));
if (ff.type != mvt_no_such_key) {
if (ff.type == mvt_bool) {
lhs = ff.numeric_value.bool_value;
auto ff = feature.find(std::string(f->value.array.array[0]->value.string.string));
if (ff != feature.end()) {
if (ff->second.type == mvt_bool) {
lhs = ff->second.numeric_value.bool_value;
} else {
lhs = -1; // not boolean: null
}
@@ -316,9 +280,9 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
false)) {
mvt_value lhs;
lhs.type = mvt_null; // attributes that aren't found are nulls
mvt_value ff = feature(std::string(f->value.array.array[0]->value.string.string));
if (ff.type != mvt_no_such_key) {
lhs = ff;
auto ff = feature.find(std::string(f->value.array.array[0]->value.string.string));
if (ff != feature.end()) {
lhs = ff->second;
}
if (f->value.array.array[2]->type == JSON_NULL && strcmp(f->value.array.array[1]->value.string.string, "is") == 0) {
@@ -377,8 +341,9 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
}
}
int cmp = compare_fsl(ff, f->value.array.array[2], fail);
int cmp = compare_fsl(ff->second, f->value.array.array[2], fail);
if (fail) {
printf("cast fail\n");
return -1; // null
}
@@ -422,7 +387,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
fprintf(stderr, "\"has\" key is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
return feature(std::string(f->value.array.array[1]->value.string.string)).type != mvt_no_such_key;
return feature.count(std::string(f->value.array.array[1]->value.string.string)) != 0;
}
if (strcmp(f->value.array.array[0]->value.string.string, "!has") == 0) {
@@ -430,7 +395,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
fprintf(stderr, "\"!has\" key is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
return feature(std::string(f->value.array.array[1]->value.string.string)).type == mvt_no_such_key;
return feature.count(std::string(f->value.array.array[1]->value.string.string)) == 0;
}
}
@@ -449,8 +414,8 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
exit(EXIT_FILTER);
}
mvt_value ff = feature(std::string(f->value.array.array[1]->value.string.string));
if (ff.type == mvt_no_such_key) {
auto ff = feature.find(std::string(f->value.array.array[1]->value.string.string));
if (ff == feature.end()) {
static bool warned = false;
if (!warned) {
const char *s = json_stringify(f);
@@ -465,7 +430,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
}
bool fail = false;
int cmp = compare(ff, f->value.array.array[2], fail);
int cmp = compare(ff->second, f->value.array.array[2], fail);
if (fail) {
static bool warned = false;
@@ -552,8 +517,8 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
exit(EXIT_FILTER);
}
mvt_value ff = feature(std::string(f->value.array.array[1]->value.string.string));
if (ff.type == mvt_no_such_key) {
auto ff = feature.find(std::string(f->value.array.array[1]->value.string.string));
if (ff == feature.end()) {
static bool warned = false;
if (!warned) {
const char *s = json_stringify(f);
@@ -570,7 +535,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
bool found = false;
for (size_t i = 2; i < f->value.array.length; i++) {
bool fail = false;
int cmp = compare(ff, f->value.array.array[i], fail);
int cmp = compare(ff->second, f->value.array.array[i], fail);
if (fail) {
static bool warned = false;
@@ -619,7 +584,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
exit(EXIT_FILTER);
}
bool evaluate(std::function<mvt_value(std::string const &)> feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes) {
bool evaluate(std::map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes) {
if (filter == NULL || filter->type != JSON_HASH) {
fprintf(stderr, "Error: filter is not a hash: %s\n", json_stringify(filter));
exit(EXIT_JSON);
@@ -673,69 +638,48 @@ json_object *parse_filter(const char *s) {
return filter;
}
bool evaluate(std::unordered_map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes) {
std::function<mvt_value(std::string const &)> getter = [&](std::string const &key) {
auto f = feature.find(key);
if (f != feature.end()) {
return f->second;
} else {
mvt_value v;
v.type = mvt_no_such_key;
v.numeric_value.null_value = 0;
return v;
}
};
return evaluate(getter, layer, filter, exclude_attributes);
}
bool evaluate(mvt_feature const &feat, mvt_layer const &layer, json_object *filter, std::set<std::string> &exclude_attributes, int z) {
std::function<mvt_value(std::string const &)> getter = [&](std::string const &key) {
const static std::string dollar_id = "$id";
if (key == dollar_id && feat.has_id) {
if (filter != NULL) {
std::map<std::string, mvt_value> attributes;
for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) {
std::string key = layer.keys[feat.tags[t]];
const mvt_value &val = layer.values[feat.tags[t + 1]];
attributes.insert(std::pair<std::string, mvt_value>(key, val));
}
if (feat.has_id) {
mvt_value v;
v.type = mvt_uint;
v.numeric_value.uint_value = feat.id;
return v;
}
const static std::string dollar_type = "$type";
if (key == dollar_type) {
mvt_value v;
v.type = mvt_string;
if (feat.type == mvt_point) {
const static std::string point = "Point";
v.set_string_value(point);
} else if (feat.type == mvt_linestring) {
const static std::string linestring = "LineString";
v.set_string_value(linestring);
} else if (feat.type == mvt_polygon) {
const static std::string polygon = "Polygon";
v.set_string_value(polygon);
}
return v;
}
const static std::string dollar_zoom = "$zoom";
if (key == dollar_zoom) {
mvt_value v2;
v2.type = mvt_uint;
v2.numeric_value.uint_value = z;
return v2;
}
for (size_t i = 0; i + 1 < feat.tags.size(); i += 2) {
if (layer.keys[feat.tags[i]] == key) {
return layer.values[feat.tags[i + 1]];
}
attributes.insert(std::pair<std::string, mvt_value>("$id", v));
}
mvt_value v;
v.type = mvt_no_such_key;
v.numeric_value.null_value = 0;
return v;
};
v.type = mvt_string;
return evaluate(getter, layer.name, filter, exclude_attributes);
if (feat.type == mvt_point) {
v.string_value = "Point";
} else if (feat.type == mvt_linestring) {
v.string_value = "LineString";
} else if (feat.type == mvt_polygon) {
v.string_value = "Polygon";
}
attributes.insert(std::pair<std::string, mvt_value>("$type", v));
mvt_value v2;
v2.type = mvt_uint;
v2.numeric_value.uint_value = z;
attributes.insert(std::pair<std::string, mvt_value>("$zoom", v2));
if (!evaluate(attributes, layer.name, filter, exclude_attributes)) {
return false;
}
}
return true;
}
+2 -2
View File
@@ -1,13 +1,13 @@
#ifndef EVALUATOR_HPP
#define EVALUATOR HPP
#include <unordered_map>
#include <map>
#include <string>
#include <set>
#include "jsonpull/jsonpull.h"
#include "mvt.hpp"
bool evaluate(std::unordered_map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes);
bool evaluate(std::map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes);
json_object *parse_filter(const char *s);
json_object *read_filter(const char *fname);
+4 -4
View File
@@ -100,16 +100,16 @@ void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int nx, int ny,
std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum);
std::map<std::string, attribute_op> const &attribute_accum);
std::string overzoom(const std::string &s, int oz, int ox, int oy, int nz, int nx, int ny,
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum);
std::map<std::string, attribute_op> const &attribute_accum);
#endif
+8 -8
View File
@@ -448,7 +448,7 @@ void *run_sort(void *v) {
return NULL;
}
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > *layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > *layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
long long segs[CPUS + 1];
segs[0] = 0;
segs[CPUS] = len;
@@ -649,7 +649,7 @@ struct read_parallel_arg {
unsigned *initial_y = NULL;
std::string layername = "";
bool uses_gamma = false;
std::unordered_map<std::string, int> const *attribute_types = NULL;
std::map<std::string, int> const *attribute_types = NULL;
double *dist_sum = NULL;
size_t *dist_count = NULL;
double *area_sum = NULL;
@@ -693,7 +693,7 @@ void *run_read_parallel(void *v) {
return NULL;
}
void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic<int> *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > &layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic<int> *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > &layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
// This has to kick off an intermediate thread to start the parser threads,
// so the main thread can get back to reading the next input stage while
// the intermediate thread waits for the completion of the parser threads.
@@ -1237,7 +1237,7 @@ int vertexcmp(const void *void1, const void *void2) {
return 0;
}
std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, json_object *filter, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, long long *file_bbox1, long long *file_bbox2, const char *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, bool guess_cluster_maxzoom, std::unordered_map<std::string, int> const *attribute_types, const char *pgm, std::unordered_map<std::string, attribute_op> const *attribute_accum, std::map<std::string, std::string> const &attribute_descriptions, std::string const &commandline, int minimum_maxzoom) {
std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, json_object *filter, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, long long *file_bbox1, long long *file_bbox2, const char *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, bool guess_cluster_maxzoom, std::map<std::string, int> const *attribute_types, const char *pgm, std::map<std::string, attribute_op> const *attribute_accum, std::map<std::string, std::string> const &attribute_descriptions, std::string const &commandline, int minimum_maxzoom) {
int ret = EXIT_SUCCESS;
std::vector<struct reader> readers;
@@ -2757,7 +2757,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
std::atomic<unsigned> midx(0);
std::atomic<unsigned> midy(0);
std::vector<strategy> strategies;
int written = traverse_zooms(fd, size, stringpool, &midx, &midy, maxzoom, minzoom, outdb, outdir, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, pool_off, initial_x, initial_y, simplification, maxzoom_simplification, layermaps, prefilter, postfilter, attribute_accum, filter, strategies, iz, shared_nodes_map, nodepos, basezoom, droprate);
int written = traverse_zooms(fd, size, stringpool, &midx, &midy, maxzoom, minzoom, outdb, outdir, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, pool_off, initial_x, initial_y, simplification, maxzoom_simplification, layermaps, prefilter, postfilter, attribute_accum, filter, strategies, iz, shared_nodes_map, nodepos);
if (maxzoom != written) {
if (written > minzoom) {
@@ -2845,7 +2845,7 @@ static bool has_name(struct option *long_options, int *pl) {
return false;
}
void set_attribute_type(std::unordered_map<std::string, int> &attribute_types, const char *arg) {
void set_attribute_type(std::map<std::string, int> &attribute_types, const char *arg) {
const char *s = strchr(arg, ':');
if (s == NULL) {
fprintf(stderr, "-T%s option must be in the form -Tname:type\n", arg);
@@ -3005,8 +3005,8 @@ int main(int argc, char **argv) {
bool guess_cluster_maxzoom = false;
std::set<std::string> exclude, include;
std::unordered_map<std::string, int> attribute_types;
std::unordered_map<std::string, attribute_op> attribute_accum;
std::map<std::string, int> attribute_types;
std::map<std::string, attribute_op> attribute_accum;
std::map<std::string, std::string> attribute_descriptions;
int exclude_all = 0;
int read_parallel = 0;
+1 -5
View File
@@ -29,11 +29,7 @@ significant travel corridor.
.PP
The easiest way to install tippecanoe on OSX is with Homebrew \[la]http://brew.sh/\[ra]:
.PP
.RS
.nf
$ brew install tippecanoe
.fi
.RE
.PP
On Ubuntu it will usually be easiest to build from the source repository:
.PP
@@ -578,7 +574,7 @@ If you use \fB\fC\-Bg\fR, it will guess a zoom level that will keep at most 50,0
You can also specify a marker\-width with \fB\fC\-Bg\fR\fIwidth\fP to allow fewer features in the densest tile to
compensate for the larger marker, or \fB\fC\-Bf\fR\fInumber\fP to allow at most \fInumber\fP features in the densest tile.
.IP \(bu 2
\fB\fC\-\-retain\-points\-multiplier=\fR\fImultiple\fP: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the \fB\fC\-m\fR option to \fB\fCtippecanoe\-overzoom\fR\&. The start of each cluster is marked in the feature sequence by the \fB\fCtippecanoe:retain_points_multiplier_first\fR attribute. The \fB\fC\-\-tile\-size\-limit\fR will also be extended at low zoom levels to allow for the multiplied features.
\fB\fC\-\-retain\-points\-multiplier=\fR\fImultiple\fP: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the \fB\fC\-m\fR option to \fB\fCtippecanoe\-overzoom\fR\&. The start of each cluster is marked in the feature sequence by the \fB\fCtippecanoe:retain_points_multiplier_first\fR attribute.
.IP \(bu 2
\fB\fC\-\-drop\-denser=\fR\fIpercentage\fP: When dropping dots at zoom levels below the base zoom, give the specified \fIpercentage\fP
preference to retaining points in sparse areas and dropping points in dense areas.
+66 -183
View File
@@ -110,7 +110,7 @@ int compress(std::string const &input, std::string &output, bool gz) {
return 0;
}
bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
bool mvt_tile::decode(std::string &message, bool &was_compressed) {
layers.clear();
std::string src;
@@ -127,7 +127,6 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
}
protozero::pbf_reader reader(src);
std::shared_ptr<std::string> string_pool = std::make_shared<std::string>();
while (reader.next()) {
switch (reader.tag()) {
@@ -158,12 +157,7 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
switch (value_reader.tag()) {
case 1: /* string */
value.type = mvt_string;
value.s = string_pool;
{
auto v = value_reader.get_view();
std::string_view sv(v.data(), v.size());
value.set_string_value(sv);
}
value.string_value = value_reader.get_string();
break;
case 2: /* float */
@@ -202,7 +196,7 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
}
}
layer.values.push_back(std::move(value));
layer.values.push_back(value);
break;
}
@@ -230,7 +224,6 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
case 2: /* tag */
{
auto pi = feature_reader.get_packed_uint32();
feature.tags.reserve(std::distance(pi.first, pi.second));
for (auto it = pi.first; it != pi.second; ++it) {
feature.tags.push_back(*it);
}
@@ -244,7 +237,6 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
case 4: /* geometry */
{
auto pi = feature_reader.get_packed_uint32();
geoms.reserve(std::distance(pi.first, pi.second));
for (auto it = pi.first; it != pi.second; ++it) {
geoms.push_back(*it);
}
@@ -258,7 +250,6 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
}
long long px = 0, py = 0;
feature.geometry.reserve(geoms.size()); // probably not quite right, but still plausible
for (size_t g = 0; g < geoms.size(); g++) {
uint32_t geom = geoms[g];
uint32_t op = geom & 7;
@@ -270,14 +261,14 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
py += protozero::decode_zigzag32(geoms[g + 2]);
g += 2;
feature.geometry.emplace_back(op, px, py);
feature.geometry.push_back(mvt_geometry(op, px, py));
}
} else {
feature.geometry.emplace_back(op, 0, 0);
feature.geometry.push_back(mvt_geometry(op, 0, 0));
}
}
layer.features.push_back(std::move(feature));
layer.features.push_back(feature);
break;
}
@@ -287,7 +278,14 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
}
}
layers.push_back(std::move(layer));
for (size_t i = 0; i < layer.keys.size(); i++) {
layer.key_map.insert(std::pair<std::string, size_t>(layer.keys[i], i));
}
for (size_t i = 0; i < layer.values.size(); i++) {
layer.value_map.insert(std::pair<mvt_value, size_t>(layer.values[i], i));
}
layers.push_back(layer);
break;
}
@@ -315,6 +313,7 @@ struct sorted_value {
std::string mvt_tile::encode() {
std::string data;
protozero::pbf_writer writer(data);
for (size_t i = 0; i < layers.size(); i++) {
@@ -336,40 +335,32 @@ std::string mvt_tile::encode() {
protozero::pbf_writer value_writer(value_string);
mvt_value &pbv = layers[i].values[v];
switch (pbv.type) {
case mvt_string:
value_writer.add_string(1, pbv.get_string_value());
break;
case mvt_float:
if (pbv.type == mvt_string) {
value_writer.add_string(1, pbv.string_value);
} else if (pbv.type == mvt_float) {
value_writer.add_float(2, pbv.numeric_value.float_value);
break;
case mvt_double:
} else if (pbv.type == mvt_double) {
value_writer.add_double(3, pbv.numeric_value.double_value);
break;
case mvt_int:
} else if (pbv.type == mvt_int) {
value_writer.add_int64(4, pbv.numeric_value.int_value);
break;
case mvt_uint:
} else if (pbv.type == mvt_uint) {
value_writer.add_uint64(5, pbv.numeric_value.uint_value);
break;
case mvt_sint:
} else if (pbv.type == mvt_sint) {
value_writer.add_sint64(6, pbv.numeric_value.sint_value);
break;
case mvt_bool:
} else if (pbv.type == mvt_bool) {
value_writer.add_bool(7, pbv.numeric_value.bool_value);
break;
case mvt_null:
} else if (pbv.type == mvt_null) {
fprintf(stderr, "Internal error: trying to write null attribute to tile\n");
exit(EXIT_IMPOSSIBLE);
default:
} else {
fprintf(stderr, "Internal error: trying to write undefined attribute type to tile\n");
exit(EXIT_IMPOSSIBLE);
}
sorted_value sv;
sv.val = std::move(value_string);
sv.val = value_string;
sv.orig = v;
sorted_values.push_back(std::move(sv));
sorted_values.push_back(sv);
}
std::sort(sorted_values.begin(), sorted_values.end());
@@ -465,70 +456,15 @@ bool mvt_value::operator<(const mvt_value &o) const {
return true;
}
if (type == o.type) {
switch (type) {
case mvt_string:
return get_string_view() < o.get_string_view();
case mvt_float:
return numeric_value.float_value < o.numeric_value.float_value;
case mvt_double:
return numeric_value.double_value < o.numeric_value.double_value;
case mvt_int:
return numeric_value.int_value < o.numeric_value.int_value;
case mvt_uint:
return numeric_value.uint_value < o.numeric_value.uint_value;
case mvt_sint:
return numeric_value.sint_value < o.numeric_value.sint_value;
case mvt_bool:
return numeric_value.bool_value < o.numeric_value.bool_value;
case mvt_null:
return numeric_value.null_value < o.numeric_value.null_value;
default:
fprintf(stderr, "mvt_value::operator<<: can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
}
return false;
}
bool mvt_value::operator==(const mvt_value &o) const {
if (type == o.type) {
switch (type) {
case mvt_string:
return get_string_view() == o.get_string_view();
case mvt_float:
return numeric_value.float_value == o.numeric_value.float_value;
case mvt_double:
return numeric_value.double_value == o.numeric_value.double_value;
case mvt_int:
return numeric_value.int_value == o.numeric_value.int_value;
case mvt_uint:
return numeric_value.uint_value == o.numeric_value.uint_value;
case mvt_sint:
return numeric_value.sint_value == o.numeric_value.sint_value;
case mvt_bool:
return numeric_value.bool_value == o.numeric_value.bool_value;
case mvt_null:
return numeric_value.null_value == o.numeric_value.null_value;
default:
fprintf(stderr, "mvt_value::operator==: can't happen\n");
exit(EXIT_IMPOSSIBLE);
if ((type == mvt_string && string_value < o.string_value) ||
(type == mvt_float && numeric_value.float_value < o.numeric_value.float_value) ||
(type == mvt_double && numeric_value.double_value < o.numeric_value.double_value) ||
(type == mvt_int && numeric_value.int_value < o.numeric_value.int_value) ||
(type == mvt_uint && numeric_value.uint_value < o.numeric_value.uint_value) ||
(type == mvt_sint && numeric_value.sint_value < o.numeric_value.sint_value) ||
(type == mvt_bool && numeric_value.bool_value < o.numeric_value.bool_value) ||
(type == mvt_null && numeric_value.null_value < o.numeric_value.null_value)) {
return true;
}
}
@@ -557,62 +493,47 @@ static std::string quote(std::string const &s) {
}
std::string mvt_value::toString() const {
switch (type) {
case mvt_string:
return quote(get_string_value());
case mvt_int:
if (type == mvt_string) {
return quote(string_value);
} else if (type == mvt_int) {
return std::to_string(numeric_value.int_value);
case mvt_double: {
} else if (type == mvt_double) {
double v = numeric_value.double_value;
if (v == (long long) v) {
return std::to_string((long long) v);
} else {
return milo::dtoa_milo(v);
}
}
case mvt_float: {
} else if (type == mvt_float) {
double v = numeric_value.float_value;
if (v == (long long) v) {
return std::to_string((long long) v);
} else {
return milo::dtoa_milo(v);
}
}
case mvt_sint:
} else if (type == mvt_sint) {
return std::to_string(numeric_value.sint_value);
case mvt_uint:
} else if (type == mvt_uint) {
return std::to_string(numeric_value.uint_value);
case mvt_bool:
} else if (type == mvt_bool) {
return numeric_value.bool_value ? "true" : "false";
case mvt_null:
} else if (type == mvt_null) {
return "null";
default:
} else {
return "unknown";
}
}
void mvt_layer::tag(mvt_feature &feature, std::string const &key, mvt_value const &value) {
void mvt_layer::tag(mvt_feature &feature, std::string key, mvt_value value) {
size_t ko, vo;
// initialize lazily the first time anyone tags an attribute
// to save the time of doing it in decode, which never actually matters.
// only tile writers actually need this.
if (key_map.size() == 0) {
for (size_t i = 0; i < keys.size(); i++) {
key_map.emplace(keys[i], i);
}
for (size_t i = 0; i < values.size(); i++) {
value_map.emplace(values[i], i);
}
}
std::unordered_map<std::string, size_t>::iterator ki = key_map.find(key);
std::unordered_map<mvt_value, size_t>::iterator vi = value_map.find(value);
std::map<std::string, size_t>::iterator ki = key_map.find(key);
std::map<mvt_value, size_t>::iterator vi = value_map.find(value);
if (ki == key_map.end()) {
ko = keys.size();
keys.push_back(key);
key_map.emplace(key, ko);
key_map.insert(std::pair<std::string, size_t>(key, ko));
} else {
ko = ki->second;
}
@@ -620,7 +541,7 @@ void mvt_layer::tag(mvt_feature &feature, std::string const &key, mvt_value cons
if (vi == value_map.end()) {
vo = values.size();
values.push_back(value);
value_map.emplace(value, vo);
value_map.insert(std::pair<mvt_value, size_t>(value, vo));
} else {
vo = vi->second;
}
@@ -708,8 +629,7 @@ bool is_unsigned_integer(const char *s, unsigned long long *v) {
mvt_value stringified_to_mvt_value(int type, const char *s) {
mvt_value tv;
switch (type) {
case mvt_double: {
if (type == mvt_double) {
long long v;
unsigned long long uv;
if (is_unsigned_integer(s, &uv)) {
@@ -748,18 +668,15 @@ mvt_value stringified_to_mvt_value(int type, const char *s) {
}
}
}
} break;
case mvt_bool:
} else if (type == mvt_bool) {
tv.type = mvt_bool;
tv.numeric_value.bool_value = (s[0] == 't');
break;
case mvt_null:
} else if (type == mvt_null) {
tv.type = mvt_null;
tv.numeric_value.null_value = 0;
break;
default:
} else {
tv.type = mvt_string;
tv.set_string_value(s);
tv.string_value = s;
}
return tv;
@@ -773,68 +690,34 @@ mvt_value stringified_to_mvt_value(int type, const char *s) {
serial_val mvt_value_to_serial_val(mvt_value const &v) {
serial_val sv;
switch (v.type) {
case mvt_string:
if (v.type == mvt_string) {
sv.type = mvt_string;
sv.s = v.get_string_value();
break;
case mvt_float:
sv.s = v.string_value;
} else if (v.type == mvt_float) {
sv.type = mvt_double;
sv.s = milo::dtoa_milo(v.numeric_value.float_value);
break;
case mvt_double:
} else if (v.type == mvt_double) {
sv.type = mvt_double;
sv.s = milo::dtoa_milo(v.numeric_value.double_value);
break;
case mvt_int:
} else if (v.type == mvt_int) {
sv.type = mvt_double;
sv.s = std::to_string(v.numeric_value.int_value);
break;
case mvt_uint:
} else if (v.type == mvt_uint) {
sv.type = mvt_double;
sv.s = std::to_string(v.numeric_value.uint_value);
break;
case mvt_sint:
} else if (v.type == mvt_sint) {
sv.type = mvt_double;
sv.s = std::to_string(v.numeric_value.sint_value);
break;
case mvt_bool:
} else if (v.type == mvt_bool) {
sv.type = mvt_bool;
sv.s = v.numeric_value.bool_value ? "true" : "false";
break;
case mvt_null:
} else if (v.type == mvt_null) {
sv.type = mvt_null;
sv.s = "null";
break;
default:
} else {
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
return sv;
}
// This extracts an integer value from an mvt_value
long long mvt_value_to_long_long(mvt_value const &v) {
switch (v.type) {
case mvt_string:
return atoll(v.c_str());
case mvt_float:
return v.numeric_value.float_value;
case mvt_double:
return v.numeric_value.double_value;
case mvt_int:
return v.numeric_value.int_value;
case mvt_uint:
return v.numeric_value.uint_value;
case mvt_sint:
return v.numeric_value.sint_value;
case mvt_bool:
return v.numeric_value.bool_value;
case mvt_null:
return 0;
default:
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}
+7 -79
View File
@@ -3,14 +3,9 @@
#include <sqlite3.h>
#include <string>
#include <string_view>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>
#include <optional>
#include <memory>
#include "errors.hpp"
struct mvt_value;
struct mvt_layer;
@@ -71,14 +66,11 @@ enum mvt_value_type {
mvt_sint,
mvt_bool,
mvt_null,
mvt_no_such_key,
};
struct mvt_value {
mvt_value_type type;
std::shared_ptr<std::string> s;
std::string string_value;
union {
float float_value;
double double_value;
@@ -87,81 +79,18 @@ struct mvt_value {
long long sint_value;
bool bool_value;
int null_value;
struct {
size_t off;
size_t len;
} string_value;
} numeric_value;
std::string get_string_value() const {
return std::string(*s, numeric_value.string_value.off, numeric_value.string_value.len);
}
std::string_view get_string_view() const {
return std::string_view(s->c_str() + numeric_value.string_value.off, numeric_value.string_value.len);
}
const char *c_str() const {
return s->c_str() + numeric_value.string_value.off;
}
void set_string_value(const std::string_view &val) {
if (s == nullptr) {
s = std::make_shared<std::string>();
}
type = mvt_string;
numeric_value.string_value.off = s->size();
numeric_value.string_value.len = val.size();
s->append(val);
s->push_back('\0');
}
bool operator<(const mvt_value &o) const;
bool operator==(const mvt_value &o) const;
std::string toString() const;
mvt_value() {
this->type = mvt_double;
this->string_value = "";
this->numeric_value.double_value = 0;
}
};
template <>
struct std::hash<mvt_value> {
std::size_t operator()(const mvt_value &k) const {
switch (k.type) {
case mvt_string:
return std::hash<std::string_view>()(k.get_string_view());
case mvt_float:
return std::hash<float>()(k.numeric_value.float_value);
case mvt_double:
return std::hash<double>()(k.numeric_value.double_value);
case mvt_int:
return std::hash<long long>()(k.numeric_value.int_value);
case mvt_uint:
return std::hash<unsigned long long>()(k.numeric_value.uint_value);
case mvt_sint:
return std::hash<long long>()(k.numeric_value.sint_value);
case mvt_bool:
return std::hash<bool>()(k.numeric_value.bool_value);
case mvt_null:
return std::hash<int>()(k.numeric_value.null_value);
default:
fprintf(stderr, "mvt_value hash can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
}
};
struct mvt_layer {
int version = 0;
std::string name = "";
@@ -171,18 +100,18 @@ struct mvt_layer {
long long extent = 0;
// Add a key-value pair to a feature, using this layer's constant pool
void tag(mvt_feature &feature, std::string const &key, mvt_value const &value);
void tag(mvt_feature &feature, std::string key, mvt_value value);
// For tracking the key-value constants already used in this layer
std::unordered_map<std::string, size_t> key_map{};
std::unordered_map<mvt_value, size_t> value_map{};
std::map<std::string, size_t> key_map{};
std::map<mvt_value, size_t> value_map{};
};
struct mvt_tile {
std::vector<mvt_layer> layers{};
std::string encode();
bool decode(const std::string &message, bool &was_compressed);
bool decode(std::string &message, bool &was_compressed);
};
bool is_compressed(std::string const &data);
@@ -191,7 +120,6 @@ int compress(std::string const &input, std::string &output, bool gz);
int dezig(unsigned n);
mvt_value stringified_to_mvt_value(int type, const char *s);
long long mvt_value_to_long_long(mvt_value const &v);
bool is_integer(const char *s, long long *v);
bool is_unsigned_integer(const char *s, unsigned long long *v);
+1 -1
View File
@@ -17,7 +17,7 @@ int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256;
bool demultiply = false;
std::string filter;
bool preserve_input_order = false;
std::unordered_map<std::string, attribute_op> attribute_accum;
std::map<std::string, attribute_op> attribute_accum;
std::set<std::string> keep;
+3 -3
View File
@@ -166,11 +166,11 @@ struct entryv3 {
}
};
struct entryv3_cmp {
struct {
bool operator()(entryv3 a, entryv3 b) const {
return a.tile_id < b.tile_id;
}
};
} entryv3_cmp;
struct entry_zxy {
uint8_t z;
@@ -388,7 +388,7 @@ inline uint64_t zxy_to_tileid(uint8_t z, uint32_t x, uint32_t y) {
if (z > 31) {
throw std::overflow_error("tile zoom exceeds 64-bit limit");
}
if (x > (1U << z) - 1 || y > (1U << z) - 1) {
if (x > (1 << z) - 1 || y > (1 << z) - 1) {
throw std::overflow_error("tile x/y outside zoom level bounds");
}
uint64_t acc = 0;
+1 -1
View File
@@ -263,7 +263,7 @@ void mbtiles_map_image_to_pmtiles(char *fname, metadata m, bool tile_compression
// finalize PMTiles archive.
{
std::sort(entries.begin(), entries.end(), pmtiles::entryv3_cmp());
std::sort(entries.begin(), entries.end(), pmtiles::entryv3_cmp);
std::string root_bytes;
std::string leaves_bytes;
+1 -1
View File
@@ -878,7 +878,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
return 1;
}
void coerce_value(std::string const &key, int &vt, std::string &val, std::unordered_map<std::string, int> const *attribute_types) {
void coerce_value(std::string const &key, int &vt, std::string &val, std::map<std::string, int> const *attribute_types) {
auto a = (*attribute_types).find(key);
if (a != attribute_types->end()) {
if (a->second == mvt_string) {
+2 -2
View File
@@ -175,7 +175,7 @@ struct serialization_state {
std::map<std::string, layermap_entry> *layermap = NULL;
std::unordered_map<std::string, int> const *attribute_types = NULL;
std::map<std::string, int> const *attribute_types = NULL;
std::set<std::string> *exclude = NULL;
std::set<std::string> *include = NULL;
int exclude_all = 0;
@@ -228,6 +228,6 @@ struct node {
int nodecmp(const void *void1, const void *void2);
int serialize_feature(struct serialization_state *sst, serial_feature &sf);
void coerce_value(std::string const &key, int &vt, std::string &val, std::unordered_map<std::string, int> const *attribute_types);
void coerce_value(std::string const &key, int &vt, std::string &val, std::map<std::string, int> const *attribute_types);
#endif
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -140,7 +140,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
mvt_feature feat = layer.features[f];
std::set<std::string> exclude_attributes;
if (filter != NULL && !evaluate(feat, layer, filter, exclude_attributes, z)) {
if (!evaluate(feat, layer, filter, exclude_attributes, z)) {
continue;
}
@@ -197,7 +197,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
mvt_value outval;
if (attr_type == mvt_string) {
outval.type = mvt_string;
outval.set_string_value(joinval);
outval.string_value = joinval;
} else {
outval.type = mvt_double;
outval.numeric_value.double_value = atof(joinval.c_str());
@@ -688,8 +688,8 @@ struct tileset_reader {
perror("pthread_mutex_lock");
}
std::function<mvt_tile(zxy)> getter = [&](zxy tileno) {
return get_tile(tileno);
std::function<mvt_tile(zxy)> getter = [&](zxy tile) {
return get_tile(tile);
};
mvt_tile source = cache.get(parent_tile, getter);
@@ -699,7 +699,7 @@ struct tileset_reader {
}
if (source.layers.size() != 0) {
std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>());
std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::map<std::string, attribute_op>());
return ret;
}
+32 -88
View File
@@ -8,7 +8,6 @@
#include <stack>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <stdio.h>
@@ -217,7 +216,7 @@ void decode_meta(std::vector<long long> const &metakeys, std::vector<long long>
mvt_value key = retrieve_string(metakeys[i], stringpool, NULL);
mvt_value value = retrieve_string(metavals[i], stringpool, &otype);
layer.tag(feature, key.get_string_value(), value);
layer.tag(feature, key.string_value, value);
}
}
@@ -227,9 +226,9 @@ static int metacmp(const std::vector<long long> &keys1, const std::vector<long l
mvt_value key1 = retrieve_string(keys1[i], stringpool1, NULL);
mvt_value key2 = retrieve_string(keys2[i], stringpool2, NULL);
if (key1.get_string_view() < key2.get_string_view()) {
if (key1.string_value < key2.string_value) {
return -1;
} else if (key1.get_string_view() > key2.get_string_view()) {
} else if (key1.string_value > key2.string_value) {
return 1;
}
@@ -259,7 +258,7 @@ static int metacmp(const std::vector<long long> &keys1, const std::vector<long l
}
}
static mvt_value find_attribute_value(const struct coalesce *c1, std::string const &key) {
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;
@@ -273,7 +272,7 @@ static mvt_value find_attribute_value(const struct coalesce *c1, std::string con
for (size_t i = 0; i < keys1.size(); i++) {
mvt_value key1 = retrieve_string(keys1[i], stringpool1, NULL);
if (key == key1.get_string_value()) {
if (key == key1.string_value) {
return retrieve_string(values1[i], stringpool1, NULL);
}
}
@@ -361,7 +360,7 @@ std::vector<std::vector<coalesce>> assemble_multiplier_clusters(std::vector<coal
}
}
if (is_cluster_start || clusters.size() == 0) {
if (is_cluster_start) {
clusters.push_back(std::vector<coalesce>());
}
@@ -538,7 +537,7 @@ struct partial {
long long extent = 0;
long long clustered = 0;
std::set<std::string> need_tilestats;
std::unordered_map<std::string, accum_state> attribute_accum_state;
std::map<std::string, accum_state> attribute_accum_state;
};
struct partial_arg {
@@ -1358,45 +1357,9 @@ unsigned long long choose_mingap(std::vector<unsigned long long> const &indices,
return top;
}
// This function is called to choose the new "extent" threshold to try when a tile exceeds the
// tile size limit or feature limit and `--drop-smallest-as-needed` or `--coalesce-smallest-as-needed`
// has been set.
//
// The "extents" are the areas of the polygon features or the pseudo-areas associated with the
// linestring or point features that were examined for inclusion in the most recent
// iteration of this tile. (This includes features that were dropped because they were below
// the previous size threshold, but not features that were dropped by fractional point dropping).
// The extents are placed in order by the sort, from smallest to largest.
//
// The `fraction` is the proportion of these features that tippecanoe thinks should be retained to
// to make the tile small enough now. Because the extents are sorted from smallest to largest,
// the smallest extent threshold that will retain that fraction of features is found `fraction`
// distance from the end of the list, or at element `(1 - fraction) * (size() - 1)`.
//
// However, the extent found there may be the same extent that was used in the last iteration!
//
// (The "existing_extent" is the extent threshold that selected these features in the recent
// iteration. It is 0 the first time a tile is attempted, and gets higher on successive iterations
// as tippecanoe restricts the features to be kept to larger and larger features.)
//
// The features that are kept are those with a size >= the existing_extent, so if there are a large
// number of features with identical small areas, the new guess may not exclude enough features
// to actually choose a new threshold larger than the previous threshold.
//
// To address this, the array index `ix` of the new chosen extent is incremented toward the end
// of the list, until the possibilities run out or something higher than the old extent is found.
// If there are no higher extents available, the tile has already been reduced as much as possible
// and tippecanoe will exit with an error.
long long choose_minextent(std::vector<long long> &extents, double f, long long existing_extent) {
long long choose_minextent(std::vector<long long> &extents, double f) {
std::sort(extents.begin(), extents.end());
size_t ix = (extents.size() - 1) * (1 - f);
while (ix + 1 < extents.size() && extents[ix] == existing_extent) {
ix++;
}
return extents[ix];
return extents[(extents.size() - 1) * (1 - f)];
}
struct write_tile_args {
@@ -1419,8 +1382,6 @@ struct write_tile_args {
std::atomic<unsigned> *midy = NULL;
int maxzoom = 0;
int minzoom = 0;
int basezoom = 0;
double droprate = 0;
int full_detail = 0;
int low_detail = 0;
double simplification = 0;
@@ -1443,7 +1404,7 @@ struct write_tile_args {
size_t feature_count_out = 0;
const char *prefilter = NULL;
const char *postfilter = NULL;
std::unordered_map<std::string, attribute_op> const *attribute_accum = NULL;
std::map<std::string, attribute_op> const *attribute_accum = NULL;
bool still_dropping = false;
int wrote_zoom = 0;
size_t tiling_seg = 0;
@@ -1632,7 +1593,7 @@ serial_feature next_feature(decompressor *geoms, std::atomic<long long> *geompos
}
if (filter != NULL) {
std::unordered_map<std::string, mvt_value> attributes;
std::map<std::string, mvt_value> attributes;
std::string layername = (*layer_unmaps)[sf.segment][sf.layer];
std::set<std::string> exclude_attributes;
@@ -1666,11 +1627,11 @@ serial_feature next_feature(decompressor *geoms, std::atomic<long long> *geompos
v.type = mvt_string;
if (sf.t == mvt_point) {
v.set_string_value("Point");
v.string_value = "Point";
} else if (sf.t == mvt_linestring) {
v.set_string_value("LineString");
v.string_value = "LineString";
} else if (sf.t == mvt_polygon) {
v.set_string_value("Polygon");
v.string_value = "Polygon";
}
attributes.insert(std::pair<std::string, mvt_value>("$type", v));
@@ -1885,7 +1846,7 @@ void promote_attribute(std::string const &key, partial &p, char *stringpool, lon
}
}
void preserve_attributes(std::unordered_map<std::string, attribute_op> const *attribute_accum, serial_feature &sf, char *stringpool, long long *pool_off, partial &p) {
void preserve_attributes(std::map<std::string, attribute_op> const *attribute_accum, serial_feature &sf, char *stringpool, long long *pool_off, partial &p) {
for (size_t i = 0; i < sf.keys.size(); i++) {
std::string key = stringpool + pool_off[sf.segment] + sf.keys[i] + 1;
@@ -1998,20 +1959,6 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
double mingap_fraction = 1;
double minextent_fraction = 1;
// allow larger tile sizes at low zooms when the retain-points-multiplier
// is intended to allow more points through. scale back down toward a
// tile size multiple of 1 at basezoom and beyond
size_t scaled_max_tile_size = max_tile_size;
double regular_retention = 1 / exp(log(arg->droprate) * (arg->basezoom - z));
if (regular_retention > 1) {
regular_retention = 1;
}
double multiplier_retention = 1 / exp(log(arg->droprate) * (arg->basezoom - z)) * retain_points_multiplier;
if (multiplier_retention > 1) {
multiplier_retention = 1;
}
scaled_max_tile_size *= multiplier_retention / regular_retention;
static std::atomic<double> oprogress(0);
long long og = *geompos_in;
@@ -2343,7 +2290,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
if (sf.geometry.size() > 0) {
if (partials.size() > scaled_max_tile_size) {
if (partials.size() > max_tile_size) {
// Even being maximally conservative, each feature is still going to be
// at least one byte in the output tile, so this can't possibly work.
skipped++;
@@ -2869,7 +2816,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
continue;
} else if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
minextent_fraction = minextent_fraction * max_tile_features / totalsize * 0.75;
long long m = choose_minextent(extents, minextent_fraction, minextent);
long long m = choose_minextent(extents, minextent_fraction);
if (m != minextent) {
minextent = m;
if (minextent > arg->minextent_out) {
@@ -2915,7 +2862,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
compressed = pbf;
}
if (compressed.size() > scaled_max_tile_size && !prevent[P_KILOBYTE_LIMIT]) {
if (compressed.size() > max_tile_size && !prevent[P_KILOBYTE_LIMIT]) {
// Estimate how big it really should have been compressed
// from how many features were kept vs skipped for already being
// over the threshold
@@ -2928,9 +2875,9 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
if (!quiet) {
if (skipped > 0) {
fprintf(stderr, "tile %d/%u/%u size is %lld (probably really %lld) with detail %d, >%zu \n", z, tx, ty, (long long) compressed.size(), (long long) (compressed.size() * kept_adjust), line_detail, scaled_max_tile_size);
fprintf(stderr, "tile %d/%u/%u size is %lld (probably really %lld) with detail %d, >%zu \n", z, tx, ty, (long long) compressed.size(), (long long) (compressed.size() * kept_adjust), line_detail, max_tile_size);
} else {
fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >%zu \n", z, tx, ty, (long long) compressed.size(), line_detail, scaled_max_tile_size);
fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >%zu \n", z, tx, ty, (long long) compressed.size(), line_detail, max_tile_size);
}
}
@@ -2951,7 +2898,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
line_detail++; // to keep it the same when the loop decrements it
} else if (mingap < ULONG_MAX && (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED])) {
mingap_fraction = mingap_fraction * scaled_max_tile_size / (kept_adjust * compressed.size()) * 0.90;
mingap_fraction = mingap_fraction * max_tile_size / (kept_adjust * compressed.size()) * 0.90;
unsigned long long mg = choose_mingap(indices, mingap_fraction);
if (mg <= mingap) {
double nmg = (mingap + 1) * 1.5;
@@ -2976,8 +2923,8 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
line_detail++;
} else if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
minextent_fraction = minextent_fraction * scaled_max_tile_size / (kept_adjust * compressed.size()) * 0.75;
long long m = choose_minextent(extents, minextent_fraction, minextent);
minextent_fraction = minextent_fraction * max_tile_size / (kept_adjust * compressed.size()) * 0.75;
long long m = choose_minextent(extents, minextent_fraction);
if (m != minextent) {
minextent = m;
if (minextent > arg->minextent_out) {
@@ -2994,7 +2941,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// The 95% is a guess to avoid too many retries
// and probably actually varies based on how much duplicated metadata there is
fraction = fraction * scaled_max_tile_size / (kept_adjust * compressed.size()) * 0.95;
fraction = fraction * max_tile_size / (kept_adjust * compressed.size()) * 0.95;
if (!quiet) {
fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100);
}
@@ -3044,7 +2991,6 @@ struct task {
void *run_thread(void *vargs) {
write_tile_args *arg = (write_tile_args *) vargs;
struct task *task;
int *err_or_null = NULL;
for (task = arg->tasks; task != NULL; task = task->next) {
int j = task->fileno;
@@ -3108,6 +3054,12 @@ void *run_thread(void *vargs) {
long long len = write_tile(&dc, &geompos, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->outdb, arg->outdir, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->tiling_seg, arg->pass, arg->mingap, arg->minextent, arg->fraction, arg->prefilter, arg->postfilter, arg->filter, arg, arg->strategy, arg->compressed, arg->shared_nodes_map, arg->nodepos);
if (len < 0) {
int *err = &arg->err;
*err = z - 1;
return err;
}
if (pthread_mutex_lock(&var_lock) != 0) {
perror("pthread_mutex_lock");
exit(EXIT_PTHREAD);
@@ -3137,12 +3089,6 @@ void *run_thread(void *vargs) {
perror("pthread_mutex_unlock");
exit(EXIT_PTHREAD);
}
if (len < 0) {
err_or_null = &arg->err;
*err_or_null = z - 1;
break;
}
}
if (arg->pass == 1) {
@@ -3168,10 +3114,10 @@ void *run_thread(void *vargs) {
}
arg->running--;
return err_or_null;
return NULL;
}
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos, int basezoom, double droprate) {
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *prefilter, const char *postfilter, std::map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos) {
last_progress = 0;
// The existing layermaps are one table per input thread.
@@ -3354,8 +3300,6 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<
args[thread].midy = midy; // locked with var_lock
args[thread].maxzoom = maxzoom;
args[thread].minzoom = minzoom;
args[thread].basezoom = basezoom;
args[thread].droprate = droprate;
args[thread].full_detail = full_detail;
args[thread].low_detail = low_detail;
args[thread].most = &most; // locked with var_lock
+1 -1
View File
@@ -55,7 +55,7 @@ struct strategy {
// long long write_tile(char **geom, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, FILE **geomfile, int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers, std::atomic<strategy> *strategy);
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry> > &layermap, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos, int basezoom, double droprate);
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry> > &layermap, const char *prefilter, const char *postfilter, std::map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos);
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap);
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.41.3"
#define VERSION "v2.41.2"
#endif
+10 -19
View File
@@ -336,40 +336,31 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
const char *key = layer.keys[feat.tags[t]].c_str();
mvt_value const &val = layer.values[feat.tags[t + 1]];
switch (val.type) {
case mvt_string:
if (val.type == mvt_string) {
state.json_write_string(key);
state.json_write_string(val.get_string_value());
break;
case mvt_int:
state.json_write_string(val.string_value);
} else if (val.type == mvt_int) {
state.json_write_string(key);
state.json_write_signed(val.numeric_value.int_value);
break;
case mvt_double:
} else if (val.type == mvt_double) {
state.json_write_string(key);
state.json_write_number(val.numeric_value.double_value);
break;
case mvt_float:
} else if (val.type == mvt_float) {
state.json_write_string(key);
state.json_write_number(val.numeric_value.float_value);
break;
case mvt_sint:
} else if (val.type == mvt_sint) {
state.json_write_string(key);
state.json_write_signed(val.numeric_value.sint_value);
break;
case mvt_uint:
} else if (val.type == mvt_uint) {
state.json_write_string(key);
state.json_write_unsigned(val.numeric_value.uint_value);
break;
case mvt_bool:
} else if (val.type == mvt_bool) {
state.json_write_string(key);
state.json_write_bool(val.numeric_value.bool_value);
break;
case mvt_null:
} else if (val.type == mvt_null) {
state.json_write_string(key);
state.json_write_null();
break;
default:
} else {
fprintf(stderr, "Internal error: property with unknown type\n");
exit(EXIT_IMPOSSIBLE);
}