mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-25 18:01:19 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87546222e0 | ||
|
|
ea0f04d4d1 | ||
|
|
9adb032d9e | ||
|
|
594d038ef1 | ||
|
|
68388f6c32 |
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -419,7 +417,6 @@ be reduced to the maximum that can be used with the specified _maxzoom_.
|
||||
* `-pe` or `--empty-csv-columns-are-null`: Treat empty CSV columns as nulls rather than as empty strings.
|
||||
* `-aI` or `--convert-stringified-ids-to-numbers`: If a feature ID is the string representation of a number, convert it to a plain number to use as the feature ID.
|
||||
* `--use-attribute-for-id=`*name*: Use the attribute with the specified *name* as if it were specified as the feature ID. (If this attribute is a stringified number, you must also use `-aI` to convert it to a number.)
|
||||
* `-pN` or `--single-precision`: Write double-precision numeric attribute values to tiles as single-precision to reduce tile size.
|
||||
|
||||
### Filtering features by attributes
|
||||
|
||||
@@ -461,9 +458,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.
|
||||
* `--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.
|
||||
* `--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.
|
||||
* `--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.
|
||||
* `-al` or `--drop-lines`: Let "dot" dropping at lower zooms apply to lines too
|
||||
* `-ap` or `--drop-polygons`: Let "dot" dropping at lower zooms apply to polygons too
|
||||
@@ -480,14 +475,8 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
|
||||
* `-aN` or `--coalesce-smallest-as-needed`: Dynamically combine the smallest features (physically smallest: the shortest lines or the smallest polygons or the densest points) from each zoom level into other nearby features to keep large tiles under the 500K size limit. This option will probably not help very much with LineStrings. It is mostly intended for polygons, to maintain the full original area covered by polygons while still reducing the feature count somehow. The attributes of the small polygons are *not* preserved into the combined features (except through `--accumulate-attribute`), only their geometry. Furthermore, the polygons to which nested polygons are coalesced may not necessarily be the immediately enclosing features.
|
||||
* `-aD` or `--coalesce-densest-as-needed`: Dynamically combine the densest features from each zoom level into other nearby features to keep large tiles under the 500K size limit. (Again, mostly useful for polygons.)
|
||||
* `-aS` or `--coalesce-fraction-as-needed`: Dynamically combine a fraction of features from each zoom level into other nearby features to keep large tiles under the 500K size limit. (Again, mostly useful for polygons.)
|
||||
* `-pd` or `--force-feature-limit`: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. (This is like `-ad` but applies to each tile individually, not to the entire zoom level.) You probably don't want to use this.
|
||||
* `-aC` or `--cluster-densest-as-needed`: If a tile is too large, try to reduce its size by increasing the minimum spacing between features, and leaving one placeholder feature from each group. The remaining feature will be given a `"clustered": true` attribute to indicate that it represents a cluster, a `"point_count"` attribute to indicate the number of features that were clustered into it, and a `"sqrt_point_count"` attribute to indicate the relative width of a feature to represent the cluster. If the features being clustered are points, the representative feature will be located at the average of the original points' locations; otherwise, one of the original features will be left as the representative.
|
||||
|
||||
### Dropping tightly overlapping features
|
||||
|
||||
* `-g` _gamma_ or `--gamma=_gamma`_: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number.
|
||||
* `-aG` or `--increase-gamma-as-needed`: If a tile is too large, try to reduce it to under 500K by increasing the `-g` gamma. The discovered gamma applies to the entire zoom level. You probably want to use `--drop-densest-as-needed` instead.
|
||||
|
||||
### Line and polygon simplification
|
||||
|
||||
* `-S` _scale_ or `--simplification=`_scale_: Multiply the tolerance for line and polygon simplification by _scale_. The standard tolerance tries to keep
|
||||
@@ -578,7 +567,7 @@ as a series of newline-delimited GeoJSON objects on the standard input, and `tip
|
||||
set of GeoJSON features from the filter's standard output.
|
||||
|
||||
The prefilter receives the features at the highest available resolution, before line simplification,
|
||||
polygon topology repair, gamma calculation, dynamic feature dropping, or other internal processing.
|
||||
polygon topology repair, dynamic feature dropping, or other internal processing.
|
||||
The postfilter receives the features at tile resolution, after simplification, cleaning, and dropping.
|
||||
|
||||
The layer name is provided as part of the `tippecanoe` element of the feature and must be passed through
|
||||
@@ -673,10 +662,6 @@ a different zoom specified with `-B` if you have precise but sparse data).
|
||||
I don't know why 2.5 is the appropriate number, but the densities of many different
|
||||
data sets fall off at about this same rate. You can use -r to specify a different rate.
|
||||
|
||||
You can use the gamma option to thin out especially dense clusters of points.
|
||||
For any area where dots are closer than one pixel together (at whatever zoom level),
|
||||
a gamma of 3, for example, will reduce these clusters to the cube root of their original density.
|
||||
|
||||
For line features, it drops any features that are too small to draw at all.
|
||||
This still leaves the lower zooms too dark (and too dense for the 500K tile limit,
|
||||
in some places), so I need to figure out an equitable way to throw features away.
|
||||
|
||||
+4
-4
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -90,7 +90,6 @@ long justx = -1, justy = -1;
|
||||
std::string attribute_for_id = "";
|
||||
size_t limit_tile_feature_count = 0;
|
||||
size_t limit_tile_feature_count_at_maxzoom = 0;
|
||||
unsigned int drop_denser = 0;
|
||||
std::map<std::string, serial_val> set_attributes;
|
||||
unsigned long long preserve_point_density_threshold = 0;
|
||||
long long extend_zooms_max = 0;
|
||||
@@ -296,12 +295,12 @@ struct drop_densest {
|
||||
}
|
||||
};
|
||||
|
||||
int calc_feature_minzoom(struct index *ix, struct drop_state *ds, int maxzoom, double gamma) {
|
||||
int calc_feature_minzoom(struct index *ix, struct drop_state *ds, int maxzoom) {
|
||||
int feature_minzoom = 0;
|
||||
|
||||
if (gamma >= 0 && (ix->t == VT_POINT ||
|
||||
(additional[A_LINE_DROP] && ix->t == VT_LINE) ||
|
||||
(additional[A_POLYGON_DROP] && ix->t == VT_POLYGON))) {
|
||||
if ((ix->t == VT_POINT ||
|
||||
(additional[A_LINE_DROP] && ix->t == VT_LINE) ||
|
||||
(additional[A_POLYGON_DROP] && ix->t == VT_POLYGON))) {
|
||||
for (ssize_t i = maxzoom; i >= 0; i--) {
|
||||
ds[i].seq++;
|
||||
}
|
||||
@@ -342,14 +341,12 @@ int calc_feature_minzoom(struct index *ix, struct drop_state *ds, int maxzoom, d
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX manage_gap
|
||||
}
|
||||
|
||||
return feature_minzoom;
|
||||
}
|
||||
|
||||
static void merge(struct mergelist *merges, size_t nmerges, unsigned char *map, FILE *indexfile, int bytes, char *geom_map, FILE *geom_out, std::atomic<long long> *geompos, long long *progress, long long *progress_max, long long *progress_reported, int maxzoom, double gamma, struct drop_state *ds) {
|
||||
static void merge(struct mergelist *merges, size_t nmerges, unsigned char *map, FILE *indexfile, int bytes, char *geom_map, FILE *geom_out, std::atomic<long long> *geompos, long long *progress, long long *progress_max, long long *progress_reported, int maxzoom, struct drop_state *ds) {
|
||||
struct mergelist *head = NULL;
|
||||
|
||||
for (size_t i = 0; i < nmerges; i++) {
|
||||
@@ -368,7 +365,7 @@ static void merge(struct mergelist *merges, size_t nmerges, unsigned char *map,
|
||||
// and is writing one byte less and then adding the byte for the minzoom.
|
||||
|
||||
fwrite_check(geom_map + ix.start, 1, ix.end - ix.start - 1, geom_out, geompos, "merge geometry");
|
||||
int feature_minzoom = calc_feature_minzoom(&ix, ds, maxzoom, gamma);
|
||||
int feature_minzoom = calc_feature_minzoom(&ix, ds, maxzoom);
|
||||
serialize_byte(geom_out, feature_minzoom, geompos, "merge geometry");
|
||||
|
||||
// Count this as an 75%-accomplishment, since we already 25%-counted it
|
||||
@@ -448,7 +445,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, 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;
|
||||
@@ -501,7 +498,6 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const
|
||||
sst[i].dist_count = &(dist_counts[i]);
|
||||
sst[i].want_dist = want_dist;
|
||||
sst[i].maxzoom = maxzoom;
|
||||
sst[i].uses_gamma = uses_gamma;
|
||||
sst[i].filters = filters;
|
||||
sst[i].layermap = &(*layermaps)[i];
|
||||
sst[i].exclude = exclude;
|
||||
@@ -648,8 +644,7 @@ struct read_parallel_arg {
|
||||
unsigned *initial_x = NULL;
|
||||
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;
|
||||
@@ -676,7 +671,7 @@ void *run_read_parallel(void *v) {
|
||||
}
|
||||
madvise(map, rpa->len, MADV_RANDOM); // sequential, but from several pointers at once
|
||||
|
||||
do_read_parallel(map, rpa->len, rpa->offset, rpa->reading, rpa->readers, rpa->progress_seq, rpa->exclude, rpa->include, rpa->exclude_all, rpa->basezoom, rpa->source, rpa->layermaps, rpa->initialized, rpa->initial_x, rpa->initial_y, rpa->maxzoom, rpa->layername, rpa->uses_gamma, rpa->attribute_types, rpa->separator, rpa->dist_sum, rpa->dist_count, rpa->area_sum, rpa->want_dist, rpa->filters);
|
||||
do_read_parallel(map, rpa->len, rpa->offset, rpa->reading, rpa->readers, rpa->progress_seq, rpa->exclude, rpa->include, rpa->exclude_all, rpa->basezoom, rpa->source, rpa->layermaps, rpa->initialized, rpa->initial_x, rpa->initial_y, rpa->maxzoom, rpa->layername, rpa->attribute_types, rpa->separator, rpa->dist_sum, rpa->dist_count, rpa->area_sum, rpa->want_dist, rpa->filters);
|
||||
|
||||
madvise(map, rpa->len, MADV_DONTNEED);
|
||||
if (munmap(map, rpa->len) != 0) {
|
||||
@@ -693,7 +688,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, 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.
|
||||
@@ -727,7 +722,6 @@ void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::ato
|
||||
rpa->initial_y = initial_y;
|
||||
rpa->maxzoom = maxzoom;
|
||||
rpa->layername = layername;
|
||||
rpa->uses_gamma = uses_gamma;
|
||||
rpa->attribute_types = attribute_types;
|
||||
rpa->dist_sum = dist_sum;
|
||||
rpa->dist_count = dist_count;
|
||||
@@ -742,7 +736,7 @@ void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::ato
|
||||
parser_created = true;
|
||||
}
|
||||
|
||||
void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int splits, long long mem, const char *tmpdir, long long *availfiles, FILE *geomfile, FILE *indexfile, std::atomic<long long> *geompos_out, long long *progress, long long *progress_max, long long *progress_reported, int maxzoom, int basezoom, double droprate, double gamma, struct drop_state *ds) {
|
||||
void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int splits, long long mem, const char *tmpdir, long long *availfiles, FILE *geomfile, FILE *indexfile, std::atomic<long long> *geompos_out, long long *progress, long long *progress_max, long long *progress_reported, int maxzoom, int basezoom, double droprate, struct drop_state *ds) {
|
||||
// Arranged as bits to facilitate subdividing again if a subdivided file is still huge
|
||||
int splitbits = log(splits) / log(2);
|
||||
splits = 1 << splitbits;
|
||||
@@ -961,7 +955,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
|
||||
madvise(geommap, geomst.st_size, MADV_RANDOM);
|
||||
madvise(geommap, geomst.st_size, MADV_WILLNEED);
|
||||
|
||||
merge(merges, nmerges, (unsigned char *) indexmap, indexfile, bytes, geommap, geomfile, geompos_out, progress, progress_max, progress_reported, maxzoom, gamma, ds);
|
||||
merge(merges, nmerges, (unsigned char *) indexmap, indexfile, bytes, geommap, geomfile, geompos_out, progress, progress_max, progress_reported, maxzoom, ds);
|
||||
|
||||
madvise(indexmap, indexst.st_size, MADV_DONTNEED);
|
||||
if (munmap(indexmap, indexst.st_size) < 0) {
|
||||
@@ -995,7 +989,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
|
||||
long long pos = *geompos_out;
|
||||
|
||||
fwrite_check(geommap + ix.start, ix.end - ix.start, 1, geomfile, geompos_out, "geom");
|
||||
int feature_minzoom = calc_feature_minzoom(&ix, ds, maxzoom, gamma);
|
||||
int feature_minzoom = calc_feature_minzoom(&ix, ds, maxzoom);
|
||||
serialize_byte(geomfile, feature_minzoom, geompos_out, "merge geometry");
|
||||
|
||||
// Count this as an 75%-accomplishment, since we already 25%-counted it
|
||||
@@ -1030,7 +1024,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
|
||||
// counter backward but will be an honest estimate of the work remaining.
|
||||
*progress_max += geomst.st_size / 4;
|
||||
|
||||
radix1(&geomfds[i], &indexfds[i], 1, prefix + splitbits, *availfiles / 4, mem, tmpdir, availfiles, geomfile, indexfile, geompos_out, progress, progress_max, progress_reported, maxzoom, basezoom, droprate, gamma, ds);
|
||||
radix1(&geomfds[i], &indexfds[i], 1, prefix + splitbits, *availfiles / 4, mem, tmpdir, availfiles, geomfile, indexfile, geompos_out, progress, progress_max, progress_reported, maxzoom, basezoom, droprate, ds);
|
||||
already_closed = 1;
|
||||
}
|
||||
}
|
||||
@@ -1090,7 +1084,7 @@ static size_t calc_memsize() {
|
||||
return mem;
|
||||
}
|
||||
|
||||
void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FILE *indexfile, const char *tmpdir, std::atomic<long long> *geompos, int maxzoom, int basezoom, double droprate, double gamma) {
|
||||
void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FILE *indexfile, const char *tmpdir, std::atomic<long long> *geompos, int maxzoom, int basezoom, double droprate) {
|
||||
// Run through the index and geometry for each reader,
|
||||
// splitting the contents out by index into as many
|
||||
// sub-files as we can write to simultaneously.
|
||||
@@ -1140,7 +1134,7 @@ void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FI
|
||||
|
||||
long long progress = 0, progress_max = geom_total, progress_reported = -1;
|
||||
long long availfiles_before = availfiles;
|
||||
radix1(geomfds, indexfds, nreaders, 0, splits, mem, tmpdir, &availfiles, geomfile, indexfile, geompos, &progress, &progress_max, &progress_reported, maxzoom, basezoom, droprate, gamma, ds);
|
||||
radix1(geomfds, indexfds, nreaders, 0, splits, mem, tmpdir, &availfiles, geomfile, indexfile, geompos, &progress, &progress_max, &progress_reported, maxzoom, basezoom, droprate, ds);
|
||||
|
||||
if (availfiles - 2 * nreaders != availfiles_before) {
|
||||
fprintf(stderr, "Internal error: miscounted available file descriptors: %lld vs %lld\n", availfiles - 2 * nreaders, availfiles);
|
||||
@@ -1237,7 +1231,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, int read_parallel, int forcetable, const char *attribution, 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;
|
||||
@@ -1514,7 +1508,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
sst[i].want_dist = guess_maxzoom;
|
||||
sst[i].maxzoom = maxzoom;
|
||||
sst[i].filters = prefilter != NULL || postfilter != NULL;
|
||||
sst[i].uses_gamma = uses_gamma;
|
||||
sst[i].layermap = &layermaps[i];
|
||||
sst[i].exclude = exclude;
|
||||
sst[i].include = include;
|
||||
@@ -1587,7 +1580,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
sst[i].want_dist = guess_maxzoom;
|
||||
sst[i].maxzoom = maxzoom;
|
||||
sst[i].filters = prefilter != NULL || postfilter != NULL;
|
||||
sst[i].uses_gamma = uses_gamma;
|
||||
sst[i].layermap = &layermaps[i];
|
||||
sst[i].exclude = exclude;
|
||||
sst[i].include = include;
|
||||
@@ -1649,7 +1641,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
sst[i].want_dist = guess_maxzoom;
|
||||
sst[i].maxzoom = maxzoom;
|
||||
sst[i].filters = prefilter != NULL || postfilter != NULL;
|
||||
sst[i].uses_gamma = uses_gamma;
|
||||
sst[i].layermap = &layermaps[i];
|
||||
sst[i].exclude = exclude;
|
||||
sst[i].include = include;
|
||||
@@ -1707,7 +1698,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
}
|
||||
|
||||
if (map != NULL && map != MAP_FAILED && read_parallel_this) {
|
||||
do_read_parallel(map, st.st_size - off, overall_offset, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, &layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, uses_gamma, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
do_read_parallel(map, st.st_size - off, overall_offset, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, &layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
overall_offset += st.st_size - off;
|
||||
checkdisk(&readers);
|
||||
|
||||
@@ -1786,7 +1777,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
}
|
||||
|
||||
fflush(readfp);
|
||||
start_parsing(readfd, streamfpopen(readfp), initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, gamma != 0, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
start_parsing(readfd, streamfpopen(readfp), initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
|
||||
initial_offset += ahead;
|
||||
overall_offset += ahead;
|
||||
@@ -1823,7 +1814,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
fflush(readfp);
|
||||
|
||||
if (ahead > 0) {
|
||||
start_parsing(readfd, streamfpopen(readfp), initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, gamma != 0, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
start_parsing(readfd, streamfpopen(readfp), initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), &readers, &progress_seq, exclude, include, exclude_all, basezoom, layer, layermaps, initialized, initial_x, initial_y, maxzoom, sources[layer].layer, attribute_types, read_parallel_this, &dist_sum, &dist_count, &area_sum, guess_maxzoom, prefilter != NULL || postfilter != NULL);
|
||||
|
||||
if (parser_created) {
|
||||
if (pthread_join(parallel_parser, NULL) != 0) {
|
||||
@@ -1857,7 +1848,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
sst.want_dist = guess_maxzoom;
|
||||
sst.maxzoom = maxzoom;
|
||||
sst.filters = prefilter != NULL || postfilter != NULL;
|
||||
sst.uses_gamma = uses_gamma;
|
||||
sst.layermap = &layermaps[0];
|
||||
sst.exclude = exclude;
|
||||
sst.include = include;
|
||||
@@ -2219,7 +2209,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
serialize_uint(geomfile, ix, &geompos, fname);
|
||||
serialize_uint(geomfile, iy, &geompos, fname);
|
||||
|
||||
radix(readers, CPUS, geomfile, indexfile, tmpdir, &geompos, maxzoom, basezoom, droprate, gamma);
|
||||
radix(readers, CPUS, geomfile, indexfile, tmpdir, &geompos, maxzoom, basezoom, droprate);
|
||||
|
||||
/* end of tile */
|
||||
serialize_ulong_long(geomfile, 0, &geompos, fname); // EOF
|
||||
@@ -2521,8 +2511,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
yyy = yy >> (32 - z);
|
||||
}
|
||||
|
||||
double scale = (double) (1LL << (64 - 2 * (z + 8)));
|
||||
|
||||
if (tile[z].x != xxx || tile[z].y != yyy) {
|
||||
if (tile[z].count > max[z].count) {
|
||||
max[z] = tile[z];
|
||||
@@ -2537,11 +2525,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
}
|
||||
|
||||
tile[z].fullcount++;
|
||||
|
||||
if (manage_gap(map[ip].ix, &tile[z].previndex, scale, gamma, &tile[z].gap)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tile[z].count++;
|
||||
}
|
||||
}
|
||||
@@ -2578,9 +2561,6 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
|
||||
if (obasezoom < 0 && basezoom > maxzoom) {
|
||||
fprintf(stderr, "Couldn't find a suitable base zoom. Working from the other direction.\n");
|
||||
if (gamma == 0) {
|
||||
fprintf(stderr, "You might want to try -g1 to limit near-duplicates.\n");
|
||||
}
|
||||
|
||||
if (droprate < 0) {
|
||||
if (maxzoom == 0) {
|
||||
@@ -2622,44 +2602,10 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
}
|
||||
}
|
||||
|
||||
if (gamma > 0) {
|
||||
int effective = 0;
|
||||
|
||||
for (z = 0; z < maxzoom; z++) {
|
||||
if (max[z].count < max[z].fullcount) {
|
||||
effective = z + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (effective == 0) {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "With gamma, effective base zoom is 0, so no effective drop rate\n");
|
||||
}
|
||||
} else {
|
||||
double interval_0 = exp(log(droprate) * (basezoom - 0));
|
||||
double interval_eff = exp(log(droprate) * (basezoom - effective));
|
||||
if (effective > basezoom) {
|
||||
interval_eff = 1;
|
||||
}
|
||||
|
||||
double scaled_0 = max[0].count / interval_0;
|
||||
double scaled_eff = max[effective].count / interval_eff;
|
||||
|
||||
double rate_at_0 = scaled_0 / max[0].fullcount;
|
||||
double rate_at_eff = scaled_eff / max[effective].fullcount;
|
||||
|
||||
double eff_drop = exp(log(rate_at_eff / rate_at_0) / (effective - 0));
|
||||
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "With gamma, effective base zoom of %d, effective drop rate of %f\n", effective, eff_drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fix_dropping = true;
|
||||
}
|
||||
|
||||
if (fix_dropping || drop_denser > 0) {
|
||||
if (fix_dropping) {
|
||||
// Fix up the minzooms for features, now that we really know the base zoom
|
||||
// and drop rate.
|
||||
|
||||
@@ -2679,48 +2625,12 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
struct drop_state ds[maxzoom + 1];
|
||||
prep_drop_states(ds, maxzoom, basezoom, droprate);
|
||||
|
||||
if (drop_denser > 0) {
|
||||
std::vector<drop_densest> ddv;
|
||||
unsigned long long previndex = 0;
|
||||
|
||||
for (long long ip = 0; ip < indices; ip++) {
|
||||
if (map[ip].t == VT_POINT ||
|
||||
(additional[A_LINE_DROP] && map[ip].t == VT_LINE) ||
|
||||
(additional[A_POLYGON_DROP] && map[ip].t == VT_POLYGON)) {
|
||||
if (map[ip].ix % 100 < drop_denser) {
|
||||
drop_densest dd;
|
||||
dd.gap = map[ip].ix - previndex;
|
||||
dd.seq = ip;
|
||||
ddv.push_back(dd);
|
||||
|
||||
previndex = map[ip].ix;
|
||||
} else {
|
||||
int feature_minzoom = calc_feature_minzoom(&map[ip], ds, maxzoom, gamma);
|
||||
geom[map[ip].end - 1] = feature_minzoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(ddv.begin(), ddv.end());
|
||||
|
||||
size_t i = 0;
|
||||
for (int z = 0; z <= basezoom; z++) {
|
||||
double keep_fraction = 1.0 / std::exp(std::log(droprate) * (basezoom - z));
|
||||
size_t keep_count = ddv.size() * keep_fraction;
|
||||
|
||||
for (; i < keep_count && i < ddv.size(); i++) {
|
||||
geom[map[ddv[i].seq].end - 1] = z;
|
||||
}
|
||||
}
|
||||
for (; i < ddv.size(); i++) {
|
||||
geom[map[ddv[i].seq].end - 1] = basezoom;
|
||||
}
|
||||
} else {
|
||||
{
|
||||
for (long long ip = 0; ip < indices; ip++) {
|
||||
if (ip > 0 && map[ip].start != map[ip - 1].end) {
|
||||
fprintf(stderr, "Mismatched index at %lld: %lld vs %lld\n", ip, map[ip].start, map[ip].end);
|
||||
}
|
||||
int feature_minzoom = calc_feature_minzoom(&map[ip], ds, maxzoom, gamma);
|
||||
int feature_minzoom = calc_feature_minzoom(&map[ip], ds, maxzoom);
|
||||
geom[map[ip].end - 1] = feature_minzoom;
|
||||
}
|
||||
}
|
||||
@@ -2757,7 +2667,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, 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 +2755,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);
|
||||
@@ -2993,7 +2903,6 @@ int main(int argc, char **argv) {
|
||||
int force = 0;
|
||||
int forcetable = 0;
|
||||
double droprate = 2.5;
|
||||
double gamma = 0;
|
||||
int buffer = 5;
|
||||
const char *tmpdir = "/tmp";
|
||||
const char *attribution = NULL;
|
||||
@@ -3005,8 +2914,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;
|
||||
@@ -3068,7 +2977,6 @@ int main(int argc, char **argv) {
|
||||
{"empty-csv-columns-are-null", no_argument, &prevent[P_EMPTY_CSV_COLUMNS], 1},
|
||||
{"convert-stringified-ids-to-numbers", no_argument, &additional[A_CONVERT_NUMERIC_IDS], 1},
|
||||
{"use-attribute-for-id", required_argument, 0, '~'},
|
||||
{"single-precision", no_argument, &prevent[P_SINGLE_PRECISION], 1},
|
||||
{"set-attribute", required_argument, 0, '~'},
|
||||
|
||||
{"Filtering features by attributes", 0, 0, 0},
|
||||
@@ -3079,7 +2987,6 @@ int main(int argc, char **argv) {
|
||||
{"drop-rate", required_argument, 0, 'r'},
|
||||
{"retain-points-multiplier", required_argument, 0, '~'},
|
||||
{"base-zoom", required_argument, 0, 'B'},
|
||||
{"drop-denser", required_argument, 0, '~'},
|
||||
{"limit-base-zoom-to-maximum-zoom", no_argument, &prevent[P_BASEZOOM_ABOVE_MAXZOOM], 1},
|
||||
{"drop-lines", no_argument, &additional[A_LINE_DROP], 1},
|
||||
{"drop-polygons", no_argument, &additional[A_POLYGON_DROP], 1},
|
||||
@@ -3094,13 +3001,8 @@ int main(int argc, char **argv) {
|
||||
{"coalesce-densest-as-needed", no_argument, &additional[A_COALESCE_DENSEST_AS_NEEDED], 1},
|
||||
{"coalesce-fraction-as-needed", no_argument, &additional[A_COALESCE_FRACTION_AS_NEEDED], 1},
|
||||
{"coalesce-smallest-as-needed", no_argument, &additional[A_COALESCE_SMALLEST_AS_NEEDED], 1},
|
||||
{"force-feature-limit", no_argument, &prevent[P_DYNAMIC_DROP], 1},
|
||||
{"cluster-densest-as-needed", no_argument, &additional[A_CLUSTER_DENSEST_AS_NEEDED], 1},
|
||||
|
||||
{"Dropping tightly overlapping features", 0, 0, 0},
|
||||
{"gamma", required_argument, 0, 'g'},
|
||||
{"increase-gamma-as-needed", no_argument, &additional[A_INCREASE_GAMMA_AS_NEEDED], 1},
|
||||
|
||||
{"Line and polygon simplification", 0, 0, 0},
|
||||
{"simplification", required_argument, 0, 'S'},
|
||||
{"no-line-simplification", no_argument, &prevent[P_SIMPLIFY], 1},
|
||||
@@ -3113,7 +3015,6 @@ int main(int argc, char **argv) {
|
||||
{"visvalingam", no_argument, &additional[A_VISVALINGAM], 1},
|
||||
|
||||
{"Attempts to improve shared polygon boundaries", 0, 0, 0},
|
||||
{"detect-shared-borders", no_argument, &additional[A_DETECT_SHARED_BORDERS], 1},
|
||||
{"grid-low-zooms", no_argument, &additional[A_GRID_LOW_ZOOMS], 1},
|
||||
|
||||
{"Controlling clipping to tile boundaries", 0, 0, 0},
|
||||
@@ -3178,6 +3079,9 @@ int main(int argc, char **argv) {
|
||||
{"prefer-radix-sort", no_argument, &additional[A_PREFER_RADIX_SORT], 1},
|
||||
{"help", no_argument, 0, 'H'},
|
||||
|
||||
{"Redundant", 0, 0, 0},
|
||||
{"detect-shared-borders", no_argument, &prevent[P_SIMPLIFY_SHARED_NODES], 1},
|
||||
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
@@ -3204,6 +3108,10 @@ int main(int argc, char **argv) {
|
||||
getopt_str[cout] = '\0';
|
||||
|
||||
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
|
||||
if (strcmp(long_options[lo].name, "Redundant")) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (long_options[lo].flag != NULL) {
|
||||
if (*long_options[lo].flag != 0) {
|
||||
fprintf(stderr, "Internal error: reused %s\n", long_options[lo].name);
|
||||
@@ -3288,12 +3196,6 @@ int main(int argc, char **argv) {
|
||||
limit_tile_feature_count = atoll_require(optarg, "Limit tile feature count");
|
||||
} else if (strcmp(opt, "limit-tile-feature-count-at-maximum-zoom") == 0) {
|
||||
limit_tile_feature_count_at_maxzoom = atoll_require(optarg, "Limit tile feature count at maxzoom");
|
||||
} else if (strcmp(opt, "drop-denser") == 0) {
|
||||
drop_denser = atoi_require(optarg, "Drop denser rate");
|
||||
if (drop_denser > 100) {
|
||||
fprintf(stderr, "%s: --drop-denser can be at most 100\n", argv[0]);
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
} else if (strcmp(opt, "preserve-point-density-threshold") == 0) {
|
||||
preserve_point_density_threshold = atoll_require(optarg, "Preserve point density threshold");
|
||||
} else if (strcmp(opt, "extend-zooms-if-still-dropping-maximum") == 0) {
|
||||
@@ -3534,10 +3436,6 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
gamma = atof_require(optarg, "Gamma");
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
quiet = 1;
|
||||
break;
|
||||
@@ -3760,13 +3658,6 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((basezoom < 0 || droprate < 0) && (gamma < 0)) {
|
||||
// Can't use randomized (as opposed to evenly distributed) dot dropping
|
||||
// if rate and base aren't known during feature reading.
|
||||
gamma = 0;
|
||||
fprintf(stderr, "Forcing -g0 since -B or -r is not known\n");
|
||||
}
|
||||
|
||||
if (out_mbtiles == NULL && out_dir == NULL) {
|
||||
fprintf(stderr, "%s: must specify -o out.mbtiles or -e directory\n", argv[0]);
|
||||
exit(EXIT_ARGS);
|
||||
@@ -3821,7 +3712,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
auto input_ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles
|
||||
: out_dir,
|
||||
maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, filter, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, file_bbox1, file_bbox2, prefilter, postfilter, description, guess_maxzoom, guess_cluster_maxzoom, &attribute_types, argv[0], &attribute_accum, attribute_descriptions, commandline, minimum_maxzoom);
|
||||
maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, filter, droprate, buffer, tmpdir, read_parallel, forcetable, attribution, file_bbox, file_bbox1, file_bbox2, prefilter, postfilter, description, guess_maxzoom, guess_cluster_maxzoom, &attribute_types, argv[0], &attribute_accum, attribute_descriptions, commandline, minimum_maxzoom);
|
||||
|
||||
ret = std::get<0>(input_ret);
|
||||
|
||||
|
||||
+2
-24
@@ -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
|
||||
@@ -524,8 +520,6 @@ The attributes and values may also be specified as JSON keys and values: \fB\fC\
|
||||
\fB\fC\-aI\fR or \fB\fC\-\-convert\-stringified\-ids\-to\-numbers\fR: If a feature ID is the string representation of a number, convert it to a plain number to use as the feature ID.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-\-use\-attribute\-for\-id=\fR\fIname\fP: Use the attribute with the specified \fIname\fP as if it were specified as the feature ID. (If this attribute is a stringified number, you must also use \fB\fC\-aI\fR to convert it to a number.)
|
||||
.IP \(bu 2
|
||||
\fB\fC\-pN\fR or \fB\fC\-\-single\-precision\fR: Write double\-precision numeric attribute values to tiles as single\-precision to reduce tile size.
|
||||
.RE
|
||||
.SS Filtering features by attributes
|
||||
.RS
|
||||
@@ -578,10 +572,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.
|
||||
.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.
|
||||
\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\-\-limit\-base\-zoom\-to\-maximum\-zoom\fR or \fB\fC\-Pb\fR: 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.
|
||||
.IP \(bu 2
|
||||
@@ -612,17 +603,8 @@ preference to retaining points in sparse areas and dropping points in dense area
|
||||
.IP \(bu 2
|
||||
\fB\fC\-aS\fR or \fB\fC\-\-coalesce\-fraction\-as\-needed\fR: Dynamically combine a fraction of features from each zoom level into other nearby features to keep large tiles under the 500K size limit. (Again, mostly useful for polygons.)
|
||||
.IP \(bu 2
|
||||
\fB\fC\-pd\fR or \fB\fC\-\-force\-feature\-limit\fR: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. (This is like \fB\fC\-ad\fR but applies to each tile individually, not to the entire zoom level.) You probably don't want to use this.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-aC\fR or \fB\fC\-\-cluster\-densest\-as\-needed\fR: If a tile is too large, try to reduce its size by increasing the minimum spacing between features, and leaving one placeholder feature from each group. The remaining feature will be given a \fB\fC"clustered": true\fR attribute to indicate that it represents a cluster, a \fB\fC"point_count"\fR attribute to indicate the number of features that were clustered into it, and a \fB\fC"sqrt_point_count"\fR attribute to indicate the relative width of a feature to represent the cluster. If the features being clustered are points, the representative feature will be located at the average of the original points' locations; otherwise, one of the original features will be left as the representative.
|
||||
.RE
|
||||
.SS Dropping tightly overlapping features
|
||||
.RS
|
||||
.IP \(bu 2
|
||||
\fB\fC\-g\fR \fIgamma\fP or \fB\fC\-\-gamma=_gamma\fR_: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-aG\fR or \fB\fC\-\-increase\-gamma\-as\-needed\fR: If a tile is too large, try to reduce it to under 500K by increasing the \fB\fC\-g\fR gamma. The discovered gamma applies to the entire zoom level. You probably want to use \fB\fC\-\-drop\-densest\-as\-needed\fR instead.
|
||||
.RE
|
||||
.SS Line and polygon simplification
|
||||
.RS
|
||||
.IP \(bu 2
|
||||
@@ -763,7 +745,7 @@ as a series of newline\-delimited GeoJSON objects on the standard input, and \fB
|
||||
set of GeoJSON features from the filter's standard output.
|
||||
.PP
|
||||
The prefilter receives the features at the highest available resolution, before line simplification,
|
||||
polygon topology repair, gamma calculation, dynamic feature dropping, or other internal processing.
|
||||
polygon topology repair, dynamic feature dropping, or other internal processing.
|
||||
The postfilter receives the features at tile resolution, after simplification, cleaning, and dropping.
|
||||
.PP
|
||||
The layer name is provided as part of the \fB\fCtippecanoe\fR element of the feature and must be passed through
|
||||
@@ -869,10 +851,6 @@ a different zoom specified with \fB\fC\-B\fR if you have precise but sparse data
|
||||
I don't know why 2.5 is the appropriate number, but the densities of many different
|
||||
data sets fall off at about this same rate. You can use \-r to specify a different rate.
|
||||
.PP
|
||||
You can use the gamma option to thin out especially dense clusters of points.
|
||||
For any area where dots are closer than one pixel together (at whatever zoom level),
|
||||
a gamma of 3, for example, will reduce these clusters to the cube root of their original density.
|
||||
.PP
|
||||
For line features, it drops any features that are too small to draw at all.
|
||||
This still leaves the lower zooms too dark (and too dense for the 500K tile limit,
|
||||
in some places), so I need to figure out an equitable way to throw features away.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
#define A_LINE_DROP ((int) 'l')
|
||||
#define A_DEBUG_POLYGON ((int) '@')
|
||||
#define A_POLYGON_DROP ((int) 'p')
|
||||
#define A_DETECT_SHARED_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')
|
||||
#define A_DROP_DENSEST_AS_NEEDED ((int) 's')
|
||||
#define A_DROP_FRACTION_AS_NEEDED ((int) 'd')
|
||||
#define A_DROP_SMALLEST_AS_NEEDED ((int) 'n')
|
||||
@@ -30,10 +28,8 @@
|
||||
#define P_SIMPLIFY ((int) 's')
|
||||
#define P_SIMPLIFY_LOW ((int) 'S')
|
||||
#define P_SIMPLIFY_SHARED_NODES ((int) 'n')
|
||||
#define P_SINGLE_PRECISION ((int) 'N')
|
||||
#define P_FEATURE_LIMIT ((int) 'f')
|
||||
#define P_KILOBYTE_LIMIT ((int) 'k')
|
||||
#define P_DYNAMIC_DROP ((int) 'd')
|
||||
#define P_INPUT_ORDER ((int) 'i')
|
||||
#define P_POLYGON_SPLIT ((int) 'p')
|
||||
#define P_CLIPPING ((int) 'c')
|
||||
|
||||
+1
-1
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
+2
-11
@@ -719,7 +719,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
|
||||
}
|
||||
}
|
||||
|
||||
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED] || additional[A_INCREASE_GAMMA_AS_NEEDED] || additional[A_GENERATE_POLYGON_LABEL_POINTS] || sst->uses_gamma || cluster_distance != 0) {
|
||||
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED] || additional[A_GENERATE_POLYGON_LABEL_POINTS] || cluster_distance != 0) {
|
||||
sf.index = bbox_index;
|
||||
} else {
|
||||
sf.index = 0;
|
||||
@@ -766,15 +766,6 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
|
||||
for (ssize_t i = (ssize_t) sf.full_keys.size() - 1; i >= 0; i--) {
|
||||
coerce_value(sf.full_keys[i], sf.full_values[i].type, sf.full_values[i].s, sst->attribute_types);
|
||||
|
||||
if (prevent[P_SINGLE_PRECISION]) {
|
||||
if (sf.full_values[i].type == mvt_double) {
|
||||
// don't coerce integers to floats, since that is counterproductive
|
||||
if (sf.full_values[i].s.find('.') != std::string::npos) {
|
||||
sf.full_values[i].s = milo::dtoa_milo((float) atof(sf.full_values[i].s.c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sf.full_keys[i] == attribute_for_id) {
|
||||
if (sf.full_values[i].type != mvt_double && !additional[A_CONVERT_NUMERIC_IDS]) {
|
||||
static bool warned = false;
|
||||
@@ -878,7 +869,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
-3
@@ -171,11 +171,10 @@ struct serialization_state {
|
||||
int basezoom = 0;
|
||||
|
||||
bool filters = false;
|
||||
bool uses_gamma = false;
|
||||
|
||||
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 +227,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
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
{ "type": "FeatureCollection", "properties": {
|
||||
"antimeridian_adjusted_bounds": "0.000000,0.000000,0.000000,0.000000",
|
||||
"bounds": "0.000000,0.000000,0.000000,0.000000",
|
||||
"center": "0.000000,0.000000,0",
|
||||
"description": "tests/attribute-type/out/-z0_-pN.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"generator_options": "./tippecanoe -q -a@ -f -o tests/attribute-type/out/-z0_-pN.json.check.mbtiles -z0 -pN tests/attribute-type/in.json",
|
||||
"json": "{\"vector_layers\":[{\"id\":\"in\",\"description\":\"\",\"minzoom\":0,\"maxzoom\":0,\"fields\":{\"booltype\":\"Mixed\",\"expect\":\"Mixed\",\"floattype\":\"Mixed\",\"inttype\":\"Mixed\",\"stringtype\":\"Mixed\"}}],\"tilestats\":{\"layerCount\":1,\"layers\":[{\"layer\":\"in\",\"count\":39,\"geometry\":\"Point\",\"attributeCount\":5,\"attributes\":[{\"attribute\":\"booltype\",\"count\":10,\"type\":\"mixed\",\"values\":[\"\",\"0\",0,1,\"[2,3]\",\"false\",false,\"null\",true,\"yes\"],\"min\":0,\"max\":1},{\"attribute\":\"expect\",\"count\":14,\"type\":\"mixed\",\"values\":[0,\"2\",\"2.5\",3,5,5.599999904632568,6,\"[2,3]\",\"false\",false,\"null\",\"something\",\"true\",true],\"min\":0,\"max\":6},{\"attribute\":\"floattype\",\"count\":9,\"type\":\"mixed\",\"values\":[\"\",\" 3\",\"5\",5.599999904632568,\"5.6\",\"[2,3]\",false,true,\"yes\"],\"min\":5.599999904632568,\"max\":5.599999904632568},{\"attribute\":\"inttype\",\"count\":9,\"type\":\"mixed\",\"values\":[\"\",\" 3\",\"5\",5.599999904632568,\"5.6\",\"[2,3]\",false,true,\"yes\"],\"min\":5.599999904632568,\"max\":5.599999904632568},{\"attribute\":\"stringtype\",\"count\":6,\"type\":\"mixed\",\"values\":[2,2.5,\"[2,3]\",false,\"something\",true],\"min\":2,\"max\":2.5}]}]}}",
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/attribute-type/out/-z0_-pN.json.check.mbtiles",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "null", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": 0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "0", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "false", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": 1, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": 0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "yes", "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": "[2,3]", "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "expect": "null" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": 2, "expect": "2" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": 2.5, "expect": "2.5" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": true, "expect": "true" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": false, "expect": "false" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "something", "expect": "something" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "[2,3]", "expect": "[2,3]" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": "5", "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": "5.6", "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 5.599999904632568, "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": true, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": false, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": "", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": "yes", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": " 3", "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": "[2,3]", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": "5", "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": "5.6", "expect": 5.599999904632568 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 5.599999904632568, "expect": 5.599999904632568 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": true, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": false, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": "", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": "yes", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": " 3", "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": "[2,3]", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
] }
|
||||
] }
|
||||
] }
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
-22258
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ struct strategy {
|
||||
strategy() = default;
|
||||
};
|
||||
|
||||
// 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);
|
||||
// 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, 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, 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);
|
||||
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double *gap);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
#define VERSION "v2.41.3"
|
||||
#define VERSION "v2.41.2"
|
||||
|
||||
#endif
|
||||
|
||||
+10
-19
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user