Compare commits

..
Author SHA1 Message Date
Claude 23fe065aea Keep the radix sort from recursing forever when it runs out of files
radix1() subdivides a bucket by the next splitbits bits of the index, and
stops recursing once prefix + splitbits reaches the width of the index.
The number of buckets comes from the number of files still available, which
shrinks at every level, so deep enough recursion reaches availfiles / 4 == 1
and therefore splitbits == 0. At that point the recursion consumes no bits
of the index and availfiles stops shrinking, so prefix never advances and
the recursion has no way to terminate.

A splitbits of 0 also makes the shift that chooses a feature's bucket a
shift by the full width of the index, which is undefined. In practice it
leaves the shift count masked to zero, so the bucket number is the whole
index rather than 0, and writing to that bucket runs off the end of the
arrays of open files.

Require at least two buckets so that each subdivision always consumes at
least one bit of the index and the shift is always in range, and don't
recurse at all when the next level would not have enough files to split
with: sort that bucket in memory instead, even though it is larger than
the memory limit asked for, since that is the only way left to get it
sorted.

--prefer-radix-sort, which lowers the memory limit to 8K to exercise this
code, segfaults on tests/feature-filter/in.json without this. The other
inputs that it fails on are failing for an unrelated reason, which is
fixed separately in #402; with both changes, --prefer-radix-sort produces
output identical to the ordinary in-memory sort on all of them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011wLk2itWETPBAS9a9yE8zu
2026-08-05 16:47:21 +00:00
32 changed files with 1517 additions and 1936 deletions
-17
View File
@@ -19,20 +19,3 @@ jobs:
run: brew install sqlite3
- run: uname -a; BUILDTYPE=${{ matrix.version }} make
- run: make test
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Pinned, because different go-md2man versions produce different roff
# for the same input, which would make this check fail spuriously.
- name: Install go-md2man
run: go install github.com/cpuguy83/go-md2man/v2@v2.0.7
- name: Regenerate the man page
run: PATH="$PATH:$(go env GOPATH)/bin" make -B docs
- name: Check that the man page is up to date with README.md
run: |
git diff --exit-code man/tippecanoe.1 || {
echo "::error::man/tippecanoe.1 is out of date. Run 'make docs' and commit the result."
exit 1
}
-3
View File
@@ -38,9 +38,6 @@ tippecanoe-json-tool
tippecanoe-overzoom
unit
# Left behind if man page generation fails
man/tippecanoe.1.tmp
# Tests
tests/**/*.mbtiles
tests/**/*.check
-76
View File
@@ -1,79 +1,3 @@
# 2.81.0
* Report errors from the tile clipping and overzooming code by throwing a
`tippecanoe_error` rather than by calling `exit()`, and give that code
RAII ownership of its `FILE *` and `json_pull *` handles so that nothing
leaks when an error unwinds the stack. Each command-line tool catches the
exception in `main()` and exits with the same status it would have
before. Along the way this fixes a leaked `z_stream` when `compress()`
failed and two `exit()` calls that could run from a destructor or from
`mvt_value`'s hash function.
* Add `--drop-by-attribute-as-needed=`*attribute* to drop the features with
the lowest values of a numeric attribute from oversized tiles, and
`--drop-by-attribute-order=desc` to drop the highest values instead.
Features exactly at the threshold are kept rather than dropped. (#384, #385)
* Add `--exclude-all-tile-geometries` to tile-join, to produce tiles that
carry only attributes. (#382)
* Generate each tool's usage message from the same option table that
`getopt_long()` reads, so the hand-written lists in tile-join,
tippecanoe-overzoom, tippecanoe-json-tool, tippecanoe-decode, and
tippecanoe-enumerate can no longer fall behind the options actually
accepted. Options previously reachable only by their short names are now
listed. tippecanoe-overzoom reports a missing `-o` instead of passing a
null pointer to `fopen()`, and tippecanoe prints its usage when run with
no arguments. (#409)
* Fix the radix sort used by `--prefer-radix-sort`. A bucket written out
directly rather than through the merge was written one byte longer than
its length prefix claimed, desynchronizing everything read from the
geometry after it. Subdividing could also recurse forever once it ran out
of files to split with, shifting by the full width of the index and
writing past the end of the arrays of buckets. Radix-sorted output is now
checked against the in-memory sort rather than against a stored copy. (#404)
* Read FlatGeobuf integer and float properties as numbers. They were tagged
with types that the rest of tippecanoe does not treat as numeric, so they
were reported in tilestats as "mixed", with quoted values and no min or
max, and warned when used as a feature ID. ULong properties are now also
read as unsigned rather than signed. (#395)
* Respect the `-t` temporary directory option in sorting operations, which
previously always used the system temporary directory. (#368)
* Keep `--generate-variable-depth-tile-pyramid` from silently dropping
features whose explicit per-feature `minzoom` is deeper than the zoom at
which their region becomes a leaf. Such a feature was excluded from the
leaf tile while its children were never generated, so it appeared at no
zoom at all. (#397, #399)
* Drop a polygon hole that no remaining ring can parent, instead of failing
the whole run. Degenerate input could abort tiling over a single
unrepresentable sliver. (#401)
* Clamp the feature extent to the `long long` range before converting it,
at both ends. The previous `extent <= LLONG_MAX` guard was doubly wrong:
`LLONG_MAX` is not representable as a double and rounds up, so an extent
at the very top of the range overflowed the conversion and came out as the
most negative value rather than the largest, and the guard admitted
everything below `LLONG_MIN` as well, which overflowed the other way. Areas
are signed, so holes that outweigh their rings can reach the low end. (#406)
* Initialize the full width of the `mvt_value` numeric union, which left the
bytes of the wider unused member indeterminate even though the implicit
copy constructor copies the union as a whole. (#406)
* Replace all variable-length arrays with `std::vector` and `std::string`,
and build with `-Wvla`. VLAs are a compiler extension rather than standard
C++, and clang warns about every one of them by default. (#406)
* Remove the unused Dockerfiles, Travis configuration, and lambda
directory. (#365)
* Correct README statements that disagreed with the code. Among them, `-aD`
and `-aS` were documented the wrong way round,
`--limit-base-zoom-to-maximum-zoom` was given as `-Pb` rather than `-pb`,
and the dot-dropping description had both the fraction and the zoom
direction backwards: tippecanoe keeps 1/2.5 of the dots at zooms below the
base zoom, rather than dropping that share above it. (#410)
* Generate `man/tippecanoe.1` with go-md2man rather than md2man-roff, which
is packaged only as a Ruby gem and so had let the page drift out of date.
The page now has a proper header and a NAME section, so `man -k` and
`whatis` can find it, and no longer silently drops or mangles text the old
converter mishandled. CI checks it against README.md. (#408)
* Documentation fixes: correct three misspellings in the README and man
page, repair the dead All Streets link, and tag more README code blocks
with their language. (#375, #391, #400)
# 2.80.0
* Remove undocumented command-line options
+12 -84
View File
@@ -11,7 +11,7 @@ CXX := $(CXX)
CFLAGS := $(CFLAGS) -fPIE -DBUILD_INFO=$(BUILD_INFO)
CXXFLAGS := $(CXXFLAGS) -std=c++17 -fPIE -DBUILD_INFO=$(BUILD_INFO)
LDFLAGS := $(LDFLAGS)
WARNING_FLAGS := -Wall -Wshadow -Wsign-compare -Wextra -Wunreachable-code -Wuninitialized -Wshadow -Wvla
WARNING_FLAGS := -Wall -Wshadow -Wsign-compare -Wextra -Wunreachable-code -Wuninitialized -Wshadow
RELEASE_FLAGS := -O3 -DNDEBUG
DEBUG_FLAGS := -O0 -DDEBUG -fno-inline-functions -fno-omit-frame-pointer
@@ -48,44 +48,8 @@ install: tippecanoe tippecanoe-enumerate tippecanoe-decode tile-join tippecanoe-
uninstall:
rm $(PREFIX)/bin/tippecanoe $(PREFIX)/bin/tippecanoe-enumerate $(PREFIX)/bin/tippecanoe-decode $(PREFIX)/bin/tile-join $(MANDIR)/tippecanoe.1 $(PREFIX)/bin/tippecanoe-json-tool
# The man page is generated from README.md by go-md2man, which is packaged for
# most systems (`brew install go-md2man`, `apt-get install go-md2man`) or can be
# built with `go install github.com/cpuguy83/go-md2man/v2@v2.0.7`. CI checks that
# the committed man page matches the README, so you don't have to regenerate it
# yourself if you don't have go-md2man installed.
#
# README.md has no .TH or NAME section of its own, since neither would make sense
# on GitHub, so prepend them here. go-md2man reads the leading "%" line as the
# man page's title, section, date, and source. The version deliberately doesn't
# appear there: it would make this page a build product of version.hpp, so every
# release would have to regenerate it just to rewrite that one line, and the docs
# CI job would fail on any version bump that forgot to.
#
# Two fixups on the way out:
#
# - README.md's own title heading becomes the second .SH, right below the NAME
# section added above, which reads as a stray "tippecanoe" section. Rename it
# to DESCRIPTION, where the text under it belongs anyway.
# - go-md2man separates paragraphs with a blank line in addition to the .PP
# macro, and a blank line is itself a break in roff, so the two together
# double-space the whole page. Drop them, except within .EX and .TS blocks,
# where a blank line is part of the example or table rather than spacing.
man/tippecanoe.1: README.md
{ \
echo '% TIPPECANOE 1 "" "tippecanoe"'; \
echo; \
echo '# NAME'; \
echo; \
echo 'tippecanoe - build vector tilesets from GeoJSON, FlatGeobuf, or CSV features'; \
echo; \
cat README.md; \
} | go-md2man \
| awk ' \
/^\.SH / && ++sh == 2 { print ".SH DESCRIPTION"; next } \
/^\.(EX|TS)$$/ { lit = 1 } \
/^\.(EE|TE)$$/ { lit = 0 } \
lit || !/^$$/ \
' > $@.tmp && mv $@.tmp $@
md2man-roff README.md > man/tippecanoe.1
PG=
@@ -95,25 +59,25 @@ C = $(wildcard *.c) $(wildcard *.cpp)
INCLUDES = -I/usr/local/include -I. -Iclipper2/include
LIBS = -L/usr/local/lib
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o platform.o text.o dirtiles.o pmtiles_file.o plugin.o read_json.o write_json.o geobuf.o flatgeobuf.o evaluator.o geocsv.o csv.o geojson-loop.o json_logger.o visvalingam.o compression.o clip.o sort.o attribute.o thread.o shared_borders.o usage.o clipper2/src/clipper.engine.o errors.o
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o platform.o text.o dirtiles.o pmtiles_file.o plugin.o read_json.o write_json.o geobuf.o flatgeobuf.o evaluator.o geocsv.o csv.o geojson-loop.o json_logger.o visvalingam.o compression.o clip.o sort.o attribute.o thread.o shared_borders.o clipper2/src/clipper.engine.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
tippecanoe-enumerate: enumerate.o usage.o
tippecanoe-enumerate: enumerate.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lsqlite3
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o usage.o errors.o
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
tile-join: tile-join.o platform.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o attribute.o thread.o read_json.o usage.o clipper2/src/clipper.engine.o errors.o
tile-join: tile-join.o platform.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o attribute.o thread.o read_json.o clipper2/src/clipper.engine.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o usage.o errors.o
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
unit: unit.o text.o sort.o mvt.o projection.o clip.o attribute.o jsonpull/jsonpull.o evaluator.o read_json.o clipper2/src/clipper.engine.o errors.o
unit: unit.o text.o sort.o mvt.o projection.o clip.o attribute.o jsonpull/jsonpull.o evaluator.o read_json.o clipper2/src/clipper.engine.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
tippecanoe-overzoom: overzoom.o mvt.o clip.o evaluator.o jsonpull/jsonpull.o text.o attribute.o read_json.o projection.o read_json.o usage.o clipper2/src/clipper.engine.o errors.o
tippecanoe-overzoom: overzoom.o mvt.o clip.o evaluator.o jsonpull/jsonpull.o text.o attribute.o read_json.o projection.o read_json.o clipper2/src/clipper.engine.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
-include $(wildcard *.d)
@@ -128,12 +92,12 @@ clean:
rm -f ./tippecanoe ./tippecanoe-* ./tile-join ./unit *.o *.d */*.o */*.d tests/**/*.mbtiles tests/**/*.check
indent:
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false, SortIncludes: false, PointerAlignment: Right, DerivePointerAlignment: false}" $(filter-out flatgeobuf.cpp,$(C)) $(H) jsonpull/*.[ch]
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false, SortIncludes: false}" $(filter-out flatgeobuf.cpp,$(C)) $(H) jsonpull/*.[ch]
TESTS = $(wildcard tests/*/out/*.json)
SPACE = $(NULL) $(NULL)
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) raw-tiles-test parallel-test radix-sort-test pbf-test join-test enumerate-test decode-test join-filter-test unit json-tool-test allow-existing-test csv-test layer-json-test pmtiles-test decode-pmtiles-test overzoom-test flatgeobuf-test
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) raw-tiles-test parallel-test pbf-test join-test enumerate-test decode-test join-filter-test unit json-tool-test allow-existing-test csv-test layer-json-test pmtiles-test decode-pmtiles-test overzoom-test flatgeobuf-test
./unit
suffixes = json json.gz
@@ -168,7 +132,7 @@ nogeobuf = tests/overflow/out/-z0.json $(wildcard tests/stringid/out/*.json)
geobuf-test: tippecanoe-json-tool $(addsuffix .checkbuf,$(filter-out $(nogeobuf),$(TESTS)))
# For quicker address sanitizer build, hope that regular JSON parsing is tested enough by parallel and join tests
fewer-tests: tippecanoe tippecanoe-decode geobuf-test raw-tiles-test parallel-test radix-sort-test pbf-test join-test enumerate-test decode-test join-filter-test unit
fewer-tests: tippecanoe tippecanoe-decode geobuf-test raw-tiles-test parallel-test pbf-test join-test enumerate-test decode-test join-filter-test unit
# XXX Use proper makefile rules instead of a for loop
%.json.checkbuf:
@@ -179,42 +143,6 @@ fewer-tests: tippecanoe tippecanoe-decode geobuf-test raw-tiles-test parallel-te
cmp $@.out $(patsubst %.checkbuf,%,$@)
rm $@.out $@.mbtiles
# The result of the sort must not depend on how the sort was performed, so instead of
# checking the sorted output against an expected copy of it, check that sorting by radix
# produces the same tiles as sorting in memory. --prefer-radix-sort lowers the memory
# limit to 8K, which radix() then halves again, so the radix subdivision has to recurse
# until each bucket is under 4K. How deeply that recurses depends on how many files the
# machine will let us open at once, but the sorted result is the same either way, so
# this comparison doesn't depend on that.
#
# What sends the sort down its rarely-taken paths is the shape of the input rather than
# the size of it: a feature whose geometry alone is bigger than the memory limit is
# sorted as a bucket of its own, and features that share a long run of leading index
# bits have to be subdivided until there are no bits left. The first two inputs are
# each one of those on purpose -- several separated features too big to sort in memory,
# and many features at one location -- and the rest are for breadth.
radix-sort-test: tippecanoe tippecanoe-decode
mkdir -p tests/radix-sort
perl -e 'for ($$f = 0; $$f < 8; $$f++) { print "{ \"type\": \"Feature\", \"properties\": { \"f\": $$f }, \"geometry\": { \"type\": \"LineString\", \"coordinates\": ["; for ($$i = 0; $$i < 2000; $$i++) { print "," unless $$i == 0; printf "[%f,%f]", $$f * 40 - 175 + $$i * 0.001, $$i % 2 * 0.5 - 20; } print "] } }\n"; }' > tests/radix-sort/bigfeatures.json
perl -e 'for ($$i = 0; $$i < 500; $$i++) { print "{ \"type\": \"Feature\", \"properties\": { \"i\": $$i }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 17, 42 ] } }\n"; }' > tests/radix-sort/onelocation.json
$(MAKE) radix-sort-compare RADIXIN="tests/radix-sort/bigfeatures.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/radix-sort/onelocation.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/feature-filter/in.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/ne_110m_ocean/in.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/border/in.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/loop/in.json" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/tl_2022_11_tract/in.json.gz" RADIXARGS="-z4"
$(MAKE) radix-sort-compare RADIXIN="tests/epsg-3857/in.json" RADIXARGS="-z4 -sEPSG:3857"
rm -r tests/radix-sort
radix-sort-compare:
./tippecanoe -q -f $(RADIXARGS) -o tests/radix-sort/memory.mbtiles $(RADIXIN)
./tippecanoe -q -f $(RADIXARGS) -aR -o tests/radix-sort/radix.mbtiles $(RADIXIN)
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/radix-sort/memory.mbtiles > tests/radix-sort/memory.json
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/radix-sort/radix.mbtiles > tests/radix-sort/radix.json
cmp tests/radix-sort/memory.json tests/radix-sort/radix.json
rm tests/radix-sort/memory.mbtiles tests/radix-sort/radix.mbtiles tests/radix-sort/memory.json tests/radix-sort/radix.json
parallel-test: $(eval SHELL:=$(ADVSHELL))
mkdir -p tests/parallel
perl -e 'for ($$i = 0; $$i < 20; $$i++) { $$lon = rand(360) - 180; $$lat = rand(180) - 90; $$k = rand(1); $$v = rand(1); print "{ \"type\": \"Feature\", \"properties\": { \"yes\": \"no\", \"who\": 1, \"$$k\": \"$$v\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ $$lon, $$lat ] } }\n"; }' > tests/parallel/in1.json
+31 -72
View File
@@ -58,7 +58,7 @@ Usage
-----
```
$ tippecanoe -o file.mbtiles [options] [file.json file.json.gz file.fgb file.csv ...]
$ tippecanoe -o file.mbtiles [options] [file.json file.json.gz file.fgb ...]
```
If no files are specified, it reads GeoJSON from the standard input.
@@ -291,11 +291,6 @@ If your features have a lot of attributes, use `-y` to keep only the ones you re
If your input is formatted as newline-delimited GeoJSON, use `-P` to make input parsing a lot faster.
Many of the options below have a short form beginning with `-a` or `-p`. These are the
`-a`_letters_ (`--additional=`_letters_) and `-p`_letters_ (`--prevent=`_letters_) options, and each
accepts several letters at once, so for example `-ansd` is the same as `-an -as -ad`
and `-pkC` is the same as `-pk -pC`.
### Output tileset
* `-o` _file_`.mbtiles`, _file_`.pmtiles` or `--output=`_file_`.mbtiles`: Name the output file.
@@ -306,9 +301,9 @@ and `-pkC` is the same as `-pk -pC`.
### Tileset description and attribution
* `-n` _name_ or `--name=`_name_: Human-readable name for the tileset (default: the name of the output file or directory)
* `-n` _name_ or `--name=`_name_: Human-readable name for the tileset (default file.json)
* `-A` _text_ or `--attribution=`_text_: Attribution (HTML) to be shown with maps that use data from this tileset.
* `-N` _description_ or `--description=`_description_: Description for the tileset (default: the name of the output file or directory)
* `-N` _description_ or `--description=`_description_: Description for the tileset (default file.mbtiles)
### Input files and layer names
@@ -325,7 +320,7 @@ and `-pkC` is the same as `-pk -pC`.
tippecanoe -z5 -o world.mbtiles -L'{"file":"ne_10m_admin_0_countries.json", "layer":"countries", "description":"Natural Earth countries"}'
```
CSV input files currently support only Point geometries, from columns named `lat`, `lon`, `long`, `lng`, `x`, or `y`, or from any column whose name contains `latitude` or `longitude`. Column names are matched without regard to case.
CSV input files currently support only Point geometries, from columns named `latitude`, `longitude`, `lat`, `lon`, `long`, `lng`, `x`, or `y`.
### Parallel processing of input
@@ -420,9 +415,8 @@ be reduced to the maximum that can be used with the specified _maxzoom_.
* `-Y`_attribute_`:`_description_ or `--attribute-description=`_attribute_`:`_description_: Set the `description` for the specified attribute in the tileset metadata to _description_ instead of the usual `String`, `Number`, or `Boolean`.
* `-E`_attribute_`:`_operation_ or `--accumulate-attribute=`_attribute_`:`_operation_: Preserve the named _attribute_ from features
that are dropped, coalesced-as-needed, or clustered. The _operation_ may be
`sum`, `product`, `mean`, `max`, `min`, `concat`, `comma`, or `count`
`sum`, `product`, `mean`, `max`, `min`, `concat`, or `comma`
to specify how the named _attribute_ is accumulated onto the attribute of the same name in a feature that does survive.
(The `count` operation replaces the attribute with the number of features, including the survivor, that carried it.)
The attributes and operations may also be specified as JSON keys and values: `--accumulate-attribute='{"attr": "operation", "attr2": "operation2"}'`.
* `--set-attribute` _attribute_`:`_value_: Set the value of the specified _attribute_ in each feature to the specified _value_. This is mostly useful to give an attribute in each feature an initial value for `--accumulate-attribute`.
The attributes and values may also be specified as JSON keys and values: `--set-attribute='{"attr": value, "attr2": value}'`.
@@ -472,17 +466,16 @@ 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 maximum tile size (`--maximum-tile-bytes`) will also be extended at low zoom levels to allow for the multiplied features.
* `--retain-points-multiplier=`_multiple_: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the `-m` option to `tippecanoe-overzoom`. The start of each cluster is marked in the feature sequence by the `tippecanoe:retain_points_multiplier_first` attribute. 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.
* `--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.
* `--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
* `-K` _distance_ or `--cluster-distance=`_distance_: Cluster points (as with `--cluster-densest-as-needed`, but without the experimental discovery process) that are approximately within _distance_ of each other. The units are tile coordinates within a nominally 256-pixel tile, so the maximum value of 255 allows only one feature per tile. Values around 10 are probably appropriate for typical marker sizes. See `--cluster-densest-as-needed` below for behavior.
* `-k` _zoom_ or `--cluster-maxzoom=`_zoom_: Max zoom on which to cluster points if clustering is enabled.
* `-kg` or `--cluster-maxzoom=g`: Set `--cluster-maxzoom=` to `maxzoom - 1` so that all features are visible at the maximum zoom level.
* `--preserve-point-density-threshold=`_level_: At the low zoom levels, do not reduce point density below the specified _level_, even if the specified drop rate would normally call for it, so that low-density areas of the map do not appear blank. The unit is the distance between preserved points, as a fraction of the size of a tile. Values of 32 or 64 are probably appropriate for typical marker sizes.
* `--preserve-multiplier-density-threshold=`_level_: As with `--preserve-point-density-threshold`, but for the additional features retained by `--retain-points-multiplier`: features that would otherwise be dropped are instead added to the multiplier cluster if they are farther than the specified _level_ from the previous retained feature, so that sparse areas still have features available to be thinned to. The unit is the same as for `--preserve-point-density-threshold`.
### Dropping a fraction of features to keep under tile size limits
@@ -491,11 +484,10 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
* `-an` or `--drop-smallest-as-needed`: Dynamically drop the smallest features (physically smallest: the shortest lines or the smallest polygons) from each zoom level to keep large tiles under the 500K size limit.
* `--drop-by-attribute-as-needed=`_attribute_: Dynamically drop features with the lowest values of the specified numeric _attribute_ from each zoom level to keep large tiles under the 500K size limit. Use `--drop-by-attribute-order=desc` to instead drop features with the highest values.
* `-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.
* `-aS` 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.)
* `-aD` 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.)
* `-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, a `"point_count_abbreviated"` attribute containing that count abbreviated for display (for example `1.2k` or `15k`), 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 (unless you use `--keep-point-cluster-position`); otherwise, one of the original features will be left as the representative.
* `-aa` or `--keep-point-cluster-position`: When clustering points, leave the representative feature at the location of the first point of the cluster instead of moving it to the average of the clustered points' locations.
* `-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
@@ -517,7 +509,7 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
### Attempts to improve shared polygon boundaries
* `-ab` or `--detect-shared-borders`: DEPRECATED. In the manner of [TopoJSON](https://github.com/mbostock/topojson/wiki/Introduction), detect borders that are shared between multiple polygons and simplify them identically in each polygon. This takes more time and memory than considering each polygon individually. Use `--no-simplification-of-shared-nodes` instead, which is faster and more correct.
* `-ab` or `--detect-shared-borders`: DEPRECATED. In the manner of [TopoJSON](https://github.com/mbostock/topojson/wiki/Introduction), detect borders that are shared between multiple polygons and simplify them identically in each polygon. This takes more time and memory than considering each polygon individually. Use `no-simplification-of-shared-nodes` instead, which is faster and more correct.
* `-aL` or `--grid-low-zooms`: At all zoom levels below _maxzoom_, snap all lines and polygons to a stairstep grid instead of allowing diagonals. You will also want to specify a tile resolution, probably `-D8`. This option provides a way to display continuous parcel, gridded, or binned data at low zooms without overwhelming the tiles with tiny polygons, since features will either get stretched out to the grid unit or lost entirely, depending on how they happened to be aligned in the original data. You probably don't want to use this.
### Controlling clipping to tile boundaries
@@ -576,16 +568,9 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
* `-q` or `--quiet`: Work quietly instead of reporting progress or warning messages
* `-Q` or `--no-progress-indicator`: Don't report progress, but still give warnings
* `-U` _seconds_ or `--progress-interval=`_seconds_: Don't report progress more often than the specified number of _seconds_.
* `-u` or `--json-progress`: like `--quiet` but logs progress as a JSON object. Use in combination with `-U`.
### Version
* `-u` or `--json-progress`: like `-quiet` but logs progress as a JSON object. Use in combination with `-U`.
* `-v` or `--version`: Report Tippecanoe's version number
### Help
* `-H` or `--help`: List the available options and exit
### Filters
* `-C` _command_ or `--prefilter=`_command_: Specify a shell filter command to be run at the start of assembling each tile
@@ -689,11 +674,11 @@ Geometric simplifications
At every zoom level, line and polygon features are subjected to Douglas-Peucker
simplification to the resolution of the tile.
For point features, it keeps only 1/2.5 of the dots for each zoom level below the
For point features, it drops 1/2.5 of the dots for each zoom level above the
point base zoom (which is normally the same as the `-z` max zoom, but can be
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.
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),
@@ -719,13 +704,8 @@ lower resolutions before failing if it still doesn't fit.
Development
-----------
Requires sqlite3 and zlib (should already be installed on MacOS).
The manpage is generated from this README by `make docs`, which uses
[go-md2man](https://github.com/cpuguy83/go-md2man) (`brew install go-md2man` or
`apt-get install go-md2man`). You don't have to run it yourself: CI regenerates the
manpage and fails if the committed copy doesn't match, so it will tell you if an
edit here needs `make docs` run against it.
Requires sqlite3 and zlib (should already be installed on MacOS). Rebuilding the manpage
uses md2man (`gem install md2man`).
Linux:
@@ -739,16 +719,15 @@ and perhaps
make install
Tippecanoe requires features from the 2017 C++ standard (it is built with `-std=c++17`).
If your compiler is older than that, you will need to install a newer one. On MacOS, updating
to the latest XCode should get you a new enough version of `clang++`. On Linux, you should be
able to upgrade `g++` with
Tippecanoe now requires features from the 2011 C++ standard. If your compiler is older than
that, you will need to install a newer one. On MacOS, updating to the latest XCode should
get you a new enough version of `clang++`. On Linux, you should be able to upgrade `g++` with
```sh
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -y
sudo apt-get install -y g++-9
export CXX=g++-9
sudo apt-get install -y g++-5
export CXX=g++-5
```
Docker Image
@@ -801,14 +780,11 @@ The options are:
* `-o` *out.mbtiles*, *out.pmtiles* or `--output=`*out.mbtiles*: Write the new tiles to the specified .mbtiles file.
* `-e` *directory* or `--output-to-directory=`*directory*: Write the new tiles to the specified directory instead of to an mbtiles file.
* `-f` or `--force`: Remove *out.mbtiles* if it already exists.
### Input tilesets
* `-r` *file* or `--read-from=`*file*: Read the list of input tilesets from the named *file*, one filename per line, instead of naming them all on the command line.
* `-r` or `--read-from`: list of input mbtiles to read from.
### Overzooming
* `-O` or `--overzoom`: If one of the source tilesets has a larger maxzoom than the others, scale up tiles from the tilesets with the lower maxzooms so they will all have the same maxzoom in the output tileset.
* `--overzoom`: If one of the source tilesets has a larger maxzoom than the others, scale up tiles from the tilesets with the lower maxzooms so they will all have the same maxzoom in the output tileset.
* `--buffer=`_pixels_ or `-b` _pixels_: Set the size of the tile buffer in the overzoomed tiles.
### Tileset description and attribution
@@ -837,8 +813,6 @@ The options are:
* `-x` *key* or `--exclude=`*key*: Remove attributes named *key* from the output. You can use this to remove the field you are matching against if you no longer need it after joining, or to remove any other attributes you don't want. You can use multiple `-x` options to remove multiple attributes.
* `-X` or `--exclude-all`: Remove all attributes from the output.
* `-y` *key* or `--include=`*key*: Remove all attributes except for those named *key* from the output. You can use multiple `-y` options to retain multiple attributes.
* `--exclude-all-tile-attributes`: Remove the attributes that were already present in the source tiles, keeping only any that are joined from a CSV with `-c`.
* `--exclude-all-tile-geometries`: Copy the features' attributes but not their geometries, so the output tiles describe the features without locating them.
* `-i` or `--if-matched`: Only include features that matched the CSV.
* `-j` *filter* or `--feature-filter`=*filter*: Check features against a per-layer filter (as defined in the [Mapbox GL Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/#other-filter)) and only include those that match. Any features in layers that have no filter specified will be passed through. Filters for the layer `"*"` apply to all layers.
* `-J` *filter-file* or `--feature-filter-file`=*filter-file*: Like `-j`, but read the filter from a file.
@@ -853,10 +827,6 @@ The options are:
* `--tile-stats-sample-values-limit=`*count*: Calculate `tilestats` attribute statistics based on *count* values instead of the default 1000.
* `--tile-stats-values-limit=`*count*: Report *count* unique attribute values in `tilestats` instead of the default 100.
### Progress indicator
* `-q` or `--quiet`: Work quietly instead of reporting progress
Because tile-join just copies the geometries to the new .mbtiles without processing them
(except to rescale the extents if necessary),
it doesn't have any of tippecanoe's recourses if the new tiles are bigger than the 500K tile limit.
@@ -947,10 +917,8 @@ resolutions.
* `-c` or `--tag-layer-and-zoom`: Include each feature's layer and zoom level as part of its `tippecanoe` object rather than as a FeatureCollection wrapper
* `-S` or `--stats`: Just report statistics about each tile's size and the number of features in it, as a JSON structure.
* `-f` or `--force`: Decode tiles even if polygon ring order or closure problems are detected
* `-I` or `--integer-coordinates`: Report coordinates in integer tile coordinates
* `-F` or `--fractional-coordinates`: Report coordinates as a fraction of the tile extent
* `-y` _attribute_ or `--include=`*attribute*: Include only the named attributes in the decoded features, excluding all those not explicitly named. (Multiple `-y` options can be specified.)
* `-x` _name_ or `--exclude-metadata-row=`*name*: Omit the named row from the tileset metadata in the output. (Multiple `-x` options can be specified.)
* `-I` or `--integer`: Report coordinates in integer tile coordinates
* `-F` or `--fraction`: Report coordinates as a fraction of the tile extent
tippecanoe-json-tool
====================
@@ -1037,19 +1005,10 @@ and produces tile `outz/outx/outy` of `out.mvt.gz` from them.
### Options
* `-o` *file* or `--output=`*file*: Write the output tile to the named *file*.
* `-t` _zoom_`/`_x_`/`_y_ or `--source-tile=`_zoom_`/`_x_`/`_y_: Specify the coordinates of the tile to produce, so that several input tiles, each followed by its own _zoom_`/`_x_`/`_y_, can be combined into it, as in the second example above.
* `-b` *buffer* or `--buffer=`*buffer*: Set the tile buffer in the output tile (default 5)
* `-d` *detail* or `--full-detail=`*detail*: Set the detail of the output tile (default 12)
* `-y` *attribute* or `--include=`*attribute*: Retain the specified *attribute* in the output features. All attributes that are not named in a `-y` option will be removed.
* `-x` *attribute* or `--exclude=`*attribute*: Remove the specified *attribute* from the output features.
* `--exclude-prefix=`*prefix*: Remove any attribute whose name begins with the specified *prefix* from the output features.
* `-j` *filter* or `--feature-filter=`*filter*: Filter features using the same expression syntax as in tippecanoe.
* `-J` *filter-file* or `--feature-filter-file=`*filter-file*: Like `-j`, but read the filter from a file.
* `-m` or `--filter-points-multiplier`: If a tile was created with the `--retain-points-multiplier` option, thin the tile back down to its normal feature count during overzooming. The first feature from each cluster will be retained, unless `-j` is used to specify a filter, in which case the first matching filter from each cluster will be retained instead.
* `-S` *scale* or `--line-simplification=`*scale*: Simplify lines and polygons in the output tile, multiplying the standard tolerance by *scale*. The default of 0 means not to simplify at all.
* `--tiny-polygon-size=`*size*: Combine the area of very small polygons into small squares of the specified *size* that represent their combined area, as `tippecanoe` does. The default of 0 means not to do tiny polygon reduction at all.
* `--deduplicate-by-id`: When several input tiles are combined, include only the first feature with any given feature ID within each layer, so that features that appear in more than one input tile are not duplicated in the output.
* `-b` *buffer*: Set the tile buffer in the output tile (default 5)
* `-d` *detail*: Set the detail of the output tile (default 12)
* `-y` *attribute*: Retain the specified *attribute* in the output features. All attributes that are not named in a `-y` option will be removed.
* `-j` *filter*: Filter features using the same expression syntax as in tippecanoe.
* `-m`: If a tile was created with the `--retain-points-multiplier` option, thin the tile back down to its normal feature count during overzooming. The first feature from each cluster will be retained, unless `-j` is used to specify a filter, in which case the first matching filter from each cluster will be retained instead.
* `--preserve-input-order`: Restore a set of filtered features to its original input order
* `-E` *attribute*`:`*operation* or `--accumulate-attribute=`*attribute*`:`*operation*: Behaves as in `tippecanoe` to sum attributes from the features of a multiplier cluster that are not included in the final output. The attributes from features that are filtered away with `-j` are *not* accumulated onto the output feature.
* `--no-tile-compression`: Don't compress the PBF vector tile data in the output tile.
* `--accumulate-attribute`: Behaves as in `tippecanoe` to sum attributes from the features of a multiplier cluster that are not included in the final output. The attributes from features that are filtered away with `-j` are *not* accumulated onto the output feature.
+17 -10
View File
@@ -5,7 +5,6 @@
#include "serial.hpp"
#include "jsonpull/jsonpull.h"
#include "milo/dtoa_milo.h"
#include "raii.hpp"
std::map<std::string, attribute_op> numeric_operations = {
{"sum", op_sum},
@@ -34,7 +33,8 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
} else if (type == "count") {
t = op_count;
} else {
throw_tippecanoe_error(EXIT_ARGS, "Attribute method (%s) must be sum, product, mean, max, min, concat, comma, or count", type.c_str());
fprintf(stderr, "Attribute method (%s) must be sum, product, mean, max, min, concat, comma, or count\n", type.c_str());
exit(EXIT_ARGS);
}
attribute_accum.insert(std::pair<std::string, attribute_op>(name, t));
@@ -42,15 +42,17 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv) {
if (*arg == '{') {
unique_json_pull jp(json_begin_string(arg));
json_object *o = json_read_tree(jp.get());
json_pull *jp = json_begin_string(arg);
json_object *o = json_read_tree(jp);
if (o == NULL) {
throw_tippecanoe_error(EXIT_JSON, "%s: -E%s: %s", *argv, arg, jp->error);
fprintf(stderr, "%s: -E%s: %s\n", *argv, arg, jp->error);
exit(EXIT_JSON);
}
if (o->type != JSON_HASH) {
throw_tippecanoe_error(EXIT_JSON, "%s: -E%s: not a JSON object", *argv, arg);
fprintf(stderr, "%s: -E%s: not a JSON object\n", *argv, arg);
exit(EXIT_JSON);
}
for (size_t i = 0; i < o->value.object.length; i++) {
@@ -58,22 +60,26 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
json_object *v = o->value.object.values[i];
if (k->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_JSON, "%s: -E%s: key %zu not a string", *argv, arg, i);
fprintf(stderr, "%s: -E%s: key %zu not a string\n", *argv, arg, i);
exit(EXIT_JSON);
}
if (v->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_JSON, "%s: -E%s: value %zu not a string", *argv, arg, i);
fprintf(stderr, "%s: -E%s: value %zu not a string\n", *argv, arg, i);
exit(EXIT_JSON);
}
set_attribute_accum(attribute_accum, k->value.string.string, v->value.string.string);
}
json_free(o);
json_end(jp);
return;
}
const char *s = strchr(arg, ':');
if (s == NULL) {
throw_tippecanoe_error(EXIT_ARGS, "-E%s option must be in the form -Ename:method", arg);
fprintf(stderr, "-E%s option must be in the form -Ename:method\n", arg);
exit(EXIT_ARGS);
}
std::string name = std::string(arg, s - arg);
@@ -165,7 +171,8 @@ static void preserve_attribute1(attribute_op const &op, std::string const &key,
break;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "can't happen: operation that isn't used by --accumulate-numeric-attributes");
fprintf(stderr, "can't happen: operation that isn't used by --accumulate-numeric-attributes\n");
exit(EXIT_IMPOSSIBLE);
}
full_keys.push_back(key_pool.pool(key));
+24 -12
View File
@@ -46,7 +46,8 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
tmp = clip_poly1(tmp, minx, miny, maxx, maxy, ax, ay, bx, by, edge_nodes, prevent_simplify_shared_nodes);
if (tmp.size() > 0) {
if (tmp[0].first != tmp[tmp.size() - 1].first || tmp[0].second != tmp[tmp.size() - 1].second) {
throw_tippecanoe_error(EXIT_FAILURE, "Internal error: Polygon ring not closed");
fprintf(stderr, "Internal error: Polygon ring not closed\n");
exit(EXIT_FAILURE);
}
}
for (size_t k = 0; k < tmp.size(); k++) {
@@ -59,7 +60,8 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
i = j - 1;
} else {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Unexpected operation in polygon %d", (int) geom[i].op);
fprintf(stderr, "Unexpected operation in polygon %d\n", (int) geom[i].op);
exit(EXIT_IMPOSSIBLE);
}
}
@@ -244,7 +246,8 @@ static void decode_clipped(mapbox::geometry::multi_polygon<long long> &t, drawve
double area = get_area(ring, 0, ring.size());
if ((j == 0 && area < 0) || (j != 0 && area > 0)) {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Ring area has wrong sign: %f for %zu", area, j);
fprintf(stderr, "Ring area has wrong sign: %f for %zu\n", area, j);
exit(EXIT_IMPOSSIBLE);
}
for (size_t k = 0; k < ring.size(); k++) {
@@ -359,7 +362,8 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
fprintf(f, "\n\n\n\n\n");
fclose(f);
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: Polygon cleaning failed. Log in /tmp/wagyu.log");
fprintf(stderr, "Internal error: Polygon cleaning failed. Log in /tmp/wagyu.log\n");
exit(EXIT_IMPOSSIBLE);
}
if (scale != 1) {
@@ -435,7 +439,8 @@ drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds) {
result.clear();
wagyu.execute(mapbox::geometry::wagyu::clip_type_intersection, result, mapbox::geometry::wagyu::fill_type_positive, mapbox::geometry::wagyu::fill_type_positive);
} catch (std::runtime_error &e) {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: Polygon clipping failed");
fprintf(stderr, "Internal error: Polygon clipping failed\n");
exit(EXIT_IMPOSSIBLE);
}
}
@@ -630,7 +635,8 @@ double get_area_scaled(const drawvec &geom, size_t i, size_t j) {
}
}
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "get_area_scaled: can't happen");
fprintf(stderr, "get_area_scaled: can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
double get_area(const drawvec &geom, size_t i, size_t j) {
@@ -748,7 +754,8 @@ static bool inside(std::pair<double, double> d, int edge, long long minx, long l
return d.first > minx;
}
throw_tippecanoe_error(EXIT_FAILURE, "internal error inside");
fprintf(stderr, "internal error inside\n");
exit(EXIT_FAILURE);
}
static std::pair<double, double> intersect(std::pair<double, double> a, std::pair<double, double> b, int edge, long long minx, long long miny, long long maxx, long long maxy) {
@@ -766,7 +773,8 @@ static std::pair<double, double> intersect(std::pair<double, double> a, std::pai
return std::pair<double, double>(minx, (a.second + (double) (b.second - a.second) * (minx - a.first) / (b.first - a.first)));
}
throw_tippecanoe_error(EXIT_FAILURE, "internal error intersecting");
fprintf(stderr, "internal error intersecting\n");
exit(EXIT_FAILURE);
}
// http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm
@@ -902,7 +910,8 @@ void douglas_peucker(drawvec &geom, int start, int n, double e, size_t kept, siz
std::stack<int> recursion_stack;
if (!geom[start + 0].necessary || !geom[start + n - 1].necessary) {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "endpoints not marked necessary");
fprintf(stderr, "endpoints not marked necessary\n");
exit(EXIT_IMPOSSIBLE);
}
int prev = 0;
@@ -1228,10 +1237,12 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
try {
bool was_compressed;
if (!tile.decode(t.tile, was_compressed)) {
throw_tippecanoe_error(EXIT_MVT, "Couldn't parse tile %d/%u/%u", t.z, t.x, t.y);
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", t.z, t.x, t.y);
exit(EXIT_MVT);
}
} catch (std::exception const &e) {
throw_tippecanoe_error(EXIT_PROTOBUF, "PBF decoding error in tile %d/%u/%u", t.z, t.x, t.y);
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", t.z, t.x, t.y);
exit(EXIT_PROTOBUF);
}
source_tile out;
@@ -1881,7 +1892,8 @@ drawvec fix_polygon(const drawvec &geom, bool use_winding, bool reverse_winding)
i = j - 1;
outer = 0;
} else {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: polygon ring begins with %d, not moveto", geom[i].op);
fprintf(stderr, "Internal error: polygon ring begins with %d, not moveto\n", geom[i].op);
exit(EXIT_IMPOSSIBLE);
}
}
+28 -52
View File
@@ -24,7 +24,6 @@
#include "dirtiles.hpp"
#include "pmtiles_file.hpp"
#include "errors.hpp"
#include "usage.hpp"
int minzoom = 0;
int maxzoom = 32;
@@ -550,46 +549,12 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
}
}
static const struct option long_options[] = {
{"Tiles to decode", 0, 0, 0},
{"minimum-zoom", required_argument, 0, 'Z'},
{"maximum-zoom", required_argument, 0, 'z'},
{"layer", required_argument, 0, 'l'},
{"Output format", 0, 0, 0},
{"projection", required_argument, 0, 's'},
{"fractional-coordinates", no_argument, 0, 'F'},
{"integer-coordinates", no_argument, 0, 'I'},
{"tag-layer-and-zoom", no_argument, 0, 'c'},
{"stats", no_argument, 0, 'S'},
{"Filtering the output", 0, 0, 0},
{"include", required_argument, 0, 'y'},
{"exclude-metadata-row", required_argument, 0, 'x'},
{"Ignoring errors in the input", 0, 0, 0},
{"force", no_argument, 0, 'f'},
{0, 0, 0, 0},
};
// the options above, with the usage message headings removed
static struct option real_long_options[sizeof(long_options) / sizeof(long_options[0])];
void usage(char **argv) {
static const char *const forms[] = {
"[options] tileset",
"[options] tileset zoom x y",
NULL,
};
print_usage(stderr, argv[0], forms, long_options, NULL);
fprintf(stderr, "\nThe tileset can be an .mbtiles or .pmtiles file or a directory of tiles,\n");
fprintf(stderr, "or, if zoom/x/y is specified, a single .pbf tile.\n");
fprintf(stderr, "Usage: %s [-s projection] [-Z minzoom] [-z maxzoom] [-l layer ...] file.mbtiles [zoom x y]\n", argv[0]);
exit(EXIT_ARGS);
}
int inner_main(int argc, char **argv) {
int main(int argc, char **argv) {
extern int optind;
extern char *optarg;
int i;
@@ -599,10 +564,33 @@ int inner_main(int argc, char **argv) {
std::set<std::string> exclude_meta;
int coordinate_mode = 0;
strip_usage_headings(long_options, real_long_options);
std::string getopt_str = getopt_string(real_long_options);
struct option long_options[] = {
{"projection", required_argument, 0, 's'},
{"fractional-coordinates", no_argument, 0, 'F'},
{"integer-coordinates", no_argument, 0, 'I'},
{"maximum-zoom", required_argument, 0, 'z'},
{"minimum-zoom", required_argument, 0, 'Z'},
{"layer", required_argument, 0, 'l'},
{"tag-layer-and-zoom", no_argument, 0, 'c'},
{"stats", no_argument, 0, 'S'},
{"force", no_argument, 0, 'f'},
{"exclude-metadata-row", required_argument, 0, 'x'},
{"include", required_argument, 0, 'y'},
{0, 0, 0, 0},
};
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, NULL)) != -1) {
std::string getopt_str;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val > ' ') {
getopt_str.push_back(long_options[lo].val);
if (long_options[lo].has_arg == required_argument) {
getopt_str.push_back(':');
}
}
}
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
switch (i) {
case 0:
break;
@@ -666,15 +654,3 @@ int inner_main(int argc, char **argv) {
return 0;
}
int main(int argc, char **argv) {
try {
return inner_main(argc, argv);
} catch (tippecanoe_error &e) {
fprintf(stderr, "%s\n", e.what());
return e.exit_code;
} catch (std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
}
+2 -19
View File
@@ -1,11 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string>
#include <sqlite3.h>
#include "errors.hpp"
#include "usage.hpp"
void enumerate(char *fname) {
sqlite3 *db;
@@ -51,20 +48,8 @@ void enumerate(char *fname) {
}
}
// there are no options, but the table is still what the usage message
// and the getopt string are derived from, so that they will keep up
// with any options that are added later
static const struct option long_options[] = {
{0, 0, 0, 0},
};
void usage(char **argv) {
static const char *const forms[] = {
"file.mbtiles ...",
NULL,
};
print_usage(stderr, argv[0], forms, long_options, NULL);
fprintf(stderr, "Usage: %s file.mbtiles ...\n", argv[0]);
exit(EXIT_ARGS);
}
@@ -73,9 +58,7 @@ int main(int argc, char **argv) {
// extern char *optarg;
int i;
std::string getopt_str = getopt_string(long_options);
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
while ((i = getopt(argc, argv, "")) != -1) {
usage(argv);
}
-31
View File
@@ -1,31 +0,0 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include "errors.hpp"
[[noreturn]] void throw_tippecanoe_error(int code, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
char *msg = NULL;
if (vasprintf(&msg, fmt, ap) < 0) {
va_end(ap);
throw tippecanoe_error(code, "error (could not format message)");
}
va_end(ap);
std::string s(msg);
free(msg);
// Remove trailing newline if present (stderr messages often have one)
while (s.size() > 0 && s.back() == '\n') {
s.pop_back();
}
throw tippecanoe_error(code, s);
}
[[noreturn]] void throw_perror(int code, const char *msg) {
throw tippecanoe_error(code, std::string(msg) + ": " + strerror(errno));
}
-36
View File
@@ -1,6 +1,3 @@
#ifndef ERRORS_HPP
#define ERRORS_HPP
#define EXIT_INCOMPLETE 100
#define EXIT_ARGS 101
#define EXIT_CLOSE 102
@@ -24,36 +21,3 @@
#define EXIT_WRITE 120
// avoid 124, 125, 126, 127, 137, which are used by GNU timeout
#include <stdexcept>
#include <string>
#include <exception>
class tippecanoe_error : public std::runtime_error {
public:
int exit_code;
tippecanoe_error(int code, const std::string &message)
: std::runtime_error(message), exit_code(code) {
}
};
// Format and throw a tippecanoe_error. Use in place of fprintf(stderr,...)+exit().
[[noreturn]] void throw_tippecanoe_error(int code, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
// Throw from errno-based errors (replaces perror()+exit() pattern)
[[noreturn]] void throw_perror(int code, const char *msg);
// Check the void* return value from pthread_join. If a thread caught an
// exception, the return value is a heap-allocated std::exception_ptr.
// This re-throws it on the joining thread, or does nothing if retval is NULL.
inline void rethrow_if_thread_failed(void *retval) {
if (retval != NULL) {
std::exception_ptr *ep = (std::exception_ptr *) retval;
std::exception_ptr copy = *ep;
delete ep;
std::rethrow_exception(copy);
}
}
#endif
+50 -27
View File
@@ -6,7 +6,6 @@
#include "mvt.hpp"
#include "evaluator.hpp"
#include "errors.hpp"
#include "raii.hpp"
#include "milo/dtoa_milo.h"
#include "text.hpp"
@@ -49,7 +48,8 @@ int compare(mvt_value const &one, json_object *two, bool &fail) {
break;
case mvt_no_such_key:
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: bad mvt type %d", one.type);
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
if (v < two->value.number.number) {
@@ -84,7 +84,8 @@ int compare(mvt_value const &one, json_object *two, bool &fail) {
break;
}
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: bad mvt type %d", one.type);
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
exit(EXIT_IMPOSSIBLE);
}
// 0: false
@@ -118,33 +119,39 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
}
if (f == NULL || f->type != JSON_ARRAY) {
throw_tippecanoe_error(EXIT_FILTER, "Filter is not an array: %s", json_stringify(f));
fprintf(stderr, "Filter is not an array: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (f->value.array.length < 1) {
throw_tippecanoe_error(EXIT_FILTER, "Array too small in filter: %s", json_stringify(f));
fprintf(stderr, "Array too small in filter: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (f->value.array.array[0]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "Filter operation is not a string: %s", json_stringify(f));
fprintf(stderr, "Filter operation is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (strcmp(f->value.array.array[0]->value.string.string, "has") == 0 ||
strcmp(f->value.array.array[0]->value.string.string, "!has") == 0) {
if (f->value.array.length != 2) {
throw_tippecanoe_error(EXIT_FILTER, "Wrong number of array elements in filter: %s", json_stringify(f));
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (strcmp(f->value.array.array[0]->value.string.string, "has") == 0) {
if (f->value.array.array[1]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "\"has\" key is not a string: %s", json_stringify(f));
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;
}
if (strcmp(f->value.array.array[0]->value.string.string, "!has") == 0) {
if (f->value.array.array[1]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "\"!has\" key is not a string: %s", json_stringify(f));
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;
}
@@ -157,10 +164,12 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
strcmp(f->value.array.array[0]->value.string.string, "<") == 0 ||
strcmp(f->value.array.array[0]->value.string.string, "<=") == 0) {
if (f->value.array.length != 3) {
throw_tippecanoe_error(EXIT_FILTER, "Wrong number of array elements in filter: %s", json_stringify(f));
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (f->value.array.array[1]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "comparison key is not a string: %s", json_stringify(f));
fprintf(stderr, "comparison key is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
mvt_value ff = feature(std::string(f->value.array.array[1]->value.string.string));
@@ -214,7 +223,8 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
return cmp <= 0;
}
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: can't happen: %s", json_stringify(f));
fprintf(stderr, "Internal error: can't happen: %s\n", json_stringify(f));
exit(EXIT_IMPOSSIBLE);
}
if (strcmp(f->value.array.array[0]->value.string.string, "all") == 0 ||
@@ -256,11 +266,13 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
if (strcmp(f->value.array.array[0]->value.string.string, "in") == 0 ||
strcmp(f->value.array.array[0]->value.string.string, "!in") == 0) {
if (f->value.array.length < 2) {
throw_tippecanoe_error(EXIT_FILTER, "Array too small in filter: %s", json_stringify(f));
fprintf(stderr, "Array too small in filter: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (f->value.array.array[1]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "\"!in\" key is not a string: %s", json_stringify(f));
fprintf(stderr, "\"!in\" key is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
mvt_value ff = feature(std::string(f->value.array.array[1]->value.string.string));
@@ -309,11 +321,13 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
if (strcmp(f->value.array.array[0]->value.string.string, "attribute-filter") == 0) {
if (f->value.array.length != 3) {
throw_tippecanoe_error(EXIT_FILTER, "Wrong number of array elements in filter: %s", json_stringify(f));
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
if (f->value.array.array[1]->type != JSON_STRING) {
throw_tippecanoe_error(EXIT_FILTER, "\"attribute-filter\" key is not a string: %s", json_stringify(f));
fprintf(stderr, "\"attribute-filter\" key is not a string: %s\n", json_stringify(f));
exit(EXIT_FILTER);
}
bool ok = eval(feature, f->value.array.array[2], exclude_attributes, unidecode_data) > 0;
@@ -324,12 +338,14 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
return true;
}
throw_tippecanoe_error(EXIT_FILTER, "Unknown filter %s", json_stringify(f));
fprintf(stderr, "Unknown filter %s\n", json_stringify(f));
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, std::vector<std::string> const &unidecode_data) {
if (filter == NULL || filter->type != JSON_HASH) {
throw_tippecanoe_error(EXIT_JSON, "Error: filter is not a hash: %s", json_stringify(filter));
fprintf(stderr, "Error: filter is not a hash: %s\n", json_stringify(filter));
exit(EXIT_JSON);
}
bool ok = true;
@@ -349,27 +365,34 @@ bool evaluate(std::function<mvt_value(std::string const &)> feature, std::string
}
json_object *read_filter(const char *fname) {
unique_file fp(fopen(fname, "r"));
if (fp.get() == NULL) {
throw_perror(EXIT_OPEN, fname);
FILE *fp = fopen(fname, "r");
if (fp == NULL) {
perror(fname);
exit(EXIT_OPEN);
}
unique_json_pull jp(json_begin_file(fp.get()));
json_object *filter = json_read_tree(jp.get());
json_pull *jp = json_begin_file(fp);
json_object *filter = json_read_tree(jp);
if (filter == NULL) {
throw_tippecanoe_error(EXIT_JSON, "%s: %s", fname, jp.get()->error);
fprintf(stderr, "%s: %s\n", fname, jp->error);
exit(EXIT_JSON);
}
json_disconnect(filter);
json_end(jp);
fclose(fp);
return filter;
}
json_object *parse_filter(const char *s) {
unique_json_pull jp(json_begin_string(s));
json_object *filter = json_read_tree(jp.get());
json_pull *jp = json_begin_string(s);
json_object *filter = json_read_tree(jp);
if (filter == NULL) {
throw_tippecanoe_error(EXIT_JSON, "Could not parse filter %s\n%s", s, jp.get()->error);
fprintf(stderr, "Could not parse filter %s\n", s);
fprintf(stderr, "%s\n", jp->error);
exit(EXIT_JSON);
}
json_disconnect(filter);
json_end(jp);
return filter;
}
+2 -1
View File
@@ -508,7 +508,8 @@ drawvec stairstep(drawvec &geom, int z, int detail) {
// out.push_back(draw(VT_LINETO, xx, yy));
} else {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Can't happen: stairstepping lineto with no moveto");
fprintf(stderr, "Can't happen: stairstepping lineto with no moveto\n");
exit(EXIT_IMPOSSIBLE);
}
}
+25 -48
View File
@@ -13,7 +13,6 @@
#include "geojson-loop.hpp"
#include "milo/dtoa_milo.h"
#include "errors.hpp"
#include "usage.hpp"
int fail = EXIT_SUCCESS;
bool wrap = false;
@@ -365,7 +364,7 @@ void join_csv(json_object *j) {
vo->value.number.large_unsigned = 0;
vo->value.number.large_signed = 0;
} else {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "unexpected JSON attribute type %d", attr_type);
abort();
}
properties->value.object.keys[properties->value.object.length] = ko;
@@ -408,45 +407,34 @@ void process(FILE *fp, const char *fname) {
json_end(jp);
}
static const struct option long_options[] = {
{"Wrapping the output", 0, 0, 0},
{"wrap", no_argument, 0, 'w'},
{"Sorting and joining", 0, 0, 0},
{"extract", required_argument, 0, 'e'},
{"csv", required_argument, 0, 'c'},
{"empty-csv-columns-are-null", no_argument, &pe, 1},
{"", 0, 0, 0},
{"prevent", required_argument, 0, 'p'},
{0, 0, 0, 0},
};
// the options above, with the usage message headings removed
static struct option real_long_options[sizeof(long_options) / sizeof(long_options[0])];
void usage(char **argv) {
static const char *const forms[] = {
"[options] [file.json ...]",
NULL,
};
print_usage(stderr, argv[0], forms, long_options, NULL);
fprintf(stderr, "\nIf no files are named, the JSON is read from the standard input.\n");
exit(EXIT_ARGS);
}
int inner_main(int argc, char **argv) {
int main(int argc, char **argv) {
const char *csv = NULL;
strip_usage_headings(long_options, real_long_options);
std::string getopt_str = getopt_string(real_long_options);
struct option long_options[] = {
{"wrap", no_argument, 0, 'w'},
{"extract", required_argument, 0, 'e'},
{"csv", required_argument, 0, 'c'},
{"empty-csv-columns-are-null", no_argument, &pe, 1},
{"prevent", required_argument, 0, 'p'},
{0, 0, 0, 0},
};
std::string getopt_str;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val > ' ') {
getopt_str.push_back(long_options[lo].val);
if (long_options[lo].has_arg == required_argument) {
getopt_str.push_back(':');
}
}
}
extern int optind;
int i;
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, NULL)) != -1) {
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
switch (i) {
case 0:
break;
@@ -473,7 +461,8 @@ int inner_main(int argc, char **argv) {
break;
default:
usage(argv);
fprintf(stderr, "Unexpected option -%c\n", i);
exit(EXIT_ARGS);
}
}
@@ -520,15 +509,3 @@ int inner_main(int argc, char **argv) {
return fail;
}
int main(int argc, char **argv) {
try {
return inner_main(argc, argv);
} catch (tippecanoe_error &e) {
fprintf(stderr, "%s\n", e.what());
return e.exit_code;
} catch (std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
}
+362 -346
View File
File diff suppressed because it is too large Load Diff
+775 -592
View File
File diff suppressed because it is too large Load Diff
@@ -1296,10 +1296,7 @@ void correct_tree(ring_manager<T>& manager) {
}
if (!found) {
if ((*itr)->is_hole()) {
// No remaining ring contains this hole (degenerate input, e.g. stacked
// duplicate rings from coalesced tiny-polygon placeholders); drop it
// rather than fail the entire tiling run.
remove_ring_and_points(*itr, manager, false);
throw std::runtime_error("Could not properly place hole to a parent.");
} else {
// Assign to base of tree by passing nullptr
reassign_as_child(*itr, static_cast<ring_ptr<T>>(nullptr), manager);
+1 -4
View File
@@ -701,10 +701,7 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
m.strategies_json = stringify_strategies(strategies);
if (std::isinf(droprate)) {
// JSON has no representation for infinity, so substitute a huge
// finite value. The cast is explicit because LLONG_MAX itself is
// not representable as a double and rounds up to 2^63.
droprate = (double) LLONG_MAX;
droprate = LLONG_MAX;
}
if (basezoom != maxzoom || droprate != 2.5 || retain_points_multiplier != 1) {
m.decisions_json = std::string("{") +
+19 -11
View File
@@ -102,7 +102,6 @@ int compress(std::string const &input, std::string &output, bool gz) {
deflate_s.next_out = (Bytef *) (output.data() + length);
int ret = deflate(&deflate_s, Z_FINISH);
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
deflateEnd(&deflate_s);
return -1;
}
length += (increase - deflate_s.avail_out);
@@ -119,7 +118,7 @@ bool mvt_tile::decode(const std::string &message, bool &was_compressed) {
if (is_compressed(message)) {
std::string uncompressed;
if (decompress(message, uncompressed) == 0) {
throw_tippecanoe_error(EXIT_MVT, "Tile decompression failed");
exit(EXIT_MVT);
}
src = uncompressed;
was_compressed = true;
@@ -369,9 +368,11 @@ std::string mvt_tile::encode() {
value_writer.add_bool(7, pbv.numeric_value.bool_value);
break;
case mvt_null:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: trying to write null attribute to tile");
fprintf(stderr, "Internal error: trying to write null attribute to tile\n");
exit(EXIT_IMPOSSIBLE);
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: trying to write undefined attribute type to tile");
fprintf(stderr, "Internal error: trying to write undefined attribute type to tile\n");
exit(EXIT_IMPOSSIBLE);
}
std::shared_ptr<sorted_value> sv = std::make_shared<sorted_value>();
@@ -450,7 +451,8 @@ std::string mvt_tile::encode() {
long long dy = wwy - py;
if (dx < INT_MIN || dx > INT_MAX || dy < INT_MIN || dy > INT_MAX) {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: Geometry delta is too big: %lld,%lld", dx, dy);
fprintf(stderr, "Internal error: Geometry delta is too big: %lld,%lld\n", dx, dy);
exit(EXIT_IMPOSSIBLE);
}
geometry.push_back(protozero::encode_zigzag32(dx));
@@ -462,7 +464,8 @@ std::string mvt_tile::encode() {
} else if (op == mvt_closepath) {
length++;
} else {
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "Internal error: corrupted geometry");
fprintf(stderr, "\nInternal error: corrupted geometry\n");
exit(EXIT_IMPOSSIBLE);
}
}
@@ -511,7 +514,8 @@ bool mvt_value::operator<(const mvt_value &o) const {
return numeric_value.null_value < o.numeric_value.null_value;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "mvt_value::operator<<: can't happen");
fprintf(stderr, "mvt_value::operator<<: can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
}
@@ -546,7 +550,8 @@ bool mvt_value::operator==(const mvt_value &o) const {
return numeric_value.null_value == o.numeric_value.null_value;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "mvt_value::operator==: can't happen");
fprintf(stderr, "mvt_value::operator==: can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
}
@@ -808,7 +813,8 @@ serial_val mvt_value_to_serial_val(mvt_value const &v) {
sv.s = "null";
break;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "unhandled mvt_type %d", v.type);
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
return sv;
@@ -834,7 +840,8 @@ long long mvt_value_to_long_long(mvt_value const &v) {
case mvt_null:
return 0;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "unhandled mvt_type %d", v.type);
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}
@@ -858,7 +865,8 @@ double mvt_value_to_double(mvt_value const &v) {
case mvt_null:
return 0;
default:
throw_tippecanoe_error(EXIT_IMPOSSIBLE, "unhandled mvt_type %d", v.type);
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}
+3 -11
View File
@@ -93,21 +93,12 @@ struct mvt_value {
long long sint_value;
bool bool_value;
int null_value;
// Initializing string_value initializes the union's full width, which
// the static_assert below checks. Setting only a narrower member (a
// double, say) would leave the remaining bytes indeterminate, and the
// implicit copy constructor copies the union as a whole, so those
// bytes get read even when they aren't the member in use.
struct {
size_t off;
size_t len;
} string_value = {0, 0};
} string_value;
} numeric_value;
static_assert(sizeof(numeric_value) == sizeof(numeric_value.string_value),
"string_value must span the whole union, since its default member "
"initializer is what initializes the union");
std::string get_string_value() const {
if (type == mvt_string) {
return std::string(*s, numeric_value.string_value.off, numeric_value.string_value.len);
@@ -204,7 +195,8 @@ struct std::hash<mvt_value> {
return fnv1a(sizeof(int), (void *) &k.numeric_value.null_value);
default:
throw tippecanoe_error(EXIT_IMPOSSIBLE, "mvt_value hash: unexpected type");
fprintf(stderr, "mvt_value hash can't happen\n");
exit(EXIT_IMPOSSIBLE);
}
}
};
+57 -88
View File
@@ -11,8 +11,6 @@
#include "text.hpp"
#include "read_json.hpp"
#include "projection.hpp"
#include "usage.hpp"
#include "raii.hpp"
extern char *optarg;
extern int optind;
@@ -32,81 +30,35 @@ std::set<std::string> keep;
std::set<std::string> exclude;
std::vector<std::string> exclude_prefix;
static const struct option long_options[] = {
{"Output tile", 0, 0, 0},
{"output", required_argument, 0, 'o'},
{"source-tile", required_argument, 0, 't'},
{"no-tile-compression", no_argument, 0, 'd' & 0x1F},
{"Tile resolution", 0, 0, 0},
{"full-detail", required_argument, 0, 'd'},
{"buffer", required_argument, 0, 'b'},
{"Filtering feature attributes", 0, 0, 0},
{"include", required_argument, 0, 'y'},
{"exclude", required_argument, 0, 'x'},
{"exclude-prefix", required_argument, 0, 'x' & 0x1F},
{"Modifying feature attributes", 0, 0, 0},
{"accumulate-attribute", required_argument, 0, 'E'},
{"Filtering features", 0, 0, 0},
{"feature-filter", required_argument, 0, 'j'},
{"feature-filter-file", required_argument, 0, 'J'},
{"filter-points-multiplier", no_argument, 0, 'm'},
{"deduplicate-by-id", no_argument, 0, 'i' & 0x1F},
{"Line and polygon simplification", 0, 0, 0},
{"line-simplification", required_argument, 0, 'S'},
{"tiny-polygon-size", required_argument, 0, 's' & 0x1F},
{"Reordering features within the tile", 0, 0, 0},
{"preserve-input-order", no_argument, 0, 'o' & 0x1F},
{"", 0, 0, 0},
{"unidecode-data", required_argument, 0, 'u' & 0x1F},
{0, 0, 0, 0},
};
// the options above, with the usage message headings removed
static struct option real_long_options[sizeof(long_options) / sizeof(long_options[0])];
void usage(char **argv) {
static const char *const forms[] = {
"[options] tile.pbf.gz oz/ox/oy nz/nx/ny",
"[options] --source-tile=nz/nx/ny tile.pbf.gz oz/ox/oy ...",
NULL,
};
static const struct usage_required_option required[] = {
{"output", "newtile.pbf.gz", 0},
{NULL, NULL, 0},
};
print_usage(stderr, argv[0], forms, long_options, required);
fprintf(stderr, "\nThe tile nz/nx/ny is created from the tile or tiles oz/ox/oy that contain it.\n");
fprintf(stderr, "In the second form, each source tile is named by a file name and a z/x/y pair.\n");
fprintf(stderr, "Usage: %s -o newtile.pbf.gz tile.pbf.gz oz/ox/oy nz/nx/ny\n", argv[0]);
fprintf(stderr, "to create tile nz/nx/ny from tile oz/ox/oy\n");
fprintf(stderr, "Usage: %s -o newtile.pbf.gz -t nz/nx/ny tile.pbf.gz oz/ox/oy tile2.pbf.gz oz2/ox2/oy2\n", argv[0]);
fprintf(stderr, "to create tile nz/nx/ny from tiles oz/ox/oy and oz2/ox2/oy2\n");
exit(EXIT_FAILURE);
}
std::string read_json_file(const char *fname) {
std::string out;
unique_file f(fopen(fname, "r"));
if (!f) {
throw_perror(EXIT_OPEN, fname);
FILE *f = fopen(fname, "r");
if (f == NULL) {
perror(optarg);
exit(EXIT_OPEN);
}
char buf[2000];
size_t nread;
while ((nread = fread(buf, sizeof(char), 2000, f.get())) != 0) {
while ((nread = fread(buf, sizeof(char), 2000, f)) != 0) {
out += std::string(buf, nread);
}
fclose(f);
return out;
}
int inner_main(int argc, char **argv) {
int main(int argc, char **argv) {
int i;
const char *outtile = NULL;
const char *outfile = NULL;
@@ -115,11 +67,41 @@ int inner_main(int argc, char **argv) {
std::vector<input_tile> sources;
strip_usage_headings(long_options, real_long_options);
std::string getopt_str = getopt_string(real_long_options);
struct option long_options[] = {
{"include", required_argument, 0, 'y'},
{"exclude", required_argument, 0, 'x'},
{"exclude-prefix", required_argument, 0, 'x' & 0x1F},
{"full-detail", required_argument, 0, 'd'},
{"buffer", required_argument, 0, 'b'},
{"output", required_argument, 0, 'o'},
{"filter-points-multiplier", no_argument, 0, 'm'},
{"feature-filter", required_argument, 0, 'j'},
{"feature-filter-file", required_argument, 0, 'J'},
{"preserve-input-order", no_argument, 0, 'o' & 0x1F},
{"accumulate-attribute", required_argument, 0, 'E'},
{"unidecode-data", required_argument, 0, 'u' & 0x1F},
{"line-simplification", required_argument, 0, 'S'},
{"tiny-polygon-size", required_argument, 0, 's' & 0x1F},
{"source-tile", required_argument, 0, 't'},
{"no-tile-compression", no_argument, 0, 'd' & 0x1F},
{"deduplicate-by-id", no_argument, 0, 'i' & 0x1F},
{0, 0, 0, 0},
};
std::string getopt_str;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val > ' ') {
getopt_str.push_back(long_options[lo].val);
if (long_options[lo].has_arg == required_argument) {
getopt_str.push_back(':');
}
}
}
int option_index = 0;
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, &option_index)) != -1) {
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, &option_index)) != -1) {
switch (i) {
case 'y':
keep.insert(optarg);
@@ -199,11 +181,6 @@ int inner_main(int argc, char **argv) {
std::vector<input_tile> its;
int nz, nx, ny;
if (outfile == NULL) {
fprintf(stderr, "%s: must specify -o newtile.pbf.gz\n", argv[0]);
usage(argv);
}
if (outtile == NULL) { // single input
if (argc - optind != 3) {
fprintf(stderr, "Wrong number of arguments\n");
@@ -271,14 +248,16 @@ int inner_main(int argc, char **argv) {
char buf[1000];
int len;
unique_file f(fopen(s.tile.c_str(), "rb"));
if (!f) {
throw_perror(EXIT_OPEN, s.tile.c_str());
FILE *f = fopen(s.tile.c_str(), "rb");
if (f == NULL) {
perror(s.tile.c_str());
exit(EXIT_FAILURE);
}
while ((len = fread(buf, sizeof(char), 1000, f.get())) > 0) {
while ((len = fread(buf, sizeof(char), 1000, f)) > 0) {
tile.append(std::string(buf, len));
}
fclose(f);
input_tile t = s;
t.tile = std::move(tile);
@@ -288,24 +267,14 @@ int inner_main(int argc, char **argv) {
out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, std::vector<mvt_layer>(), "", "", SIZE_MAX, std::vector<clipbbox>(), deduplicate_by_id);
}
unique_file f(fopen(outfile, "wb"));
if (!f) {
throw_perror(EXIT_OPEN, outfile);
FILE *f = fopen(outfile, "wb");
if (f == NULL) {
perror(outfile);
exit(EXIT_FAILURE);
}
fwrite(out.c_str(), sizeof(char), out.size(), f.get());
fwrite(out.c_str(), sizeof(char), out.size(), f);
fclose(f);
return 0;
}
int main(int argc, char **argv) {
try {
return inner_main(argc, argv);
} catch (tippecanoe_error &e) {
fprintf(stderr, "%s\n", e.what());
return e.exit_code;
} catch (std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
}
-28
View File
@@ -1,28 +0,0 @@
#ifndef RAII_HPP
#define RAII_HPP
#include <memory>
#include <stdio.h>
#include "jsonpull/jsonpull.h"
// FILE* → unique_file
struct file_closer {
void operator()(FILE *f) {
if (f) {
fclose(f);
}
}
};
using unique_file = std::unique_ptr<FILE, file_closer>;
// json_pull* → unique_json_pull
struct json_pull_closer {
void operator()(json_pull *jp) {
if (jp) {
json_end(jp);
}
}
};
using unique_json_pull = std::unique_ptr<json_pull, json_pull_closer>;
#endif
+14 -13
View File
@@ -14,7 +14,6 @@
#include "milo/dtoa_milo.h"
#include "errors.hpp"
#include "serial.hpp"
#include "raii.hpp"
const char *geometry_names[GEOM_TYPES] = {
"Point",
@@ -100,7 +99,7 @@ void parse_coordinates(int t, json_object *j, drawvec &out, int op, const char *
json_context(j);
fprintf(stderr, "%s:%d: malformed point: ", fname, line);
json_context(feature);
throw_tippecanoe_error(EXIT_JSON, "%s:%d: malformed point", fname, line);
exit(EXIT_JSON);
}
}
@@ -136,7 +135,7 @@ serial_val stringify_value(json_object *value, const char *reading, int line, js
if (err.size() > 0) {
fprintf(stderr, "%s:%d: %s: ", reading, line, err.c_str());
json_context(feature);
throw_tippecanoe_error(EXIT_UTF8, "%s:%d: %s", reading, line, err.c_str());
exit(EXIT_UTF8);
}
} else if (vt == JSON_NUMBER) {
sv.type = mvt_double;
@@ -185,20 +184,20 @@ std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, jso
if (geometry_type == NULL) {
fprintf(stderr, "Filter output:%d: null geometry (additional not reported): ", jp->line);
json_context(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: null geometry (additional not reported)", jp->line);
exit(EXIT_JSON);
}
if (geometry_type->type != JSON_STRING) {
fprintf(stderr, "Filter output:%d: geometry type is not a string: ", jp->line);
json_context(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: geometry type is not a string", jp->line);
exit(EXIT_JSON);
}
json_object *coordinates = json_hash_get(geometry, "coordinates");
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
fprintf(stderr, "Filter output:%d: geometry without coordinates array: ", jp->line);
json_context(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: geometry without coordinates array", jp->line);
exit(EXIT_JSON);
}
int t;
@@ -210,7 +209,7 @@ std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, jso
if (t >= GEOM_TYPES) {
fprintf(stderr, "Filter output:%d: Can't handle geometry type %s: ", jp->line, geometry_type->value.string.string);
json_context(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: Can't handle geometry type %s", jp->line, geometry_type->value.string.string);
exit(EXIT_JSON);
}
drawvec dv;
@@ -306,9 +305,9 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
std::map<std::string, mvt_layer> ret;
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
unique_json_pull jp(json_begin_file(fp));
json_pull *jp = json_begin_file(fp);
while (1) {
json_object *j = json_read(jp.get());
json_object *j = json_read(jp);
if (j == NULL) {
if (jp->error != NULL) {
fprintf(stderr, "Filter output:%d: %s: ", jp->line, jp->error);
@@ -317,7 +316,7 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
} else {
fprintf(stderr, "\n");
}
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: %s", jp->line, jp->error);
exit(EXIT_JSON);
}
json_free(jp->root);
@@ -337,7 +336,7 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
fprintf(stderr, "Filter output:%d: feature without properties hash: ", jp->line);
json_context(j);
json_free(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: feature without properties hash", jp->line);
exit(EXIT_JSON);
}
std::string layername = "unknown";
@@ -365,10 +364,10 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
fprintf(stderr, "Filter output:%d: filtered feature with no geometry: ", jp->line);
json_context(j);
json_free(j);
throw_tippecanoe_error(EXIT_JSON, "Filter output:%d: filtered feature with no geometry", jp->line);
exit(EXIT_JSON);
}
std::pair<int, drawvec> parsed_geometry = parse_geometry(geometry, jp.get(), j, z, x, y, extent, fix_longitudes, true);
std::pair<int, drawvec> parsed_geometry = parse_geometry(geometry, jp, j, z, x, y, extent, fix_longitudes, true);
int t = parsed_geometry.first;
drawvec &dv = parsed_geometry.second;
@@ -405,6 +404,8 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
json_free(j);
}
json_end(jp);
std::vector<mvt_layer> final;
for (auto a : ret) {
final.push_back(a.second);
+2 -10
View File
@@ -665,18 +665,10 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
// VT_POINT extent will be calculated in write_tile from the distance between adjacent features.
}
// Clamp before converting, since converting a double that is out of range
// for a long long is undefined. The bounds are asymmetric: LLONG_MAX is not
// representable as a double and rounds up to 2^63, so the upper bound has to
// be exclusive, while LLONG_MIN is exactly -2^63 and so can be included.
// Areas are signed, so holes that outweigh their rings can make this
// negative.
if (extent >= (double) LLONG_MIN && extent < (double) LLONG_MAX) {
if (extent <= LLONG_MAX) {
sf.extent = (long long) extent;
} else if (extent < 0) {
sf.extent = LLONG_MIN;
} else {
sf.extent = LLONG_MAX; // also the NaN case
sf.extent = LLONG_MAX;
}
if (sst->want_dist && sf.t == VT_POLYGON) {
+9 -6
View File
@@ -8,7 +8,6 @@
#include "milo/dtoa_milo.h"
#include "milo/milo.h"
#include "errors.hpp"
#include "raii.hpp"
/**
* Returns an empty string if `s` is valid utf8;
@@ -136,7 +135,7 @@ int integer_zoom(std::string where, std::string text) {
double d = atof(text.c_str());
if (!std::isfinite(d) || d != floor(d) || d < 0 || d > 32) {
fprintf(stderr, "%s: Expected integer zoom level in \"tippecanoe\" GeoJSON extension, not %s\n", where.c_str(), text.c_str());
throw_tippecanoe_error(EXIT_JSON, "%s: Expected integer zoom level in \"tippecanoe\" GeoJSON extension, not %s", where.c_str(), text.c_str());
exit(EXIT_JSON);
}
return d;
}
@@ -182,7 +181,8 @@ char *dtoa_milo(double val) {
std::string s = milo::dtoa_milo(val);
char *dup = strdup(s.c_str());
if (dup == NULL) {
throw_perror(EXIT_MEMORY, "strdup");
perror("strdup");
exit(EXIT_MEMORY);
}
return dup;
}
@@ -191,22 +191,25 @@ char *dtoa_milo(double val) {
std::vector<std::string> read_unidecode(const char *fname) {
std::string data;
unique_file f(fopen(fname, "rb"));
FILE *f = fopen(fname, "rb");
if (f == NULL) {
throw_perror(EXIT_OPEN, fname);
perror(fname);
exit(EXIT_OPEN);
}
std::string buf;
buf.resize(2000);
while (true) {
size_t nread = fread((void *) buf.c_str(), sizeof(char), buf.size(), f.get());
size_t nread = fread((void *) buf.c_str(), sizeof(char), buf.size(), f);
if (nread == 0) {
break;
}
data.append(buf.c_str(), nread);
}
fclose(f);
std::vector<std::string> out;
out.emplace_back(); // because the data file is 1-indexed
out.emplace_back(); // ascii 001
+56 -93
View File
@@ -44,7 +44,6 @@
#include "geometry.hpp"
#include "thread.hpp"
#include "platform.hpp"
#include "usage.hpp"
int pk = false;
int pC = false;
@@ -893,7 +892,7 @@ void *join_worker(void *v) {
}
void dispatch_tasks(std::map<zxy, std::vector<std::string>> &tasks, std::vector<std::map<std::string, layermap_entry>> &layermaps, sqlite3 *outdb, const char *outdir, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, sqlite3 *db, std::set<std::string> &exclude, std::set<std::string> &include, int ifmatched, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, json_object *filter, struct tileset_reader *readers, double *minlat, double *minlon, double *maxlat, double *maxlon, double *minlon2, double *maxlon2) {
std::vector<pthread_t> pthreads(CPUS);
pthread_t pthreads[CPUS];
std::vector<arg> args;
for (size_t i = 0; i < CPUS; i++) {
@@ -1254,85 +1253,12 @@ void decode(struct tileset_reader *readers, std::map<std::string, layermap_entry
}
}
static const struct option long_options[] = {
{"Output tileset", 0, 0, 0},
{"output", required_argument, 0, 'o'},
{"output-to-directory", required_argument, 0, 'e'},
{"force", no_argument, 0, 'f'},
{"Tileset description and attribution", 0, 0, 0},
{"name", required_argument, 0, 'n'},
{"attribution", required_argument, 0, 'A'},
{"description", required_argument, 0, 'N'},
{"Input tilesets", 0, 0, 0},
{"read-from", required_argument, 0, 'r'},
{"Zoom levels", 0, 0, 0},
{"maximum-zoom", required_argument, 0, 'z'},
{"minimum-zoom", required_argument, 0, 'Z'},
{"overzoom", no_argument, 0, 'O'},
{"buffer", required_argument, 0, 'b'},
{"Layer names", 0, 0, 0},
{"layer", required_argument, 0, 'l'},
{"exclude-layer", required_argument, 0, 'L'},
{"rename-layer", required_argument, 0, 'R'},
{"Joining with a CSV file", 0, 0, 0},
{"csv", required_argument, 0, 'c'},
{"if-matched", no_argument, 0, 'i'},
{"empty-csv-columns-are-null", no_argument, &pe, 1},
{"Filtering feature attributes", 0, 0, 0},
{"exclude", required_argument, 0, 'x'},
{"include", required_argument, 0, 'y'},
{"exclude-all", no_argument, 0, 'X'},
{"exclude-all-tile-attributes", no_argument, 0, '~'},
{"exclude-all-tile-geometries", no_argument, 0, '~'},
{"Filtering features by attributes", 0, 0, 0},
{"feature-filter-file", required_argument, 0, 'J'},
{"feature-filter", required_argument, 0, 'j'},
{"Setting or disabling tile size limits", 0, 0, 0},
{"no-tile-size-limit", no_argument, &pk, 1},
{"no-tile-compression", no_argument, &pC, 1},
{"no-tile-stats", no_argument, &pg, 1},
{"tile-stats-attributes-limit", required_argument, 0, '~'},
{"tile-stats-sample-values-limit", required_argument, 0, '~'},
{"tile-stats-values-limit", required_argument, 0, '~'},
{"Progress indicator", 0, 0, 0},
{"quiet", no_argument, 0, 'q'},
{"", 0, 0, 0},
{"prevent", required_argument, 0, 'p'},
{"unidecode-data", required_argument, 0, '~'},
{0, 0, 0, 0},
};
// the options above, with the usage message headings removed
static struct option real_long_options[sizeof(long_options) / sizeof(long_options[0])];
void usage(char **argv) {
static const char *const forms[] = {
"[options] source.mbtiles ...",
"[options] --read-from=inputfile.txt",
NULL,
};
static const struct usage_required_option required[] = {
{"output", "new.mbtiles", 1},
{"output-to-directory", "directory", 1},
{NULL, NULL, 0},
};
print_usage(stderr, argv[0], forms, long_options, required);
fprintf(stderr, "Usage: %s [-f] [-i] [-pk] [-pC] [-c joins.csv] [-X] [-x exclude ...] [-y include ...] [-r inputfile.txt ] -o new.mbtiles source.mbtiles ...\n", argv[0]);
exit(EXIT_ARGS);
}
int inner_main(int argc, char **argv) {
int main(int argc, char **argv) {
char *out_mbtiles = NULL;
char *out_dir = NULL;
sqlite3 *outdb = NULL;
@@ -1372,8 +1298,57 @@ int inner_main(int argc, char **argv) {
std::string set_name, set_description, set_attribution;
strip_usage_headings(long_options, real_long_options);
std::string getopt_str = getopt_string(real_long_options);
struct option long_options[] = {
{"output", required_argument, 0, 'o'},
{"output-to-directory", required_argument, 0, 'e'},
{"force", no_argument, 0, 'f'},
{"overzoom", no_argument, 0, 'O'},
{"buffer", required_argument, 0, 'b'},
{"if-matched", no_argument, 0, 'i'},
{"attribution", required_argument, 0, 'A'},
{"name", required_argument, 0, 'n'},
{"description", required_argument, 0, 'N'},
{"prevent", required_argument, 0, 'p'},
{"csv", required_argument, 0, 'c'},
{"exclude", required_argument, 0, 'x'},
{"exclude-all", no_argument, 0, 'X'},
{"include", required_argument, 0, 'y'},
{"exclude-all-tile-attributes", no_argument, 0, '~'},
{"exclude-all-tile-geometries", no_argument, 0, '~'},
{"layer", required_argument, 0, 'l'},
{"exclude-layer", required_argument, 0, 'L'},
{"quiet", no_argument, 0, 'q'},
{"maximum-zoom", required_argument, 0, 'z'},
{"minimum-zoom", required_argument, 0, 'Z'},
{"feature-filter-file", required_argument, 0, 'J'},
{"feature-filter", required_argument, 0, 'j'},
{"rename-layer", required_argument, 0, 'R'},
{"read-from", required_argument, 0, 'r'},
{"use-attribute-for-id", required_argument, 0, '~'},
{"no-tile-size-limit", no_argument, &pk, 1},
{"no-tile-compression", no_argument, &pC, 1},
{"empty-csv-columns-are-null", no_argument, &pe, 1},
{"no-tile-stats", no_argument, &pg, 1},
{"tile-stats-attributes-limit", required_argument, 0, '~'},
{"tile-stats-sample-values-limit", required_argument, 0, '~'},
{"tile-stats-values-limit", required_argument, 0, '~'},
{"unidecode-data", required_argument, 0, '~'},
{0, 0, 0, 0},
};
std::string getopt_str;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val > ' ') {
getopt_str.push_back(long_options[lo].val);
if (long_options[lo].has_arg == required_argument) {
getopt_str.push_back(':');
}
}
}
extern int optind;
extern char *optarg;
@@ -1382,7 +1357,7 @@ int inner_main(int argc, char **argv) {
std::string commandline = format_commandline(argc, argv);
int option_index = 0;
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, &option_index)) != -1) {
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, &option_index)) != -1) {
switch (i) {
case 0:
break;
@@ -1527,7 +1502,7 @@ int inner_main(int argc, char **argv) {
break;
case '~': {
const char *opt = real_long_options[option_index].name;
const char *opt = long_options[option_index].name;
if (strcmp(opt, "tile-stats-attributes-limit") == 0) {
max_tilestats_attributes = atoi(optarg);
} else if (strcmp(opt, "tile-stats-sample-values-limit") == 0) {
@@ -1683,15 +1658,3 @@ int inner_main(int argc, char **argv) {
return 0;
}
int main(int argc, char **argv) {
try {
return inner_main(argc, argv);
} catch (tippecanoe_error &e) {
fprintf(stderr, "%s\n", e.what());
return e.exit_code;
} catch (std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
}
+25 -21
View File
@@ -61,6 +61,9 @@ extern "C" {
#define COORD_OFFSET (4LL << 32)
#define SHIFT_RIGHT(a) ((long long) std::round((double) (a) / (1LL << geometry_scale)))
#define XSTRINGIFY(s) STRINGIFY(s)
#define STRINGIFY(s) #s
pthread_mutex_t db_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t var_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t task_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -1744,8 +1747,8 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
key_pool key_pool;
std::vector<std::atomic<bool> > within(child_shards);
std::vector<long long> start_geompos(child_shards);
std::atomic<bool> within[child_shards];
long long start_geompos[child_shards];
for (size_t i = 0; i < (size_t) child_shards; i++) {
within[i] = false;
start_geompos[i] = -1;
@@ -1810,10 +1813,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
rpa.along = along;
rpa.alongminus = alongminus;
rpa.buffer = buffer;
rpa.within = within.data();
rpa.within = within;
rpa.geomfile = geomfile;
rpa.geompos = geompos;
rpa.start_geompos = start_geompos.data();
rpa.start_geompos = start_geompos;
rpa.oprogress = &oprogress;
rpa.todo = todo;
rpa.fname = fname;
@@ -1858,7 +1861,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
ssize_t which_serial_feature = -1;
if (prefilter == NULL) {
sf = next_feature(geoms, geompos_in, z, tx, ty, initial_x, initial_y, &original_features, &unclipped_features, nextzoom, maxzoom, minzoom, max_zoom_increment, pass, along, alongminus, buffer, within.data(), geomfile, geompos, start_geompos.data(), &oprogress, todo, fname, child_shards, filter, global_stringpool, pool_off, layer_unmaps, first_time, compressed_input, &multiplier_state, tile_stringpool, unidecode_data, next_feature_state, arg->droprate);
sf = next_feature(geoms, geompos_in, z, tx, ty, initial_x, initial_y, &original_features, &unclipped_features, nextzoom, maxzoom, minzoom, max_zoom_increment, pass, along, alongminus, buffer, within, geomfile, geompos, start_geompos, &oprogress, todo, fname, child_shards, filter, global_stringpool, pool_off, layer_unmaps, first_time, compressed_input, &multiplier_state, tile_stringpool, unidecode_data, next_feature_state, arg->droprate);
} else {
sf = parse_feature(prefilter_jp, z, tx, ty, layermaps, tiling_seg, layer_unmaps, postfilter != NULL, key_pool);
}
@@ -2395,7 +2398,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
if (p.clustered > 0) {
serial_val sv, sv2, sv3, sv4;
long long point_count = p.clustered + 1;
char abbrev[24]; // fits "%lld" of any long long, including the sign and the NUL
char abbrev[20]; // to_string(LLONG_MAX).length() / 1000 + 1;
p.full_keys.push_back(key_pool.pool("clustered"));
sv.type = mvt_bool;
@@ -2445,7 +2448,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
{
std::vector<pthread_t> pthreads(tasks);
pthread_t pthreads[tasks];
std::vector<simplification_worker_arg> args;
args.resize(tasks);
for (int i = 0; i < tasks; i++) {
@@ -3249,27 +3252,28 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::
for (z = iz; z <= maxzoom; z++) {
std::atomic<long long> most(0);
std::vector<compressor> compressors(TEMP_FILES);
std::vector<compressor *> sub(TEMP_FILES);
std::vector<std::atomic<long long> > subpos(TEMP_FILES);
std::vector<int> subfd(TEMP_FILES);
compressor compressors[TEMP_FILES];
compressor *sub[TEMP_FILES];
std::atomic<long long> subpos[TEMP_FILES];
int subfd[TEMP_FILES];
for (size_t j = 0; j < TEMP_FILES; j++) {
std::string geomname = std::string(tmpdir) + "/geom" + std::to_string(j) + ".XXXXXXXX";
subfd[j] = mkstemp_cloexec(&geomname[0]);
// printf("%s\n", geomname.c_str());
char geomname[strlen(tmpdir) + strlen("/geom.XXXXXXXX" XSTRINGIFY(INT_MAX)) + 1];
snprintf(geomname, sizeof(geomname), "%s/geom%zu.XXXXXXXX", tmpdir, j);
subfd[j] = mkstemp_cloexec(geomname);
// printf("%s\n", geomname);
if (subfd[j] < 0) {
perror(geomname.c_str());
perror(geomname);
exit(EXIT_OPEN);
}
FILE *fp = fopen_oflag(geomname.c_str(), "wb", O_WRONLY | O_CLOEXEC);
FILE *fp = fopen_oflag(geomname, "wb", O_WRONLY | O_CLOEXEC);
if (fp == NULL) {
perror(geomname.c_str());
perror(geomname);
exit(EXIT_OPEN);
}
compressors[j] = compressor(fp);
sub[j] = &compressors[j];
subpos[j] = 0;
unlink(geomname.c_str());
unlink(geomname);
}
size_t useful_threads = 0;
@@ -3337,7 +3341,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::
std::set<zxy> skip_children_out;
for (size_t pass = 0;; pass++) {
std::vector<pthread_t> pthreads(threads);
pthread_t pthreads[threads];
std::vector<write_tile_args> args;
args.resize(threads);
std::atomic<int> running(threads);
@@ -3356,8 +3360,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::
args[thread].outdir = outdir;
args[thread].buffer = buffer;
args[thread].fname = fname;
args[thread].geomfile = sub.data() + thread * (TEMP_FILES / threads);
args[thread].geompos = subpos.data() + thread * (TEMP_FILES / threads);
args[thread].geomfile = sub + thread * (TEMP_FILES / threads);
args[thread].geompos = subpos + thread * (TEMP_FILES / threads);
args[thread].todo = todo;
args[thread].along = &along; // locked with var_lock
args[thread].gamma = zoom_gamma;
-33
View File
@@ -136,36 +136,3 @@ TEST_CASE("line_is_too_small") {
dv.emplace_back(VT_LINETO, -51864809, 2683873977);
REQUIRE(line_is_too_small(dv, 0, 10));
}
TEST_CASE("Polygon cleaning drops a hole that no ring can parent", "[wagyu]") {
// Two mutually reversed self-intersecting rings whose union leaves a hole
// that wagyu's topology correction cannot assign to any surviving parent
// ring (found by fuzzing; same failure as mapbox/tippecanoe#761). Without
// the fix in mapbox/geometry/wagyu/topology_correction.hpp, this exits
// through the "Could not properly place hole to a parent." handler in
// clean_or_clip_poly instead of returning.
static const std::vector<std::vector<std::pair<long long, long long>>> rings = {
{{0, 5}, {5, 4}, {5, 1}, {4, 4}, {4, 2}, {7, 1}, {0, 5}},
{{0, 5}, {7, 1}, {4, 2}, {4, 4}, {5, 1}, {5, 4}, {0, 0}, {0, 5}},
};
drawvec geom;
for (auto const &ring : rings) {
for (size_t i = 0; i < ring.size(); i++) {
geom.push_back(draw(i == 0 ? VT_MOVETO : VT_LINETO, ring[i].first, ring[i].second));
}
}
drawvec out = clean_or_clip_poly(geom, 0, 0, false, false);
// The regression signal is getting here at all: without the fix,
// clean_or_clip_poly exits the process from its wagyu error handler.
SUCCEED("clean_or_clip_poly returned");
// Anything that survives must be sanely wound: first ring positive.
if (out.size() > 0) {
size_t j = 1;
while (j < out.size() && out[j].op == VT_LINETO) j++;
REQUIRE(get_area(out, 0, j) > 0);
}
}
-133
View File
@@ -1,133 +0,0 @@
#include <string.h>
#include <set>
#include <string>
#include "usage.hpp"
// Options are wrapped to fit within this many columns
#define USAGE_WIDTH 80
// The indentation of the continuation lines of the option list
#define USAGE_INDENT 8
std::string getopt_string(const struct option *long_options) {
std::string getopt_str;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val > ' ') {
getopt_str.push_back(long_options[lo].val);
if (long_options[lo].has_arg == required_argument) {
getopt_str.push_back(':');
}
}
}
return getopt_str;
}
void strip_usage_headings(const struct option *long_options, struct option *real_long_options) {
size_t out = 0;
for (size_t lo = 0; long_options[lo].name != NULL; lo++) {
if (long_options[lo].val != 0) {
real_long_options[out++] = long_options[lo];
}
}
real_long_options[out] = {0, 0, 0, 0};
}
// The entry for `name` in the list of options that must be specified,
// or NULL if it is an optional option
static const struct usage_required_option *required_for(const char *name, const struct usage_required_option *required) {
for (size_t i = 0; required != NULL && required[i].name != NULL; i++) {
if (strcmp(required[i].name, name) == 0) {
return &required[i];
}
}
return NULL;
}
// "--option", or "--option=placeholder" if the option takes an argument
static std::string option_text(const struct option *opt, const struct usage_required_option *req) {
std::string text = std::string("--") + opt->name;
if (opt->has_arg != no_argument) {
text += "=";
text += (req != NULL && req->placeholder != NULL) ? req->placeholder : "...";
}
return text;
}
// The alternatives that `req` belongs to, as "(--this=... | --that=...)"
static std::string alternation_text(const struct option *long_options, const struct usage_required_option *required, int alternation) {
std::string text;
size_t found = 0;
for (size_t lo = 0; long_options[lo].name != NULL && long_options[lo].name[0] != '\0'; lo++) {
const struct usage_required_option *req = required_for(long_options[lo].name, required);
if (req != NULL && req->alternation == alternation) {
if (found++ > 0) {
text += " | ";
}
text += option_text(&long_options[lo], req);
}
}
if (found > 1) {
text = "(" + text + ")";
}
return text;
}
void print_usage(FILE *out, const char *program, const char *const *forms,
const struct option *long_options,
const struct usage_required_option *required) {
for (size_t f = 0; forms[f] != NULL; f++) {
const char *lead = (f == 0) ? "Usage: " : "\n or: ";
fprintf(out, "%s%s %s", lead, program, forms[f]);
}
// whatever the forms took up, the option list starts on a line of its own
size_t width = USAGE_WIDTH;
std::set<int> alternations_listed;
for (size_t lo = 0; long_options[lo].name != NULL && long_options[lo].name[0] != '\0'; lo++) {
if (long_options[lo].val == 0) {
fprintf(out, "\n %s\n%*s", long_options[lo].name, USAGE_INDENT, "");
width = USAGE_INDENT;
continue;
}
const struct usage_required_option *req = required_for(long_options[lo].name, required);
std::string text;
if (req == NULL) {
text = "[" + option_text(&long_options[lo], NULL) + "]";
} else if (req->alternation == 0) {
text = option_text(&long_options[lo], req);
} else {
if (alternations_listed.count(req->alternation) != 0) {
continue; // already listed with the first of its alternatives
}
alternations_listed.insert(req->alternation);
text = alternation_text(long_options, required, req->alternation);
}
if (width + 1 + text.size() >= USAGE_WIDTH) {
fprintf(out, "\n%*s", USAGE_INDENT, "");
width = USAGE_INDENT;
}
fprintf(out, " %s", text.c_str());
width += 1 + text.size();
}
fprintf(out, "\n");
}
-52
View File
@@ -1,52 +0,0 @@
#ifndef USAGE_HPP
#define USAGE_HPP
#include <stdio.h>
#include <getopt.h>
#include <string>
// An option that must be specified rather than being optional, and the
// placeholder to show for its argument in the usage message.
//
// Options that share the same non-zero `alternation` are alternatives to
// each other: one of them must be specified, but not more than one, and
// they are listed together as `(--this=... | --that=...)`.
struct usage_required_option {
const char *name;
const char *placeholder;
int alternation;
};
// Returns the short option string to pass to getopt_long() for the
// options in `long_options`, so that the two can't disagree about
// which short options exist or take arguments.
std::string getopt_string(const struct option *long_options);
// Copies `long_options` to `real_long_options`, leaving out the headings
// of the usage message, which are not real options and so must not be
// passed on to getopt_long(). The destination must be at least as large
// as the source.
void strip_usage_headings(const struct option *long_options, struct option *real_long_options);
// Prints a usage message for `program` to `out`:
//
// Usage: program forms[0]
// or: program forms[1]
// [--some-option] [--another-option=...] ...
//
// where `forms` is a NULL-terminated list of the ways the non-option
// arguments can be given, and the list of options is derived from
// `long_options`, the same table that is passed to getopt_long(), so that
// the message stays in sync with the options that are really accepted.
//
// Options named in `required` (a list terminated by a NULL name, or NULL
// if there are none) are shown without brackets, using the placeholder
// given there for their argument, and grouped with any alternatives to
// them. An entry in `long_options` with no `val` is printed as a heading
// for the options that follow it, and an entry with an empty name ends
// the listing, hiding any options after it.
void print_usage(FILE *out, const char *program, const char *const *forms,
const struct option *long_options,
const struct usage_required_option *required);
#endif
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.81.0"
#define VERSION "v2.80.0"
#endif
+1 -2
View File
@@ -25,9 +25,8 @@ struct json_writer {
~json_writer() {
if (state.size() > 0) {
if (state.size() != 1 || state[0] != JSON_WRITE_TOP) {
// Log but don't throw — throwing from a destructor
// during stack unwinding calls std::terminate().
fprintf(stderr, "JSON not closed at end\n");
exit(EXIT_FAILURE);
}
}
}