mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-22 16:31:18 +01:00
Compare commits
55
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f5365aa5d | ||
|
|
63fcac725a | ||
|
|
734bba7c78 | ||
|
|
1820630392 | ||
|
|
905fe84459 | ||
|
|
ec727172b1 | ||
|
|
e6e1ec3263 | ||
|
|
1b060b7faf | ||
|
|
7c80fccdc1 | ||
|
|
0badb242be | ||
|
|
0dc1e00eee | ||
|
|
0c650b881a | ||
|
|
7fc82a1796 | ||
|
|
fe7e84be4a | ||
|
|
cb6cacef15 | ||
|
|
eb9acf9d44 | ||
|
|
a5805bd809 | ||
|
|
d7b2892f98 | ||
|
|
c82e4beee3 | ||
|
|
9a7ac5733f | ||
|
|
533e000faa | ||
|
|
68ab8dcc22 | ||
|
|
6dd49be6c9 | ||
|
|
c2a973d8f6 | ||
|
|
8ac730718a | ||
|
|
2d548bed06 | ||
|
|
94929b048c | ||
|
|
bfb62ee2db | ||
|
|
a0532e73ac | ||
|
|
9d1637f7c1 | ||
|
|
de4e1e478f | ||
|
|
423fea1544 | ||
|
|
583fc3744a | ||
|
|
390c362452 | ||
|
|
10f7f0a3c2 | ||
|
|
7165ae6999 | ||
|
|
d70e3326da | ||
|
|
a8bd7ac723 | ||
|
|
bdfb06cd6a | ||
|
|
1d81935cd5 | ||
|
|
dcc616d3d4 | ||
|
|
11e3196c9a | ||
|
|
905b58cdf4 | ||
|
|
6d46578ad8 | ||
|
|
794ae2b1eb | ||
|
|
23667bb8eb | ||
|
|
b3b89e1e07 | ||
|
|
120b8f4e41 | ||
|
|
28efc40e6e | ||
|
|
78661f1cb2 | ||
|
|
8409bf9ce4 | ||
|
|
23c6559b03 | ||
|
|
66e5d66300 | ||
|
|
4822d02f24 | ||
|
|
c5f2f0da34 |
@@ -4,11 +4,35 @@ on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
|
||||
version: ['Release', 'Debug']
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install dependencies (Ubuntu)
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get install libsqlite3-dev
|
||||
- name: Install dependencies (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install sqlite3
|
||||
- run: uname -a; BUILDTYPE=${{ matrix.version }} make
|
||||
- run: make test
|
||||
- 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
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ tippecanoe-json-tool
|
||||
tippecanoe-overzoom
|
||||
unit
|
||||
|
||||
# Left behind if man page generation fails
|
||||
man/tippecanoe.1.tmp
|
||||
|
||||
# Tests
|
||||
tests/**/*.mbtiles
|
||||
tests/**/*.check
|
||||
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
|
||||
sudo: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# test on docker+centos7
|
||||
- os: linux
|
||||
compiler: clang
|
||||
services:
|
||||
- docker
|
||||
sudo: true
|
||||
dist: trusty
|
||||
env: DOCKERFILE=Dockerfile.centos7
|
||||
before_install: []
|
||||
install:
|
||||
- docker build -t tippecanoe-image -f ${DOCKERFILE} .
|
||||
script:
|
||||
- docker run -it tippecanoe-image
|
||||
# test on docker+ubuntu
|
||||
- os: linux
|
||||
compiler: clang
|
||||
services:
|
||||
- docker
|
||||
sudo: true
|
||||
dist: trusty
|
||||
env: DOCKERFILE=Dockerfile
|
||||
before_install: []
|
||||
install:
|
||||
- docker build -t tippecanoe-image -f ${DOCKERFILE} .
|
||||
script:
|
||||
- docker run -it tippecanoe-image
|
||||
# debug+integer-santizer build
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: CLANG_VERSION='3.8.0' BUILDTYPE=Debug CC="clang-3.8" CXX="clang++-3.8" CXXFLAGS="-fsanitize=integer" CFLAGS="-fsanitize=integer" LDFLAGS="-fsanitize=integer"
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test' ]
|
||||
packages: [ 'libstdc++6','libstdc++-5-dev' ]
|
||||
# debug+leak+address-sanitizer build
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: CLANG_VERSION='3.8.0' BUILDTYPE=Debug ASAN_OPTIONS=detect_leaks=1 CC="clang-3.8" CXX="clang++-3.8" CXXFLAGS="-fsanitize=address,undefined" CFLAGS="-fsanitize=address,undefined" LDFLAGS="-fsanitize=address,undefined" FEWER=true
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test' ]
|
||||
packages: [ 'libstdc++6','libstdc++-5-dev' ]
|
||||
# coverage+debug build
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: CLANG_VERSION='3.8.0' BUILDTYPE=Debug CC="clang-3.8" CXX="clang++-3.8" CXXFLAGS="--coverage" CFLAGS="--coverage" LDFLAGS="--coverage"
|
||||
after_script:
|
||||
- mason install llvm-cov 3.9.1
|
||||
- mason link llvm-cov 3.9.1
|
||||
- which llvm-cov
|
||||
- curl -S -f https://codecov.io/bash -o codecov
|
||||
- chmod +x codecov
|
||||
- ./codecov -x "llvm-cov gcov" -Z
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test' ]
|
||||
packages: [ 'libstdc++6','libstdc++-5-dev' ]
|
||||
# release+linux+g++
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: BUILDTYPE=Release CC="gcc-4.9" CXX="g++-4.9"
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: [ 'g++-4.9' ]
|
||||
# release+linux+clang++
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: CLANG_VERSION='3.8.0' BUILDTYPE=Release CC="clang-3.8" CXX="clang++-3.8"
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test' ]
|
||||
packages: [ 'libstdc++6','libstdc++-5-dev' ]
|
||||
# release+osx
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILDTYPE=Release
|
||||
# debug+osx
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILDTYPE=Debug
|
||||
|
||||
before_install:
|
||||
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
|
||||
- export PATH=${DEPS_DIR}/bin:${PATH} && mkdir -p ${DEPS_DIR}
|
||||
- |
|
||||
if [[ ${CLANG_VERSION:-false} != false ]]; then
|
||||
export CCOMPILER='clang'
|
||||
export CXXCOMPILER='clang++'
|
||||
CLANG_URL="https://mason-binaries.s3.amazonaws.com/${TRAVIS_OS_NAME}-x86_64/clang/${CLANG_VERSION}.tar.gz"
|
||||
travis_retry wget --quiet -O - ${CLANG_URL} | tar --strip-components=1 -xz -C ${DEPS_DIR}
|
||||
fi
|
||||
|
||||
install:
|
||||
- BUILDTYPE=${BUILDTYPE} make -j
|
||||
|
||||
script:
|
||||
- npm install geobuf
|
||||
- if [ -n "${FEWER}" ]; then
|
||||
BUILDTYPE=${BUILDTYPE} make fewer-tests; else
|
||||
BUILDTYPE=${BUILDTYPE} make test geobuf-test;
|
||||
fi
|
||||
+184
@@ -1,3 +1,187 @@
|
||||
# 2.81.0
|
||||
|
||||
* 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
|
||||
|
||||
# 2.79.0
|
||||
|
||||
* When deduplicating features by ID in tippecanoe-overzoom, be careful
|
||||
to track even features that have been clipped away.
|
||||
|
||||
# 2.78.0
|
||||
|
||||
* Fix potential infinite loops in as-needed dropping and coalescing.
|
||||
When the threshold cannot be increased, it is now an error, rather than
|
||||
falling back to trying to lower the detail.
|
||||
* Cleaning of complex polygon geometries now happens in stages
|
||||
to avoid performance problems when there are very large numbers
|
||||
of vertices.
|
||||
* Label point generation happens earlier in tiling, to avoid doing slow
|
||||
operations on polygons that will not be retained anyway.
|
||||
|
||||
# 2.77.0
|
||||
|
||||
* Add --deduplicate-by-id option to tippecanoe-overzoom
|
||||
|
||||
# 2.76.0
|
||||
|
||||
* Add missing case for accumulating the mean of attributes that are inconsistently present
|
||||
* Add --keep-point-cluster-position (#326)
|
||||
|
||||
# 2.75.1
|
||||
|
||||
* Further reduce memory consumption in attribute sorting and tilestats tracking
|
||||
|
||||
# 2.75.0
|
||||
|
||||
* Reduce memory consumption in attribute accumulation and feature sorting
|
||||
|
||||
# 2.74.0
|
||||
|
||||
* Add the option to join attributes from a sqlite database in tile-join
|
||||
* Improve tile-join's tileset bounding box calculations
|
||||
|
||||
# 2.73.0
|
||||
|
||||
* Correctly clip features down to nothing when the clip region doesn't intersect the tile at all
|
||||
|
||||
# 2.72.0
|
||||
|
||||
* Add --clip-polygon-file and --feature-filter-file options to tippecanoe-overzoom
|
||||
|
||||
# 2.71.0
|
||||
|
||||
* Add --clip-bounding-box and --clip-polygon options to tippecanoe-overzoom
|
||||
|
||||
# 2.70.1
|
||||
|
||||
* Raise tippecanoe-decode limit on the size of individual tiles
|
||||
|
||||
# 2.70.0
|
||||
|
||||
* Performance improvements to tippecanoe-overzoom with attribute exclusion
|
||||
|
||||
# 2.69.0
|
||||
|
||||
* Fix crash when the first bin gets clipped away
|
||||
|
||||
# 2.68.0
|
||||
|
||||
* Adds `--no-tile-compression` option to `tippecanoe-overzoom`
|
||||
* Make `tippecanoe-overzoom` clip the output tile to the tile buffer after assigning points to bins
|
||||
* Adds `--include`/`-y` option to `tippecanoe-decode` to decode only specified attributes
|
||||
* Cleans up some inconsistent handling of variable tile extents in overzooming code
|
||||
* Speeds up overzooming slightly in `tile-join` by doing less preflighting to discover which child tiles contain features
|
||||
|
||||
# 2.67.0
|
||||
|
||||
* Reduce memory consumption of duplicate attribute names in `serial_feature`
|
||||
* The maxzoom guess calculation now takes into account the number of duplicate feature locations
|
||||
|
||||
# 2.66.0
|
||||
|
||||
* Only bin by ID, not by geometry, if --bin-by-id-list is specified
|
||||
* Do attribute accumulation in overzoom in mvt_value instead of converting to serial_val
|
||||
* Fix bool values read from flatgeobuf sources (#289)
|
||||
|
||||
# 2.65.0
|
||||
|
||||
* Improve spatial distribution of --retain-points-multiplier features
|
||||
* Add --preserve-multiplier-density-threshold option to maintain minimum density of multiplier features
|
||||
|
||||
# 2.64.0
|
||||
|
||||
* Add --bin-by-id to overzoom
|
||||
|
||||
# 2.63.0
|
||||
|
||||
* Top-level null filter now evaluates to true
|
||||
|
||||
# 2.62.6
|
||||
|
||||
* Remove buggy optimization to avoid reclipping in tippecanoe-overzoom
|
||||
|
||||
# 2.62.5
|
||||
|
||||
* More aggressive binning when points fail the point-in-polygon test
|
||||
|
||||
# 2.62.4
|
||||
|
||||
* Fix accumulation of count and mean in overzoom
|
||||
|
||||
# 2.62.3
|
||||
|
||||
* Summary statistics with --accumulate-numeric-attributes make it from tiling through to binning
|
||||
* Prefix can be specified for --accumulate-numeric-attributes
|
||||
* Added --exclude and --exclude-prefix to tippecanoe-overzoom
|
||||
|
||||
# 2.62.2
|
||||
|
||||
* Pass feature ID through with bins
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
FROM ubuntu:22.04 AS tippecanoe-builder
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get -y install make gcc g++ libsqlite3-dev zlib1g-dev
|
||||
|
||||
COPY . /tmp/tippecanoe-src
|
||||
WORKDIR /tmp/tippecanoe-src
|
||||
|
||||
RUN make
|
||||
|
||||
CMD make test
|
||||
|
||||
# Using multistage build reduces the docker image size by alot by only copying the needed binaries
|
||||
FROM ubuntu:22.04
|
||||
RUN apt-get update \
|
||||
&& apt-get -y install libsqlite3-0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=tippecanoe-builder /tmp/tippecanoe-src/tippecanoe* /usr/local/bin/
|
||||
COPY --from=tippecanoe-builder /tmp/tippecanoe-src/tile-join /usr/local/bin/
|
||||
WORKDIR /app
|
||||
@@ -1,15 +0,0 @@
|
||||
FROM centos:centos8
|
||||
|
||||
RUN yum install -y make sqlite-devel zlib-devel bash git gcc-c++
|
||||
|
||||
# Create a directory and copy in all files
|
||||
RUN mkdir -p /tmp/tippecanoe-src
|
||||
WORKDIR /tmp/tippecanoe-src
|
||||
COPY . /tmp/tippecanoe-src
|
||||
|
||||
# Build tippecanoe
|
||||
RUN make \
|
||||
&& make install
|
||||
|
||||
# Run the tests
|
||||
CMD make test
|
||||
+5
-5
@@ -1,19 +1,19 @@
|
||||
## [Visualizing a Month of Lightning](http://rousseau.io/2015/03/23/visualizing-a-month-of-lightning) by Jordan Rousseau
|
||||
## [Visualizing a Month of Lightning](https://medium.com/@jvrousseau/visualizing-a-month-of-lightning-8ab63d040d8c) by Jordan Rousseau
|
||||
|
||||

|
||||
|
||||
## [Making the most detailed tweet map ever](https://www.mapbox.com/blog/twitter-map-every-tweet/) by Eric Fischer
|
||||
## [Making the most detailed tweet map ever](https://web.archive.org/web/20161220144946/https://www.mapbox.com/blog/twitter-map-every-tweet/) by Eric Fischer
|
||||
|
||||

|
||||
|
||||
## [Superpowering Runkeeper's 1.5 million walks, runs, and bike rides](https://www.mapbox.com/blog/runkeeper-million-routes/)
|
||||
## [Superpowering Runkeeper's 1.5 million walks, runs, and bike rides](https://web.archive.org/web/20161219225305/https://www.mapbox.com/blog/runkeeper-million-routes/)
|
||||
|
||||

|
||||
|
||||
## [The Geotaggers' World Atlas](https://www.mapbox.com/blog/geotaggers-world-atlas/) by Eric Fischer
|
||||
## [The Geotaggers' World Atlas](https://web.archive.org/web/20170319084321/https://www.mapbox.com/blog/geotaggers-world-atlas/) by Eric Fischer
|
||||
|
||||

|
||||
|
||||
## [Atmospheric River](https://www.mapbox.com/blog/atmospheric-river/)
|
||||
## [Atmospheric River](https://web.archive.org/web/20161011171030/https://www.mapbox.com/blog/atmospheric-river/)
|
||||
|
||||

|
||||
|
||||
@@ -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
|
||||
WARNING_FLAGS := -Wall -Wshadow -Wsign-compare -Wextra -Wunreachable-code -Wuninitialized -Wshadow -Wvla
|
||||
RELEASE_FLAGS := -O3 -DNDEBUG
|
||||
DEBUG_FLAGS := -O0 -DDEBUG -fno-inline-functions -fno-omit-frame-pointer
|
||||
|
||||
@@ -48,36 +48,72 @@ 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
|
||||
md2man-roff README.md > man/tippecanoe.1
|
||||
{ \
|
||||
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 $@
|
||||
|
||||
PG=
|
||||
|
||||
H = $(wildcard *.h) $(wildcard *.hpp)
|
||||
C = $(wildcard *.c) $(wildcard *.cpp)
|
||||
|
||||
INCLUDES = -I/usr/local/include -I.
|
||||
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 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
|
||||
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
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-enumerate: enumerate.o
|
||||
tippecanoe-enumerate: enumerate.o usage.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
|
||||
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o usage.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
|
||||
|
||||
tile-join: tile-join.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
|
||||
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
|
||||
$(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
|
||||
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o usage.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
|
||||
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
|
||||
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
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
-include $(wildcard *.d)
|
||||
@@ -97,7 +133,7 @@ indent:
|
||||
TESTS = $(wildcard tests/*/out/*.json)
|
||||
SPACE = $(NULL) $(NULL)
|
||||
|
||||
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
|
||||
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
|
||||
./unit
|
||||
|
||||
suffixes = json json.gz
|
||||
@@ -108,6 +144,7 @@ suffixes = json json.gz
|
||||
# %22 for quoted quote
|
||||
# %2f for /
|
||||
# %3a for :
|
||||
# %3d for =
|
||||
# %5f for _
|
||||
# %7b for {
|
||||
|
||||
@@ -115,10 +152,11 @@ testargs = \
|
||||
$(subst %20,' ',\
|
||||
$(subst %22,'"',\
|
||||
$(subst %3a,:,\
|
||||
$(subst %2f,/,\
|
||||
$(subst %7b,'{',\
|
||||
$(subst %5f,'_',\
|
||||
$(subst _, ,$(1))))))))
|
||||
$(subst %3d,=,\
|
||||
$(subst %2f,/,\
|
||||
$(subst %7b,'{',\
|
||||
$(subst %5f,'_',\
|
||||
$(subst _, ,$(1)))))))))
|
||||
|
||||
%.json.check:
|
||||
./tippecanoe -q -a@ -f -o $@.mbtiles $(call testargs,$(patsubst %.json.check,%,$(word 4,$(subst /, ,$@)))) $(foreach suffix,$(suffixes),$(sort $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.$(suffix)))) < /dev/null
|
||||
@@ -132,7 +170,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 pbf-test join-test enumerate-test decode-test join-filter-test unit
|
||||
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
|
||||
|
||||
# XXX Use proper makefile rules instead of a for loop
|
||||
%.json.checkbuf:
|
||||
@@ -143,6 +181,42 @@ 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
|
||||
@@ -280,7 +354,8 @@ overzoom-test: tippecanoe-overzoom
|
||||
cmp tests/pbf/13-1310-3166.pbf.json.check tests/pbf/13-1310-3166.pbf.json
|
||||
rm tests/pbf/13-1310-3166.pbf tests/pbf/13-1310-3166.pbf.json.check
|
||||
# Make sure feature order is stable
|
||||
./tippecanoe-overzoom --preserve-input-order -o tests/pbf/11-327-791-out.pbf tests/pbf/11-327-791.pbf 11/327/791 11/327/791
|
||||
# Large -b20 tile buffer to prevent altering the geometries by clipping
|
||||
./tippecanoe-overzoom -b20 --preserve-input-order -o tests/pbf/11-327-791-out.pbf tests/pbf/11-327-791.pbf 11/327/791 11/327/791
|
||||
./tippecanoe-decode tests/pbf/11-327-791.pbf 11 327 791 > tests/pbf/11-327-791.json
|
||||
./tippecanoe-decode tests/pbf/11-327-791-out.pbf 11 327 791 > tests/pbf/11-327-791-out.json
|
||||
cmp tests/pbf/11-327-791.json tests/pbf/11-327-791-out.json
|
||||
@@ -290,8 +365,8 @@ overzoom-test: tippecanoe-overzoom
|
||||
./tippecanoe-decode tests/pbf/13-1310-3166.pbf 13 1310 3166 > tests/pbf/13-1310-3166.pbf.json.check
|
||||
cmp tests/pbf/13-1310-3166.pbf.json.check tests/pbf/13-1310-3166.pbf.json
|
||||
rm tests/pbf/13-1310-3166.pbf tests/pbf/13-1310-3166.pbf.json.check
|
||||
# Multiple inputs
|
||||
./tippecanoe-overzoom -o tests/pbf/13-1310-3166-ne.pbf -t 13/1310/3166 tests/pbf/11-327-791.pbf 11/327/791 tests/pbf/0-0-0.pbf 0/0/0
|
||||
# Multiple inputs, no compression
|
||||
./tippecanoe-overzoom --no-tile-compression -o tests/pbf/13-1310-3166-ne.pbf -t 13/1310/3166 tests/pbf/11-327-791.pbf 11/327/791 tests/pbf/0-0-0.pbf 0/0/0
|
||||
./tippecanoe-decode tests/pbf/13-1310-3166-ne.pbf 13 1310 3166 > tests/pbf/13-1310-3166-ne.pbf.json.check
|
||||
cmp tests/pbf/13-1310-3166-ne.pbf.json.check tests/pbf/13-1310-3166-ne.pbf.json
|
||||
rm tests/pbf/13-1310-3166-ne.pbf tests/pbf/13-1310-3166-ne.pbf.json.check
|
||||
@@ -321,20 +396,25 @@ overzoom-test: tippecanoe-overzoom
|
||||
# Filtering
|
||||
# 243 features in the source tile tests/pbf/0-0-0-pop.pbf
|
||||
# 27 of them match the filter and are retained
|
||||
./tippecanoe-overzoom -y NAME -j'{"*":["SCALERANK","eq",0]}' -o tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-overzoom -y NAME -j'{"*":["==","SCALERANK",0]}' -o tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-expr.pbf 0 0 0 > tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-pop-expr.pbf.json.check tests/pbf/0-0-0-pop-expr.pbf.json
|
||||
rm tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
# Same filter test, but reading the filter from a file
|
||||
./tippecanoe-overzoom -y NAME -J tests/pbf/scalerank-0-filter.json -o tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-expr.pbf 0 0 0 > tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-pop-expr.pbf.json.check tests/pbf/0-0-0-pop-expr.pbf.json
|
||||
rm tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
# Filtering with multiplier
|
||||
# 243 features in the source tile tests/pbf/0-0-0-pop.pbf
|
||||
# 8 features survive into the output, from 9 clusters of 30
|
||||
./tippecanoe-overzoom -y NAME -y SCALERANK -j'{"*":["SCALERANK","eq",0]}' -m -o tests/pbf/0-0-0-filter-mult.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-overzoom -y NAME -y SCALERANK -j'{"*":["==","SCALERANK",0]}' -m -o tests/pbf/0-0-0-filter-mult.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-filter-mult.pbf 0 0 0 > tests/pbf/0-0-0-filter-mult.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-filter-mult.pbf.json.check tests/pbf/0-0-0-filter-mult.pbf.json
|
||||
rm tests/pbf/0-0-0-filter-mult.pbf tests/pbf/0-0-0-filter-mult.pbf.json.check
|
||||
# Filtering with multiplier and preserve-input-order
|
||||
# 243 features in the source tile tests/pbf/0-0-0-pop.pbf
|
||||
./tippecanoe-overzoom -y NAME -y SCALERANK -j'{"*":["NAME","cn","e"]}' -m --preserve-input-order -o tests/pbf/0-0-0-filter-mult-order.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-overzoom -y NAME -y SCALERANK -y LATITUDE -j'{"*":[">","LATITUDE",40]}' -m --preserve-input-order -o tests/pbf/0-0-0-filter-mult-order.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-filter-mult-order.pbf 0 0 0 > tests/pbf/0-0-0-filter-mult-order.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-filter-mult-order.pbf.json.check tests/pbf/0-0-0-filter-mult-order.pbf.json
|
||||
rm tests/pbf/0-0-0-filter-mult-order.pbf tests/pbf/0-0-0-filter-mult-order.pbf.json.check
|
||||
@@ -346,39 +426,21 @@ overzoom-test: tippecanoe-overzoom
|
||||
./tippecanoe-decode tests/muni/out/out.dir/000.pbf 0 0 0 > tests/muni/out/out.dir/overzoomed.json
|
||||
cmp tests/muni/out/out.dir/overzoomed.json tests/muni/out/out.dir/direct.json
|
||||
rm -rf tests/muni/out/out.dir tests/muni/out/out.mbtiles tests/muni/out/out.dir/overzoomed.json tests/muni/out/out.dir/direct.json
|
||||
# Test filter with null attribute
|
||||
./tippecanoe-overzoom -j '{"*":["name","ni",[1,5,6,9]]}' -o tests/pbf/12-2145-1391-filter1.pbf tests/pbf/12-2145-1391.pbf 12/2145/1391 12/2145/1391
|
||||
./tippecanoe-decode tests/pbf/12-2145-1391-filter1.pbf 12 2145 1391 > tests/pbf/12-2145-1391-filter1.pbf.json.check
|
||||
cmp tests/pbf/12-2145-1391-filter1.pbf.json.check tests/pbf/12-2145-1391-filter1.pbf.json
|
||||
rm tests/pbf/12-2145-1391-filter1.pbf.json.check tests/pbf/12-2145-1391-filter1.pbf
|
||||
# Test filter with null attribute in "ni" list
|
||||
./tippecanoe-overzoom -j '{"*":["name","ni",[1,5,6,9,null]]}' -o tests/pbf/12-2145-1391-filter2.pbf tests/pbf/12-2145-1391.pbf 12/2145/1391 12/2145/1391
|
||||
./tippecanoe-decode tests/pbf/12-2145-1391-filter2.pbf 12 2145 1391 > tests/pbf/12-2145-1391-filter2.pbf.json.check
|
||||
cmp tests/pbf/12-2145-1391-filter2.pbf.json.check tests/pbf/12-2145-1391-filter2.pbf.json
|
||||
rm tests/pbf/12-2145-1391-filter2.pbf.json.check tests/pbf/12-2145-1391-filter2.pbf
|
||||
# Tiny polygon reduction
|
||||
./tippecanoe-overzoom --line-simplification=5 --tiny-polygon-size=50 -o tests/pbf/countries-0-0-0.pbf.out tests/pbf/countries-0-0-0.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/countries-0-0-0.pbf.out 0 0 0 > tests/pbf/countries-0-0-0.pbf.out.json.check
|
||||
cmp tests/pbf/countries-0-0-0.pbf.out.json.check tests/pbf/countries-0-0-0.pbf.out.json
|
||||
rm tests/pbf/countries-0-0-0.pbf.out tests/pbf/countries-0-0-0.pbf.out.json.check
|
||||
# Binning
|
||||
./tippecanoe-overzoom -o tests/pbf/bin-11-327-791.pbf.out --assign-to-bins tests/pbf/sf-zips.json tests/pbf/muni-11-327-791.pbf 11/327/791 11/327/791
|
||||
./tippecanoe-decode tests/pbf/bin-11-327-791.pbf.out 11 327 791 > tests/pbf/bin-11-327-791.pbf.out.json.check
|
||||
cmp tests/pbf/bin-11-327-791.pbf.out.json.check tests/pbf/bin-11-327-791.pbf.out.json
|
||||
rm tests/pbf/bin-11-327-791.pbf.out.json.check tests/pbf/bin-11-327-791.pbf.out
|
||||
# Binning with longitude wraparound problems
|
||||
./tippecanoe-overzoom -o tests/pbf/0-0-0-pop-2-0-1.pbf.out --assign-to-bins tests/pbf/h3-2-0-1.geojson tests/pbf/0-0-0.pbf 2/0/1 2/0/1
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-2-0-1.pbf.out 2 0 1 > tests/pbf/0-0-0-pop-2-0-1.pbf.out.json.check
|
||||
cmp tests/pbf/0-0-0-pop-2-0-1.pbf.out.json.check tests/pbf/0-0-0-pop-2-0-1.pbf.out.json
|
||||
rm tests/pbf/0-0-0-pop-2-0-1.pbf.out tests/pbf/0-0-0-pop-2-0-1.pbf.out.json.check
|
||||
./tippecanoe-overzoom -o tests/pbf/0-0-0-pop-1-1-0.pbf.out --assign-to-bins tests/pbf/h3-1-1-0.geojson tests/pbf/0-0-0.pbf 1/1/0 1/1/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-1-1-0.pbf.out 1 1 0 > tests/pbf/0-0-0-pop-1-1-0.pbf.out.json.check
|
||||
cmp tests/pbf/0-0-0-pop-1-1-0.pbf.out.json.check tests/pbf/0-0-0-pop-1-1-0.pbf.out.json
|
||||
rm tests/pbf/0-0-0-pop-1-1-0.pbf.out tests/pbf/0-0-0-pop-1-1-0.pbf.out.json.check
|
||||
./tippecanoe-overzoom -o tests/pbf/0-0-0-pop-0-0-0.pbf.out --assign-to-bins tests/pbf/h3-0-0-0.geojson tests/pbf/0-0-0.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-0-0-0.pbf.out 0 0 0 > tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check
|
||||
cmp tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check tests/pbf/0-0-0-pop-0-0-0.pbf.out.json
|
||||
rm tests/pbf/0-0-0-pop-0-0-0.pbf.out tests/pbf/0-0-0-pop-0-0-0.pbf.out.json.check
|
||||
# Deduplication by feature ID
|
||||
./tippecanoe -z0 -f -e tests/pbf/1.json.dir -l layer tests/pbf/1.json
|
||||
./tippecanoe -z0 -f -e tests/pbf/2.json.dir -l layer tests/pbf/2.json
|
||||
./tippecanoe-overzoom -b0 -o tests/pbf/merged-nodedup.pbf -t 1/1/0 tests/pbf/1.json.dir/0/0/0.pbf 0/0/0 tests/pbf/2.json.dir/0/0/0.pbf 0/0/0
|
||||
./tippecanoe-decode tests/pbf/merged-nodedup.pbf 1 1 0 > tests/pbf/merged-nodedup.pbf.json.check
|
||||
cmp tests/pbf/merged-nodedup.pbf.json.check tests/pbf/merged-nodedup.pbf.json
|
||||
./tippecanoe-overzoom -b0 --deduplicate-by-id -o tests/pbf/merged-dedup.pbf -t 1/1/0 tests/pbf/1.json.dir/0/0/0.pbf 0/0/0 tests/pbf/2.json.dir/0/0/0.pbf 0/0/0
|
||||
./tippecanoe-decode tests/pbf/merged-dedup.pbf 1 1 0 > tests/pbf/merged-dedup.pbf.json.check
|
||||
cmp tests/pbf/merged-dedup.pbf.json.check tests/pbf/merged-dedup.pbf.json
|
||||
rm -r tests/pbf/1.json.dir tests/pbf/2.json.dir tests/pbf/merged-nodedup.pbf tests/pbf/merged-nodedup.pbf.json.check tests/pbf/merged-dedup.pbf tests/pbf/merged-dedup.pbf.json.check
|
||||
|
||||
join-test: tippecanoe tippecanoe-decode tile-join
|
||||
./tippecanoe -q -f -z12 -o tests/join-population/tabblock_06001420.mbtiles -YALAND10:'Land area' -L'{"file": "tests/join-population/tabblock_06001420.json", "description": "population"}'
|
||||
@@ -584,6 +646,12 @@ csv-test: tippecanoe tippecanoe-decode
|
||||
cmp tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles.json
|
||||
rm -f tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles
|
||||
|
||||
flatgeobuf-test: tippecanoe tippecanoe-decode
|
||||
./tippecanoe -q -f -z0 -l numeric-properties -o tests/flatgeobuf/numeric-properties.mbtiles tests/flatgeobuf/numeric-properties.fgb
|
||||
./tippecanoe-decode tests/flatgeobuf/numeric-properties.mbtiles 0 0 0 > tests/flatgeobuf/numeric-properties.json.check
|
||||
cmp tests/flatgeobuf/numeric-properties.json.check tests/flatgeobuf/numeric-properties.json
|
||||
rm -f tests/flatgeobuf/numeric-properties.mbtiles tests/flatgeobuf/numeric-properties.json.check
|
||||
|
||||
layer-json-test: tippecanoe tippecanoe-decode
|
||||
# GeoJSON with description and named layer
|
||||
./tippecanoe -q -z0 -r1 -yNAME -f -o tests/layer-json/out.mbtiles -L'{"file":"tests/ne_110m_populated_places/in.json", "description":"World cities", "layer":"places"}'
|
||||
|
||||
@@ -20,11 +20,11 @@ the density and texture of the data rather than a simplification from dropping
|
||||
supposedly unimportant features or clustering or aggregating them.
|
||||
|
||||
If you give it all of OpenStreetMap and zoom out, it should give you back
|
||||
something that looks like "[All Streets](http://benfry.com/allstreets/map5.html)"
|
||||
something that looks like "[All Streets](https://benfry.com/allstreets/)"
|
||||
rather than something that looks like an Interstate road atlas.
|
||||
|
||||
If you give it all the building footprints in Los Angeles and zoom out
|
||||
far enough that most individual buildings are no longer discernable, you
|
||||
far enough that most individual buildings are no longer discernible, you
|
||||
should still be able to see the extent and variety of development in every neighborhood,
|
||||
not just the largest downtown buildings.
|
||||
|
||||
@@ -57,8 +57,8 @@ compiler errors.
|
||||
Usage
|
||||
-----
|
||||
|
||||
```sh
|
||||
$ tippecanoe -o file.mbtiles [options] [file.json file.json.gz file.fgb ...]
|
||||
```
|
||||
$ tippecanoe -o file.mbtiles [options] [file.json file.json.gz file.fgb file.csv ...]
|
||||
```
|
||||
|
||||
If no files are specified, it reads GeoJSON from the standard input.
|
||||
@@ -99,7 +99,7 @@ $ tippecanoe -o alameda.mbtiles -l alameda -n "Alameda County from TIGER" -z13 t
|
||||
Create a tileset of all TIGER roads, at only zoom level 12, but with higher detail than normal,
|
||||
with a custom layer name and description, and leaving out the `LINEARID` and `RTTYP` attributes:
|
||||
|
||||
```
|
||||
```sh
|
||||
$ cat tiger/tl_2014_*_roads.json | tippecanoe -o tiger.mbtiles -l roads -n "All TIGER roads, one zoom" -z12 -Z12 -d14 -x LINEARID -x RTTYP
|
||||
```
|
||||
|
||||
@@ -108,7 +108,7 @@ Cookbook
|
||||
|
||||
### Linear features (world railroads), visible at all zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_railroads.zip
|
||||
unzip ne_10m_railroads.zip
|
||||
ogr2ogr -f GeoJSON ne_10m_railroads.geojson ne_10m_railroads.shp
|
||||
@@ -122,7 +122,7 @@ tippecanoe -zg -o ne_10m_railroads.mbtiles --drop-densest-as-needed --extend-zoo
|
||||
|
||||
### Discontinuous polygon features (buildings of Rhode Island), visible at all zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/RhodeIsland.zip
|
||||
unzip RhodeIsland.zip
|
||||
|
||||
@@ -135,7 +135,7 @@ tippecanoe -zg -o RhodeIsland.mbtiles --drop-densest-as-needed --extend-zooms-if
|
||||
|
||||
### Continuous polygon features (states and provinces), visible at all zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip
|
||||
unzip -o ne_10m_admin_1_states_provinces.zip
|
||||
ogr2ogr -f GeoJSON ne_10m_admin_1_states_provinces.geojson ne_10m_admin_1_states_provinces.shp
|
||||
@@ -149,7 +149,7 @@ tippecanoe -zg -o ne_10m_admin_1_states_provinces.mbtiles --coalesce-densest-as-
|
||||
|
||||
### Large point dataset (GPS bus locations), for visualization at all zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O ftp://avl-data.sfmta.com/avl_data/avl_raw/sfmtaAVLRawData01012013.csv
|
||||
sed 's/PREDICTABLE.*/PREDICTABLE/' sfmtaAVLRawData01012013.csv > sfmta.csv
|
||||
tippecanoe -zg -o sfmta.mbtiles --drop-densest-as-needed --extend-zooms-if-still-dropping sfmta.csv
|
||||
@@ -163,7 +163,7 @@ tippecanoe -zg -o sfmta.mbtiles --drop-densest-as-needed --extend-zooms-if-still
|
||||
|
||||
### Clustered points (world cities), summing the clustered population, visible at all zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
|
||||
unzip -o ne_10m_populated_places.zip
|
||||
ogr2ogr -f GeoJSON ne_10m_populated_places.geojson ne_10m_populated_places.shp
|
||||
@@ -178,7 +178,7 @@ tippecanoe -zg -o ne_10m_populated_places.mbtiles -r1 --cluster-distance=10 --ac
|
||||
|
||||
### Show countries at low zoom levels but states at higher zoom levels
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip
|
||||
unzip ne_10m_admin_0_countries.zip
|
||||
ogr2ogr -f GeoJSON ne_10m_admin_0_countries.geojson ne_10m_admin_0_countries.shp
|
||||
@@ -206,7 +206,7 @@ States and Provinces:
|
||||
|
||||
### Represent multiple sources (Illinois and Indiana counties) as separate layers
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/COUNTY/2010/tl_2010_17_county10.zip
|
||||
unzip tl_2010_17_county10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_17_county10.geojson tl_2010_17_county10.shp
|
||||
@@ -224,7 +224,7 @@ tippecanoe -zg -o counties-separate.mbtiles --coalesce-densest-as-needed --exten
|
||||
|
||||
### Merge multiple sources (Illinois and Indiana counties) into the same layer
|
||||
|
||||
```
|
||||
```sh
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/COUNTY/2010/tl_2010_17_county10.zip
|
||||
unzip tl_2010_17_county10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_17_county10.geojson tl_2010_17_county10.shp
|
||||
@@ -242,7 +242,7 @@ As above, but
|
||||
|
||||
### Selectively remove and replace features (Census tracts) to update a tileset
|
||||
|
||||
```
|
||||
```sh
|
||||
# Retrieve and tile California 2000 Census tracts
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/TRACT/2000/tl_2010_06_tract00.zip
|
||||
unzip tl_2010_06_tract00.zip
|
||||
@@ -291,6 +291,11 @@ 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.
|
||||
@@ -301,9 +306,9 @@ If your input is formatted as newline-delimited GeoJSON, use `-P` to make input
|
||||
|
||||
### Tileset description and attribution
|
||||
|
||||
* `-n` _name_ or `--name=`_name_: Human-readable name for the tileset (default file.json)
|
||||
* `-n` _name_ or `--name=`_name_: Human-readable name for the tileset (default: the name of the output file or directory)
|
||||
* `-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 file.mbtiles)
|
||||
* `-N` _description_ or `--description=`_description_: Description for the tileset (default: the name of the output file or directory)
|
||||
|
||||
### Input files and layer names
|
||||
|
||||
@@ -316,11 +321,11 @@ If your input is formatted as newline-delimited GeoJSON, use `-P` to make input
|
||||
* `-L` _name_`:`_file.json_ or `--named-layer=`_name_`:`_file.json_: Specify layer names for individual files. If your shell supports it, you can use a subshell redirect like `-L` _name_`:<(cat dir/*.json)` to specify a layer name for the output of streamed input.
|
||||
* `-L{`_layer-json_`}` or `--named-layer={`_layer-json_`}`: Specify an input file and layer options by a JSON object. The JSON object must contain a `"file"` key to specify the filename to read from. (If the `"file"` key is an empty string, it means to read from the standard input stream.) It may also contain a `"layer"` field to specify the name of the layer, and/or a `"description"` field to specify the layer's description in the tileset metadata, and/or a `"format"` field to specify `csv` or `fgb` file format if it is not obvious from the `name`. Example:
|
||||
|
||||
```
|
||||
```sh
|
||||
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 `latitude`, `longitude`, `lat`, `lon`, `long`, `lng`, `x`, or `y`.
|
||||
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.
|
||||
|
||||
### Parallel processing of input
|
||||
|
||||
@@ -352,7 +357,7 @@ Parallel processing will also be automatic if the input file is in FlatGeobuf fo
|
||||
specified maximum zoom and to any levels added beyond that.
|
||||
* `--extend-zooms-if-still-dropping-maximum=`_count_: Increase the maxzoom if features are still being dropped at that zoom level
|
||||
by up to _count_ zoom levels.
|
||||
* `-at` or `--generate-variable-depth-tile-pyramid`: Don't produce child tiles for any tile that should be sufficient to be overzoomed to any higher zoom level. Such tiles will be produced with maximum detail and no simplification or polygon cleaning. Tiles with point features below the basezoom or where any features have to be dropped dynamically, or which contain too many features or bytes with full detail, will be written out with normal detail and split into child tiles. Tilesets generated with this option are suitable for use only with tile servers that will find the appropriate tile to overzoom from and will simplify and clean the geometries appropriately before serving the tile.
|
||||
* `-at` or `--generate-variable-depth-tile-pyramid`: Don't produce child tiles for any tile that should be sufficient to be overzoomed to any higher zoom level. Such tiles will be produced with maximum detail, retaining every vertex that is not collinear with its neighbors, but their polygons are still cleaned so that overlapping areas are merged rather than left stacked. Tiles with point features below the basezoom, or which contain too many features or bytes with full detail, will be written out with normal detail and split into child tiles. If any features have to be dropped dynamically at a zoom level, no tile in that zoom level is truncated, so that the whole zoom level is reduced consistently; any tile that was already being skipped because an ancestor had been truncated is written out after all. Tilesets generated with this option are suitable for use only with tile servers that will find the appropriate tile to overzoom from and will simplify the geometries appropriately before serving the tile.
|
||||
* `-R` _zoom_`/`_x_`/`_y_ or `--one-tile=`_zoom_`/`_x_`/`_y_: Set the minzoom and maxzoom to _zoom_ and produce only
|
||||
the single specified tile at that zoom level.
|
||||
|
||||
@@ -415,11 +420,12 @@ 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`, or `comma`
|
||||
`sum`, `product`, `mean`, `max`, `min`, `concat`, `comma`, or `count`
|
||||
to specify how the named _attribute_ is accumulated onto the attribute of the same name in a feature that does survive.
|
||||
The attributes and operations may also be specified as JSON keys and values: `--accumulate-attribute='{"attr": "operation", "attr2", "operation2"}'`.
|
||||
(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}'`.
|
||||
The attributes and values may also be specified as JSON keys and values: `--set-attribute='{"attr": value, "attr2": value}'`.
|
||||
* `-pe` or `--empty-csv-columns-are-null`: Treat empty CSV columns as nulls rather than as empty strings.
|
||||
* `-aI` or `--convert-stringified-ids-to-numbers`: If a feature ID is the string representation of a number, convert it to a plain number to use as the feature ID.
|
||||
* `--use-attribute-for-id=`*name*: Use the attribute with the specified *name* as if it were specified as the feature ID. (If this attribute is a stringified number, you must also use `-aI` to convert it to a number.)
|
||||
@@ -433,20 +439,20 @@ be reduced to the maximum that can be used with the specified _maxzoom_.
|
||||
|
||||
Example: to find the Natural Earth countries with low `scalerank` but high `LABELRANK`:
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -z5 -o filtered.mbtiles -j '{ "ne_10m_admin_0_countries": [ "all", [ "<", "scalerank", 3 ], [ ">", "LABELRANK", 5 ] ] }' ne_10m_admin_0_countries.geojson
|
||||
```
|
||||
|
||||
Example: to retain only major TIGER roads at low zoom levels:
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -o roads.mbtiles -j '{ "*": [ "any", [ ">=", "$zoom", 11 ], [ "in", "MTFCC", "S1100", "S1200" ] ] }' tl_2015_06001_roads.json
|
||||
```
|
||||
|
||||
Tippecanoe also accepts expressions of the form `[ "attribute-filter", name, expression ]`, to filter individual feature attributes
|
||||
instead of entire features. For example, you can exclude the road names at low zoom levels by doing
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -o roads.mbtiles -j '{ "*": [ "attribute-filter", "FULLNAME", [ ">=", "$zoom", 9 ] ] }' tl_2015_06001_roads.json
|
||||
```
|
||||
|
||||
@@ -466,31 +472,34 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
|
||||
If you use `-Bg`, it will guess a zoom level that will keep at most 50,000 features in the densest tile.
|
||||
You can also specify a marker-width with `-Bg`*width* to allow fewer features in the densest tile to
|
||||
compensate for the larger marker, or `-Bf`*number* to allow at most *number* features in the densest tile.
|
||||
* `--retain-points-multiplier=`_multiple_: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the `-m` option to `tippecanoe-overzoom`. The start of each cluster is marked in the feature sequence by the `tippecanoe:retain_points_multiplier_first` attribute. The `--tile-size-limit` will also be extended at low zoom levels to allow for the multiplied features.
|
||||
* `--retain-points-multiplier=`_multiple_: Retain the specified multiple of points instead of just the number of points that would ordinarily be retained by the drop rate. These can be thinned out later with the `-m` option to `tippecanoe-overzoom`. The start of each cluster is marked in the feature sequence by the `tippecanoe:retain_points_multiplier_first` attribute. The maximum tile size (`--maximum-tile-bytes`) 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 specfied 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-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
|
||||
|
||||
* `-as` or `--drop-densest-as-needed`: If a tile is too large, try to reduce it to under 500K by increasing the minimum spacing between features. The discovered spacing applies to the entire zoom level.
|
||||
* `-ad` or `--drop-fraction-as-needed`: Dynamically drop some fraction of features from each zoom level to keep large tiles under the 500K size limit. (This is like `-pd` but applies to the entire zoom level, not to each tile.)
|
||||
* `-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.
|
||||
* `-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.)
|
||||
* `-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.)
|
||||
* `-pd` or `--force-feature-limit`: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. (This is like `-ad` but applies to each tile individually, not to the entire zoom level.) You probably don't want to use this.
|
||||
* `-aC` or `--cluster-densest-as-needed`: If a tile is too large, try to reduce its size by increasing the minimum spacing between features, and leaving one placeholder feature from each group. The remaining feature will be given a `"clustered": true` attribute to indicate that it represents a cluster, a `"point_count"` attribute to indicate the number of features that were clustered into it, and a `"sqrt_point_count"` attribute to indicate the relative width of a feature to represent the cluster. If the features being clustered are points, the representative feature will be located at the average of the original points' locations; otherwise, one of the original features will be left as the representative.
|
||||
* `-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.
|
||||
|
||||
### Dropping tightly overlapping features
|
||||
|
||||
* `-g` _gamma_ or `--gamma=_gamma`_: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number.
|
||||
* `-g` _gamma_ or `--gamma=`_gamma_: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number.
|
||||
* `-aG` or `--increase-gamma-as-needed`: If a tile is too large, try to reduce it to under 500K by increasing the `-g` gamma. The discovered gamma applies to the entire zoom level. You probably want to use `--drop-densest-as-needed` instead.
|
||||
|
||||
### Line and polygon simplification
|
||||
@@ -508,7 +517,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
|
||||
@@ -567,9 +576,16 @@ 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`.
|
||||
* `-u` or `--json-progress`: like `--quiet` but logs progress as a JSON object. Use in combination with `-U`.
|
||||
|
||||
### Version
|
||||
|
||||
* `-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
|
||||
@@ -597,7 +613,7 @@ contain `index`, `sequence`, `extent`, and `dropped`, elements, which must be pa
|
||||
* Make a tileset of the Natural Earth countries to zoom level 5, and also copy the GeoJSON features
|
||||
to files in a `tiles/z/x/y.geojson` directory hierarchy.
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -o countries.mbtiles -z5 -C 'mkdir -p tiles/$1/$2; tee tiles/$1/$2/$3.geojson' ne_10m_admin_0_countries.json
|
||||
```
|
||||
|
||||
@@ -605,13 +621,13 @@ tippecanoe -o countries.mbtiles -z5 -C 'mkdir -p tiles/$1/$2; tee tiles/$1/$2/$3
|
||||
intersect the [bounding box of Germany](https://www.flickr.com/places/info/23424829).
|
||||
(The `limit-tiles-to-bbox` script is [in the Tippecanoe source directory](filters/limit-tiles-to-bbox).)
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -o countries.mbtiles -z5 -C './filters/limit-tiles-to-bbox 5.8662 47.2702 15.0421 55.0581 $*' ne_10m_admin_0_countries.json
|
||||
```
|
||||
|
||||
* Make a tileset of TIGER roads in Tippecanoe County, leaving out all but primary and secondary roads (as [classified by TIGER](https://www.census.gov/geo/reference/mtfcc.html)) below zoom level 11.
|
||||
|
||||
```
|
||||
```sh
|
||||
tippecanoe -o roads.mbtiles -c 'if [ $1 -lt 11 ]; then grep "\"MTFCC\": \"S1[12]00\""; else cat; fi' tl_2016_18157_roads.json
|
||||
```
|
||||
|
||||
@@ -628,7 +644,7 @@ Tippecanoe defines a GeoJSON extension that you can use to specify the minimum a
|
||||
at which an individual feature will be included in the vector tileset being produced.
|
||||
If you have a feature like this:
|
||||
|
||||
```
|
||||
```json
|
||||
{
|
||||
"type" : "Feature",
|
||||
"tippecanoe" : { "maxzoom" : 9, "minzoom" : 4 },
|
||||
@@ -640,7 +656,7 @@ If you have a feature like this:
|
||||
}
|
||||
```
|
||||
|
||||
with a `tippecanoe` object specifiying a `maxzoom` of 9 and a `minzoom` of 4, the feature
|
||||
with a `tippecanoe` object specifying a `maxzoom` of 9 and a `minzoom` of 4, the feature
|
||||
will only appear in the vector tiles for zoom levels 4 through 9. Note that the `tippecanoe`
|
||||
object belongs to the Feature, not to its `properties`. If you specify a `minzoom` for a feature,
|
||||
it will be preserved down to that zoom level even if dot-dropping with `-r` would otherwise have
|
||||
@@ -649,7 +665,7 @@ dropped it.
|
||||
You can also specify a layer name in the `tippecanoe` object, which will take precedence over
|
||||
the filename or name specified using `--layer`, like this:
|
||||
|
||||
```
|
||||
```json
|
||||
{
|
||||
"type" : "Feature",
|
||||
"tippecanoe" : { "layer" : "streets" },
|
||||
@@ -673,11 +689,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 drops 1/2.5 of the dots for each zoom level above the
|
||||
For point features, it keeps only 1/2.5 of the dots for each zoom level below 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),
|
||||
@@ -703,8 +719,13 @@ lower resolutions before failing if it still doesn't fit.
|
||||
Development
|
||||
-----------
|
||||
|
||||
Requires sqlite3 and zlib (should already be installed on MacOS). Rebuilding the manpage
|
||||
uses md2man (`gem install md2man`).
|
||||
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.
|
||||
|
||||
Linux:
|
||||
|
||||
@@ -718,15 +739,16 @@ and perhaps
|
||||
|
||||
make install
|
||||
|
||||
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 lastest XCode should
|
||||
get you a new enough version of `clang++`. On Linux, you should be able to upgrade `g++` with
|
||||
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
|
||||
|
||||
```
|
||||
```sh
|
||||
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y g++-5
|
||||
export CXX=g++-5
|
||||
sudo apt-get install -y g++-9
|
||||
export CXX=g++-9
|
||||
```
|
||||
|
||||
Docker Image
|
||||
@@ -779,11 +801,14 @@ 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.
|
||||
* `-r` or `--read-from`: list of input mbtiles to read from.
|
||||
|
||||
### 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.
|
||||
|
||||
### Overzooming
|
||||
|
||||
* `--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.
|
||||
* `-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.
|
||||
* `--buffer=`_pixels_ or `-b` _pixels_: Set the size of the tile buffer in the overzoomed tiles.
|
||||
|
||||
### Tileset description and attribution
|
||||
@@ -812,6 +837,8 @@ 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.
|
||||
@@ -826,6 +853,10 @@ 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.
|
||||
@@ -858,7 +889,7 @@ awk 'BEGIN {
|
||||
|
||||
which looks like this:
|
||||
|
||||
```
|
||||
```csv
|
||||
GEOID10,population
|
||||
"060014277003018",0
|
||||
"060014283014046",0
|
||||
@@ -916,8 +947,10 @@ 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`: Report coordinates in integer tile coordinates
|
||||
* `-F` or `--fraction`: Report coordinates as a fraction of the tile extent
|
||||
* `-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.)
|
||||
|
||||
tippecanoe-json-tool
|
||||
====================
|
||||
@@ -956,7 +989,7 @@ for Tippecanoe County, Indiana.
|
||||
|
||||
Download Census block geometry, and convert to GeoJSON:
|
||||
|
||||
```
|
||||
```sh
|
||||
$ curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/TABBLOCK/2010/tl_2010_18157_tabblock10.zip
|
||||
$ unzip tl_2010_18157_tabblock10.zip
|
||||
$ ogr2ogr -f GeoJSON tl_2010_18157_tabblock10.json tl_2010_18157_tabblock10.shp
|
||||
@@ -964,7 +997,7 @@ $ ogr2ogr -f GeoJSON tl_2010_18157_tabblock10.json tl_2010_18157_tabblock10.shp
|
||||
|
||||
Download Indiana employment data, and fix name of join key in header
|
||||
|
||||
```
|
||||
```sh
|
||||
$ curl -L -O https://lehd.ces.census.gov/data/lodes/LODES7/in/wac/in_wac_S000_JT00_2015.csv.gz
|
||||
$ gzip -dc in_wac_S000_JT00_2015.csv.gz | sed '1s/w_geocode/GEOID10/' > in_wac_S000_JT00_2015.csv
|
||||
```
|
||||
@@ -972,13 +1005,13 @@ $ gzip -dc in_wac_S000_JT00_2015.csv.gz | sed '1s/w_geocode/GEOID10/' > in_wac_S
|
||||
Sort GeoJSON block geometry so it is ordered by block ID. If you don't do this, you will get a
|
||||
"GeoJSON file is out of sort" error.
|
||||
|
||||
```
|
||||
```sh
|
||||
$ tippecanoe-json-tool -e GEOID10 tl_2010_18157_tabblock10.json | LC_ALL=C sort > tl_2010_18157_tabblock10.sort.json
|
||||
```
|
||||
|
||||
Join block geometries to employment attributes:
|
||||
|
||||
```
|
||||
```sh
|
||||
$ tippecanoe-json-tool -c in_wac_S000_JT00_2015.csv tl_2010_18157_tabblock10.sort.json > blocks-wac.json
|
||||
```
|
||||
|
||||
@@ -1004,10 +1037,19 @@ and produces tile `outz/outx/outy` of `out.mvt.gz` from them.
|
||||
|
||||
### Options
|
||||
|
||||
* `-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.
|
||||
* `-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.
|
||||
* `--preserve-input-order`: Restore a set of filtered features to its original input order
|
||||
* `--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.
|
||||
* `-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.
|
||||
|
||||
+73
-48
@@ -6,6 +6,13 @@
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "milo/dtoa_milo.h"
|
||||
|
||||
std::map<std::string, attribute_op> numeric_operations = {
|
||||
{"sum", op_sum},
|
||||
{"min", op_min},
|
||||
{"max", op_max},
|
||||
{"count", op_count},
|
||||
};
|
||||
|
||||
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, std::string name, std::string type) {
|
||||
attribute_op t;
|
||||
|
||||
@@ -81,83 +88,101 @@ void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribut
|
||||
set_attribute_accum(attribute_accum, name, type);
|
||||
}
|
||||
|
||||
void preserve_attribute(attribute_op const &op, std::string const &key, serial_val const &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::unordered_map<std::string, accum_state> &attribute_accum_state) {
|
||||
template <class T>
|
||||
static void preserve_attribute1(attribute_op const &op, std::string const &key, T const &val, std::vector<std::shared_ptr<std::string>> &full_keys, std::vector<T> &full_values, key_pool &key_pool) {
|
||||
for (size_t i = 0; i < full_keys.size(); i++) {
|
||||
if (key == full_keys[i]) {
|
||||
if (key == *full_keys[i]) {
|
||||
switch (op) {
|
||||
case op_sum:
|
||||
full_values[i].s = milo::dtoa_milo(atof(full_values[i].s.c_str()) + atof(val.s.c_str()));
|
||||
full_values[i].type = mvt_double;
|
||||
break;
|
||||
full_values[i] = (full_values[i].to_double() + val.to_double());
|
||||
return;
|
||||
|
||||
case op_product:
|
||||
full_values[i].s = milo::dtoa_milo(atof(full_values[i].s.c_str()) * atof(val.s.c_str()));
|
||||
full_values[i].type = mvt_double;
|
||||
break;
|
||||
full_values[i] = (full_values[i].to_double() * val.to_double());
|
||||
return;
|
||||
|
||||
case op_max: {
|
||||
double existing = atof(full_values[i].s.c_str());
|
||||
double maybe = atof(val.s.c_str());
|
||||
double existing = full_values[i].to_double();
|
||||
double maybe = val.to_double();
|
||||
if (maybe > existing) {
|
||||
full_values[i].s = val.s.c_str();
|
||||
full_values[i].type = mvt_double;
|
||||
full_values[i] = val;
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
case op_min: {
|
||||
double existing = atof(full_values[i].s.c_str());
|
||||
double maybe = atof(val.s.c_str());
|
||||
double existing = full_values[i].to_double();
|
||||
double maybe = val.to_double();
|
||||
if (maybe < existing) {
|
||||
full_values[i].s = val.s.c_str();
|
||||
full_values[i].type = mvt_double;
|
||||
full_values[i] = val;
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
case op_mean: {
|
||||
auto state = attribute_accum_state.find(key);
|
||||
if (state == attribute_accum_state.end()) {
|
||||
accum_state s;
|
||||
s.sum = atof(full_values[i].s.c_str()) + atof(val.s.c_str());
|
||||
s.count = 2;
|
||||
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
|
||||
|
||||
full_values[i].s = milo::dtoa_milo(s.sum / s.count);
|
||||
size_t count = full_values[i].get_count();
|
||||
if (count <= 1) {
|
||||
full_values[i].set_double_count((full_values[i].to_double() + val.to_double()) / 2, 2);
|
||||
} else {
|
||||
state->second.sum += atof(val.s.c_str());
|
||||
state->second.count += 1;
|
||||
|
||||
full_values[i].s = milo::dtoa_milo(state->second.sum / state->second.count);
|
||||
double sum = full_values[i].to_double() * count + val.to_double();
|
||||
count++;
|
||||
full_values[i].set_double_count(sum / count, count);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
case op_concat:
|
||||
full_values[i].s += val.s;
|
||||
full_values[i].type = mvt_string;
|
||||
break;
|
||||
full_values[i].set_string_value(full_values[i].get_string_value() + val.get_string_value());
|
||||
return;
|
||||
|
||||
case op_comma:
|
||||
full_values[i].s += std::string(",") + val.s;
|
||||
full_values[i].type = mvt_string;
|
||||
break;
|
||||
full_values[i].set_string_value(full_values[i].get_string_value() + "," + val.get_string_value());
|
||||
return;
|
||||
|
||||
case op_count: {
|
||||
auto state = attribute_accum_state.find(key);
|
||||
if (state == attribute_accum_state.end()) { // not already present
|
||||
accum_state s;
|
||||
s.count = 2;
|
||||
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
|
||||
|
||||
full_values[i].s = std::to_string(s.count);
|
||||
} else { // already present, incrementing
|
||||
state->second.count += 1;
|
||||
full_values[i].s = std::to_string(state->second.count);
|
||||
size_t count = full_values[i].get_count();
|
||||
if (count <= 1) {
|
||||
full_values[i].set_double_count(2, 2);
|
||||
} else {
|
||||
full_values[i].set_double_count(count + 1, count + 1);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found, so we are making a new value
|
||||
|
||||
T v;
|
||||
switch (op) {
|
||||
case op_sum:
|
||||
case op_max:
|
||||
case op_min:
|
||||
v = val;
|
||||
break;
|
||||
|
||||
case op_count:
|
||||
v.set_double_count(1, 1);
|
||||
break;
|
||||
|
||||
case op_mean:
|
||||
v.set_double_count(val.to_double(), 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
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));
|
||||
full_values.push_back(v);
|
||||
}
|
||||
|
||||
void preserve_attribute(attribute_op const &op, std::string const &key, mvt_value const &val, std::vector<std::shared_ptr<std::string>> &full_keys, std::vector<mvt_value> &full_values, key_pool &key_pool) {
|
||||
preserve_attribute1(op, key, val, full_keys, full_values, key_pool);
|
||||
}
|
||||
|
||||
void preserve_attribute(attribute_op const &op, std::string const &key, serial_val const &val, std::vector<std::shared_ptr<std::string>> &full_keys, std::vector<serial_val> &full_values, key_pool &key_pool) {
|
||||
preserve_attribute1(op, key, val, full_keys, full_values, key_pool);
|
||||
}
|
||||
|
||||
+10
-6
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "mvt.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
|
||||
enum attribute_op {
|
||||
op_sum,
|
||||
@@ -15,15 +19,15 @@ enum attribute_op {
|
||||
op_count,
|
||||
};
|
||||
|
||||
struct accum_state {
|
||||
double sum = 0;
|
||||
double count = 0;
|
||||
};
|
||||
|
||||
struct serial_val;
|
||||
struct key_pool;
|
||||
|
||||
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, std::string name, std::string type);
|
||||
void set_attribute_accum(std::unordered_map<std::string, attribute_op> &attribute_accum, const char *arg, char **argv);
|
||||
void preserve_attribute(attribute_op const &op, const std::string &key, serial_val const &val, std::vector<std::string> &full_keys, std::vector<serial_val> &full_values, std::unordered_map<std::string, accum_state> &attribute_accum_state);
|
||||
|
||||
void preserve_attribute(attribute_op const &op, std::string const &key, serial_val const &val, std::vector<std::shared_ptr<std::string>> &full_keys, std::vector<serial_val> &full_values, key_pool &key_pool);
|
||||
void preserve_attribute(attribute_op const &op, std::string const &key, mvt_value const &val, std::vector<std::shared_ptr<std::string>> &full_keys, std::vector<mvt_value> &full_values, key_pool &key_pool);
|
||||
|
||||
extern std::map<std::string, attribute_op> numeric_operations;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mapbox/geometry/point.hpp>
|
||||
#include <mapbox/geometry/multi_polygon.hpp>
|
||||
#include <mapbox/geometry/wagyu/wagyu.hpp>
|
||||
#include <clipper2/clipper.h>
|
||||
#include <limits.h>
|
||||
#include "geometry.hpp"
|
||||
#include "errors.hpp"
|
||||
@@ -13,6 +14,7 @@
|
||||
#include "serial.hpp"
|
||||
#include "attribute.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "read_json.hpp"
|
||||
|
||||
static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<double, double>> &geom,
|
||||
long long minx, long long miny, long long maxx, long long maxy,
|
||||
@@ -385,6 +387,123 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
|
||||
return ret;
|
||||
}
|
||||
|
||||
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
mapbox::geometry::multi_polygon<long long> result;
|
||||
|
||||
{
|
||||
mapbox::geometry::wagyu::wagyu<long long> wagyu;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
mapbox::geometry::linear_ring<long long> lr;
|
||||
lr.push_back(mapbox::geometry::point<long long>(geom[i].x, geom[i].y));
|
||||
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
lr.push_back(mapbox::geometry::point<long long>(geom[j].x, geom[j].y));
|
||||
}
|
||||
|
||||
if (lr.size() >= 4) {
|
||||
wagyu.add_ring(lr);
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bounds.size(); i++) {
|
||||
if (bounds[i].op == VT_MOVETO) {
|
||||
mapbox::geometry::linear_ring<long long> lr;
|
||||
lr.push_back(mapbox::geometry::point<long long>(bounds[i].x, bounds[i].y));
|
||||
|
||||
size_t j;
|
||||
for (j = i + 1; j < bounds.size(); j++) {
|
||||
if (bounds[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
lr.push_back(mapbox::geometry::point<long long>(bounds[j].x, bounds[j].y));
|
||||
}
|
||||
|
||||
if (lr.size() >= 4) {
|
||||
wagyu.add_ring(lr, mapbox::geometry::wagyu::polygon_type_clip);
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
fprintf(stderr, "Internal error: Polygon clipping failed\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
drawvec ret;
|
||||
decode_clipped(result, ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
drawvec out;
|
||||
for (auto const &p : geom) {
|
||||
if (pnpoly_mp(bounds, p.x, p.y)) {
|
||||
out.push_back(p);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static Clipper2Lib::Paths64 geom_to_clipper(drawvec const &geom) {
|
||||
Clipper2Lib::Paths64 subject;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
Clipper2Lib::Path64 path({{geom[i].x, geom[i].y}});
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
path.emplace_back(geom[j].x, geom[j].y);
|
||||
}
|
||||
subject.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
static void clipper_to_geom(Clipper2Lib::Paths64 const &geom, drawvec &out) {
|
||||
for (auto const &ring : geom) {
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
out.emplace_back(i == 0 ? VT_MOVETO : VT_LINETO, ring[i].x, ring[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawvec clip_lines_poly(drawvec const &geom, drawvec const ®ion) {
|
||||
Clipper2Lib::Paths64 subject = geom_to_clipper(geom);
|
||||
Clipper2Lib::Paths64 clip = geom_to_clipper(region);
|
||||
|
||||
Clipper2Lib::Clipper64 clipper;
|
||||
clipper.AddOpenSubject(subject);
|
||||
clipper.AddClip(clip);
|
||||
|
||||
Clipper2Lib::Paths64 solution, open_solution;
|
||||
clipper.Execute(Clipper2Lib::ClipType::Intersection, Clipper2Lib::FillRule::Positive, solution, open_solution);
|
||||
|
||||
drawvec out;
|
||||
clipper_to_geom(solution, out);
|
||||
clipper_to_geom(open_solution, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void to_tile_scale(drawvec &geom, int z, int detail) {
|
||||
if (32 - detail - z < 0) {
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
@@ -452,8 +571,7 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
|
||||
}
|
||||
|
||||
if (geom[i + 1].op == VT_CLOSEPATH) {
|
||||
// followed by closepath: not possible
|
||||
fprintf(stderr, "Shouldn't happen\n");
|
||||
// followed by closepath: only possible after close_poly()
|
||||
i++; // also remove unused closepath
|
||||
continue;
|
||||
}
|
||||
@@ -1075,13 +1193,42 @@ bool pnpoly_mp(std::vector<mvt_geometry> const &geom, long long x, long long y)
|
||||
return found;
|
||||
}
|
||||
|
||||
bool pnpoly_mp(drawvec const &geom, long long x, long long y) {
|
||||
// assumes rings are properly nested, so inside a hole matches twice
|
||||
bool found = false;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
found ^= pnpoly(geom, i, j - i, x, y);
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
int detail_or_unspecified, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix,
|
||||
bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::vector<std::string> const &unidecode_data, double simplification,
|
||||
double tiny_polygon_size, std::vector<mvt_layer> const &bins) {
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &unused2, std::string const &unused3,
|
||||
std::string const &unused, size_t feature_limit,
|
||||
std::vector<clipbbox> const &unused4,
|
||||
bool deduplicate_by_id) {
|
||||
std::vector<source_tile> decoded;
|
||||
|
||||
for (auto const &t : tiles) {
|
||||
@@ -1107,9 +1254,10 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
|
||||
decoded.push_back(out);
|
||||
}
|
||||
|
||||
return overzoom(decoded, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
|
||||
return overzoom(decoded, nz, nx, ny, detail_or_unspecified, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, unused2, unused3, unused, feature_limit, unused4, deduplicate_by_id);
|
||||
}
|
||||
|
||||
// like a minimal serial_feature, but with mvt_feature-style attributes
|
||||
struct tile_feature {
|
||||
drawvec geom;
|
||||
int t;
|
||||
@@ -1120,17 +1268,100 @@ struct tile_feature {
|
||||
size_t seq = 0;
|
||||
};
|
||||
|
||||
static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer, std::set<std::string> const &keep, std::unordered_map<std::string, attribute_op> const &attribute_accum, std::shared_ptr<std::string> const &tile_stringpool) {
|
||||
static bool should_keep(std::string const &key,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix) {
|
||||
if (keep.size() == 0 || keep.find(key) != keep.end()) {
|
||||
if (exclude.find(key) != exclude.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto const &prefix : exclude_prefix) {
|
||||
if (starts_with(key, prefix)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void handle_closepath_from_mvt(drawvec &geom) {
|
||||
// mvt geometries close polygons with a mvt_closepath operation
|
||||
// tippecanoe-internal geometries close polygons with a lineto to the initial point
|
||||
|
||||
size_t last_open = 0;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == mvt_closepath) {
|
||||
geom[i] = draw(mvt_lineto, geom[last_open].x, geom[last_open].y);
|
||||
} else if (geom[i].op == mvt_moveto) {
|
||||
last_open = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if a feature was output; false if it was clipped away
|
||||
static bool feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix,
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::string const &,
|
||||
key_pool &key_pool, int buffer, bool include_nonaggregate,
|
||||
std::vector<clipbbox> const &, int, int, int,
|
||||
std::set<unsigned long long> *deduplicate_ids) {
|
||||
// Add geometry to output feature
|
||||
|
||||
drawvec geom = features[0].geom;
|
||||
int t = features[0].t;
|
||||
|
||||
bool fix_polygons = false;
|
||||
if ((buffer >= 0) && t == VT_POLYGON) {
|
||||
fix_polygons = true;
|
||||
}
|
||||
|
||||
if (fix_polygons) {
|
||||
handle_closepath_from_mvt(geom);
|
||||
}
|
||||
|
||||
if (buffer >= 0) {
|
||||
if (t == VT_LINE) {
|
||||
geom = clip_lines(geom, 32 - outlayer.detail(), buffer);
|
||||
} else if (t == VT_POLYGON) {
|
||||
drawvec dv;
|
||||
geom = simple_clip_poly(geom, 32 - outlayer.detail(), buffer, dv, false);
|
||||
} else if (t == VT_POINT) {
|
||||
geom = clip_point(geom, 32 - outlayer.detail(), buffer);
|
||||
}
|
||||
|
||||
geom = remove_noop(geom, t, 0);
|
||||
}
|
||||
|
||||
if (fix_polygons) {
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, false);
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
mvt_feature outfeature;
|
||||
outfeature.type = features[0].t;
|
||||
for (auto const &g : features[0].geom) {
|
||||
for (auto const &g : geom) {
|
||||
outfeature.geometry.emplace_back(g.op, g.x, g.y);
|
||||
}
|
||||
|
||||
// ID and attributes, if it didn't get clipped away
|
||||
|
||||
if (features[0].has_id && deduplicate_ids != NULL) {
|
||||
if (deduplicate_ids->find(features[0].id) != deduplicate_ids->end()) {
|
||||
outfeature.geometry.clear();
|
||||
} else {
|
||||
deduplicate_ids->insert(features[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
if (outfeature.geometry.size() > 0) {
|
||||
if (features[0].has_id) {
|
||||
outfeature.has_id = true;
|
||||
@@ -1141,24 +1372,25 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
|
||||
if (attribute_accum.size() > 0) {
|
||||
// convert the attributes of the output feature
|
||||
// from mvt_value to serial_val so they can have
|
||||
// from layer references to a vector so they can have
|
||||
// attributes from the other features of the
|
||||
// multiplier cluster accumulated onto them
|
||||
|
||||
std::unordered_map<std::string, accum_state> attribute_accum_state;
|
||||
std::vector<std::string> full_keys;
|
||||
std::vector<serial_val> full_values;
|
||||
std::vector<std::shared_ptr<std::string>> full_keys;
|
||||
std::vector<mvt_value> full_values;
|
||||
std::map<std::string, size_t> numeric_out_field;
|
||||
|
||||
for (size_t i = 0; i + 1 < features[0].tags.size(); i += 2) {
|
||||
auto f = attribute_accum.find(features[0].layer->keys[features[0].tags[i]]);
|
||||
if (f != attribute_accum.end()) {
|
||||
// this attribute has an accumulator, so convert it
|
||||
full_keys.push_back(features[0].layer->keys[features[0].tags[i]]);
|
||||
full_values.push_back(mvt_value_to_serial_val(features[0].layer->values[features[0].tags[i + 1]]));
|
||||
} else {
|
||||
// otherwise just tag it directly onto the output feature
|
||||
if (keep.size() == 0 || keep.find(features[0].layer->keys[features[0].tags[i]]) != keep.end()) {
|
||||
outlayer.tag(outfeature, features[0].layer->keys[features[0].tags[i]], features[0].layer->values[features[0].tags[i + 1]]);
|
||||
auto const &f = features[0];
|
||||
for (size_t i = 0; i + 1 < f.tags.size(); i += 2) {
|
||||
const std::string &key = f.layer->keys[f.tags[i]];
|
||||
if (should_keep(key, keep, exclude, exclude_prefix)) {
|
||||
if (attribute_accum.find(key) != attribute_accum.end()) {
|
||||
// this attribute has an accumulator, so convert it
|
||||
full_keys.push_back(key_pool.pool(f.layer->keys[f.tags[i]]));
|
||||
full_values.push_back(f.layer->values[f.tags[i + 1]]);
|
||||
} else if (include_nonaggregate) {
|
||||
// otherwise just tag it directly onto the output feature
|
||||
outlayer.tag(outfeature, f.layer->keys[f.tags[i]], f.layer->values[f.tags[i + 1]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1168,13 +1400,23 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
// features that will not
|
||||
|
||||
for (size_t i = 1; i < features.size(); i++) {
|
||||
for (size_t j = 0; j + 1 < features[i].tags.size(); j += 2) {
|
||||
std::string key = features[i].layer->keys[features[i].tags[j]];
|
||||
std::set<std::string> keys;
|
||||
|
||||
auto f = attribute_accum.find(key);
|
||||
if (f != attribute_accum.end()) {
|
||||
serial_val val = mvt_value_to_serial_val(features[i].layer->values[features[i].tags[j + 1]]);
|
||||
preserve_attribute(f->second, key, val, full_keys, full_values, attribute_accum_state);
|
||||
for (size_t j = 0; j + 1 < features[i].tags.size(); j += 2) {
|
||||
const std::string &key = features[i].layer->keys[features[i].tags[j]];
|
||||
if (should_keep(key, keep, exclude, exclude_prefix)) {
|
||||
keys.insert(key);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j + 1 < features[i].tags.size(); j += 2) {
|
||||
const std::string &key = features[i].layer->keys[features[i].tags[j]];
|
||||
if (should_keep(key, keep, exclude, exclude_prefix)) {
|
||||
auto found = attribute_accum.find(key);
|
||||
if (found != attribute_accum.end()) {
|
||||
mvt_value val = features[i].layer->values[features[i].tags[j + 1]];
|
||||
preserve_attribute(found->second, key, val, full_keys, full_values, key_pool);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1183,20 +1425,23 @@ static void feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
// and tag them onto the output feature
|
||||
|
||||
for (size_t i = 0; i < full_keys.size(); i++) {
|
||||
if (keep.size() == 0 || keep.find(full_keys[i]) != keep.end()) {
|
||||
outlayer.tag(outfeature, full_keys[i], stringified_to_mvt_value(full_values[i].type, full_values[i].s.c_str(), tile_stringpool));
|
||||
if (should_keep(*full_keys[i], keep, exclude, exclude_prefix)) {
|
||||
outlayer.tag(outfeature, *full_keys[i], full_values[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (include_nonaggregate) {
|
||||
for (size_t i = 0; i + 1 < features[0].tags.size(); i += 2) {
|
||||
if (keep.size() == 0 || keep.find(features[0].layer->keys[features[0].tags[i]]) != keep.end()) {
|
||||
if (should_keep(features[0].layer->keys[features[0].tags[i]], keep, exclude, exclude_prefix)) {
|
||||
outlayer.tag(outfeature, features[0].layer->keys[features[0].tags[i]], features[0].layer->values[features[0].tags[i + 1]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outlayer.features.push_back(std::move(outfeature));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct preservecmp {
|
||||
@@ -1205,294 +1450,32 @@ static struct preservecmp {
|
||||
}
|
||||
} preservecmp;
|
||||
|
||||
struct index_event {
|
||||
unsigned long long where;
|
||||
enum index_event_kind {
|
||||
ENTER = 0, // new bin in is now active
|
||||
CHECK, // point needs to be checked against active bins
|
||||
EXIT // bin has ceased to be active
|
||||
} kind;
|
||||
size_t layer;
|
||||
size_t feature;
|
||||
|
||||
index_event(unsigned long long where_, index_event_kind kind_, size_t layer_, size_t feature_)
|
||||
: where(where_), kind(kind_), layer(layer_), feature(feature_) {
|
||||
}
|
||||
|
||||
bool operator<(const index_event &ie) const {
|
||||
if (where < ie.where) {
|
||||
return true;
|
||||
} else if (where == ie.where) {
|
||||
if (kind < ie.kind) {
|
||||
return true;
|
||||
} else if (kind == ie.kind) {
|
||||
if (layer < ie.layer) {
|
||||
return true;
|
||||
} else if (layer == ie.layer) {
|
||||
if (feature < ie.feature) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct active_bin {
|
||||
size_t layer;
|
||||
size_t feature;
|
||||
|
||||
active_bin(size_t layer_, size_t feature_)
|
||||
: layer(layer_), feature(feature_) {
|
||||
}
|
||||
|
||||
bool operator<(const active_bin &o) const {
|
||||
if (layer < o.layer) {
|
||||
return true;
|
||||
} else if (layer == o.layer) {
|
||||
if (feature < o.feature) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t outfeature;
|
||||
long long xmin, ymin, xmax, ymax;
|
||||
size_t counter = 0;
|
||||
};
|
||||
|
||||
void get_quadkey_bounds(long long xmin, long long ymin, long long xmax, long long ymax,
|
||||
unsigned long long *start, unsigned long long *end) {
|
||||
if (xmin < 0 || ymin < 0 || xmax >= 1LL << 32 || ymax >= 1LL << 32) {
|
||||
*start = 0;
|
||||
*end = ULLONG_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
*start = encode_quadkey(xmin, ymin);
|
||||
*end = encode_quadkey(xmax, ymax);
|
||||
|
||||
for (ssize_t i = 62; i >= 0; i -= 2) {
|
||||
if ((*start & (3LL << i)) != (*end & (3LL << i))) {
|
||||
for (; i >= 0; i -= 2) {
|
||||
*start &= ~(3LL << i);
|
||||
*end |= 3LL << i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mvt_tile assign_to_bins(mvt_tile const &features, std::vector<mvt_layer> const &bins, int z, int x, int y, int detail) {
|
||||
std::vector<index_event> events;
|
||||
|
||||
// Index bins
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
for (size_t j = 0; j < bins[i].features.size(); j++) {
|
||||
long long xmin, ymin, xmax, ymax;
|
||||
unsigned long long start, end;
|
||||
|
||||
get_bbox(bins[i].features[j].geometry, &xmin, &ymin, &xmax, &ymax, z, x, y, detail);
|
||||
get_quadkey_bounds(xmin, ymin, xmax, ymax, &start, &end);
|
||||
events.emplace_back(start, index_event::ENTER, i, j);
|
||||
events.emplace_back(end, index_event::EXIT, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
// Index points
|
||||
for (size_t i = 0; i < features.layers.size(); i++) {
|
||||
for (size_t j = 0; j < features.layers[i].features.size(); j++) {
|
||||
long long xmin, ymin, xmax, ymax;
|
||||
unsigned long long start, end;
|
||||
|
||||
if (features.layers[i].features[j].geometry.size() > 0) {
|
||||
get_bbox(features.layers[i].features[j].geometry, &xmin, &ymin, &xmax, &ymax, z, x, y, detail);
|
||||
get_quadkey_bounds(xmin, ymin, xmax, ymax, &start, &end);
|
||||
events.emplace_back(start, index_event::CHECK, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(events.begin(), events.end());
|
||||
std::set<active_bin> active;
|
||||
std::vector<size_t> counters; // separate because set items can't be mutated from an iterator
|
||||
std::vector<std::map<std::string, double>> sums; // separate because set items can't be mutated from an iterator
|
||||
std::vector<std::map<std::string, double>> maxes; // separate because set items can't be mutated from an iterator
|
||||
std::vector<std::map<std::string, double>> mins; // separate because set items can't be mutated from an iterator
|
||||
std::vector<std::map<std::string, double>> counts; // separate because set items can't be mutated from an iterator
|
||||
|
||||
mvt_layer outlayer;
|
||||
outlayer.extent = 1 << detail;
|
||||
outlayer.version = 2;
|
||||
outlayer.name = features.layers[0].name;
|
||||
|
||||
for (auto &e : events) {
|
||||
if (e.kind == index_event::ENTER) {
|
||||
active_bin a(e.layer, e.feature);
|
||||
|
||||
const mvt_feature &bin = bins[e.layer].features[e.feature];
|
||||
mvt_feature outfeature;
|
||||
outfeature.geometry = bin.geometry;
|
||||
outfeature.type = bin.type;
|
||||
outfeature.has_id = bin.has_id;
|
||||
outfeature.id = bin.id;
|
||||
a.outfeature = outlayer.features.size();
|
||||
|
||||
a.counter = counters.size();
|
||||
counters.push_back(0);
|
||||
sums.emplace_back();
|
||||
maxes.emplace_back();
|
||||
mins.emplace_back();
|
||||
counts.emplace_back();
|
||||
|
||||
outlayer.features.push_back(std::move(outfeature));
|
||||
active.insert(std::move(a));
|
||||
} else if (e.kind == index_event::CHECK) {
|
||||
auto const &feature = features.layers[e.layer].features[e.feature];
|
||||
#if 0
|
||||
for (size_t i = 0; i + 1 < feature.tags.size(); i += 2) {
|
||||
printf("%s ", features.layers[e.layer].values[feature.tags[i + 1]].toString().c_str());
|
||||
}
|
||||
printf(": ");
|
||||
#endif
|
||||
|
||||
for (auto const &a : active) {
|
||||
auto const &bin = bins[a.layer].features[a.feature];
|
||||
|
||||
// XXX do bounding box check first
|
||||
if (pnpoly_mp(bin.geometry, feature.geometry[0].x, feature.geometry[0].y)) {
|
||||
#if 0
|
||||
printf("found: ");
|
||||
|
||||
for (size_t i = 0; i + 1 < bin.tags.size(); i += 2) {
|
||||
printf("%s ", bins[a.first].values[bin.tags[i + 1]].toString().c_str());
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
counters[a.counter]++;
|
||||
|
||||
for (size_t i = 0; i + 1 < feature.tags.size(); i += 2) {
|
||||
const mvt_value &val = features.layers[e.layer].values[feature.tags[i + 1]];
|
||||
const std::string &key = features.layers[e.layer].keys[feature.tags[i]];
|
||||
|
||||
if (val.is_numeric()) {
|
||||
auto sum_attr = sums[a.counter].find(key);
|
||||
if (sum_attr == sums[a.counter].end()) {
|
||||
sums[a.counter].emplace(key, 0);
|
||||
mins[a.counter].emplace(key, std::numeric_limits<double>::infinity());
|
||||
maxes[a.counter].emplace(key, -std::numeric_limits<double>::infinity());
|
||||
counts[a.counter].emplace(key, 0);
|
||||
|
||||
sum_attr = sums[a.counter].find(key);
|
||||
}
|
||||
|
||||
auto min_attr = mins[a.counter].find(key);
|
||||
auto max_attr = maxes[a.counter].find(key);
|
||||
auto count_attr = counts[a.counter].find(key);
|
||||
double v = mvt_value_to_double(val);
|
||||
|
||||
sum_attr->second += v;
|
||||
count_attr->second += 1;
|
||||
min_attr->second = std::min(min_attr->second, v);
|
||||
max_attr->second = std::max(max_attr->second, v);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else /* EXIT */ {
|
||||
auto const &found = active.find({e.layer, e.feature});
|
||||
if (found != active.end()) {
|
||||
mvt_feature &outfeature = outlayer.features[found->outfeature];
|
||||
|
||||
if (counters[found->counter] >= 0) {
|
||||
const mvt_feature &bin = bins[e.layer].features[e.feature];
|
||||
|
||||
// copy attributes from the original bin feature
|
||||
for (size_t i = 0; i + 1 < bin.tags.size(); i += 2) {
|
||||
outlayer.tag(outfeature, bins[e.layer].keys[bin.tags[i]], bins[e.layer].values[bin.tags[i + 1]]);
|
||||
}
|
||||
|
||||
// new attribute for number of features assigned to the bin
|
||||
mvt_value v;
|
||||
v.type = mvt_uint;
|
||||
v.numeric_value.uint_value = counters[found->counter];
|
||||
outlayer.tag(outfeature, "tippecanoe:count", v);
|
||||
|
||||
for (auto const &kv : sums[found->counter]) {
|
||||
mvt_value v_sum;
|
||||
v_sum.type = mvt_double;
|
||||
v_sum.numeric_value.double_value = kv.second;
|
||||
outlayer.tag(outfeature, "tippecanoe:sum:" + kv.first, v_sum);
|
||||
|
||||
mvt_value v_count;
|
||||
v_count.type = mvt_double;
|
||||
v_count.numeric_value.double_value = counts[found->counter][kv.first];
|
||||
outlayer.tag(outfeature, "tippecanoe:count:" + kv.first, v_count);
|
||||
|
||||
mvt_value v_mean;
|
||||
v_mean.type = mvt_double;
|
||||
v_mean.numeric_value.double_value = kv.second / counters[found->counter];
|
||||
outlayer.tag(outfeature, "tippecanoe:mean:" + kv.first, v_mean);
|
||||
|
||||
mvt_value v_min;
|
||||
v_min.type = mvt_double;
|
||||
v_min.numeric_value.double_value = mins[found->counter][kv.first];
|
||||
outlayer.tag(outfeature, "tippecanoe:min:" + kv.first, v_min);
|
||||
|
||||
mvt_value v_max;
|
||||
v_max.type = mvt_double;
|
||||
v_max.numeric_value.double_value = maxes[found->counter][kv.first];
|
||||
outlayer.tag(outfeature, "tippecanoe:max:" + kv.first, v_max);
|
||||
}
|
||||
} else {
|
||||
outfeature.geometry.clear();
|
||||
}
|
||||
|
||||
active.erase(found);
|
||||
} else {
|
||||
fprintf(stderr, "event mismatch: can't happen\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// crunch out bin features whose geometry we cleared along the way
|
||||
size_t out = 0;
|
||||
for (size_t i = 0; i < outlayer.features.size(); i++) {
|
||||
if (outlayer.features[i].geometry.size() > 0) {
|
||||
outlayer.features[out++] = outlayer.features[i];
|
||||
}
|
||||
}
|
||||
outlayer.features.resize(out);
|
||||
#endif
|
||||
|
||||
mvt_tile ret;
|
||||
ret.layers.push_back(outlayer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
int detail_or_unspecified, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix,
|
||||
bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::vector<std::string> const &unidecode_data, double simplification,
|
||||
double tiny_polygon_size, std::vector<mvt_layer> const &bins) {
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &unused2, std::string const &unused3,
|
||||
std::string const &unused, size_t feature_limit,
|
||||
std::vector<clipbbox> const &unused4,
|
||||
bool deduplicate_by_id) {
|
||||
mvt_tile outtile;
|
||||
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
|
||||
key_pool key_pool;
|
||||
|
||||
// map from layer name to ids used in that layer
|
||||
std::map<std::string, std::set<unsigned long long>> deduplicate_ids;
|
||||
|
||||
for (auto const &tile : tiles) {
|
||||
for (auto const &layer : tile.tile.layers) {
|
||||
mvt_layer *outlayer = NULL;
|
||||
|
||||
int det = detail;
|
||||
int det = detail_or_unspecified;
|
||||
if (det <= 0) {
|
||||
det = std::round(log(layer.extent) / log(2));
|
||||
}
|
||||
@@ -1514,6 +1497,16 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
outlayer = &outtile.layers.back();
|
||||
}
|
||||
|
||||
std::set<unsigned long long> *deduplicate_by_id_set = NULL;
|
||||
if (deduplicate_by_id) {
|
||||
auto layer_deduplicate_ids = deduplicate_ids.find(layer.name);
|
||||
if (layer_deduplicate_ids == deduplicate_ids.end()) {
|
||||
deduplicate_ids.emplace(layer.name, std::set<unsigned long long>());
|
||||
layer_deduplicate_ids = deduplicate_ids.find(layer.name);
|
||||
}
|
||||
deduplicate_by_id_set = &layer_deduplicate_ids->second;
|
||||
}
|
||||
|
||||
std::vector<tile_feature> pending_tile_features;
|
||||
double accum_area = 0;
|
||||
|
||||
@@ -1545,7 +1538,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
}
|
||||
|
||||
// Now offset from world coordinates to output tile coordinates,
|
||||
// but retain world scale, because that is what tippecanoe clipping expects
|
||||
// but retain world scale, because that is what tippecanoe zoom-oriented clipping expects
|
||||
|
||||
long long outtilesize = 1LL << (32 - nz); // destination tile size in world coordinates
|
||||
for (auto &g : geom) {
|
||||
@@ -1553,7 +1546,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
g.y -= ny * outtilesize;
|
||||
}
|
||||
|
||||
if (!sametile) {
|
||||
{
|
||||
// Clip to output tile
|
||||
|
||||
long long xmin = LLONG_MAX;
|
||||
@@ -1571,6 +1564,9 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
long long b = outtilesize * buffer / 256;
|
||||
if (xmax < -b || ymax < -b || xmin > outtilesize + b || ymin > outtilesize + b) {
|
||||
// quick exclusion by bounding box
|
||||
if (deduplicate_by_id && feature.has_id) {
|
||||
deduplicate_by_id_set->insert(feature.id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1586,6 +1582,9 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
|
||||
if (geom.size() == 0) {
|
||||
// clipped away
|
||||
if (deduplicate_by_id && feature.has_id) {
|
||||
deduplicate_by_id_set->insert(feature.id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1610,13 +1609,20 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
|
||||
if (flush_multiplier_cluster) {
|
||||
if (pending_tile_features.size() > 0) {
|
||||
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
|
||||
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, unused, key_pool, -1, true, std::vector<clipbbox>(), nz, nx, ny, deduplicate_by_id_set);
|
||||
if (outlayer->features.size() >= feature_limit) {
|
||||
break;
|
||||
}
|
||||
pending_tile_features.clear();
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> exclude_attributes;
|
||||
if (filter != NULL && !evaluate(feature, layer, filter, exclude_attributes, nz, unidecode_data)) {
|
||||
// filtered away
|
||||
if (deduplicate_by_id && feature.has_id) {
|
||||
deduplicate_by_id_set->insert(feature.id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1624,16 +1630,16 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
if (t == VT_POLYGON && tiny_polygon_size > 0) {
|
||||
bool simplified_away_by_reduction = false;
|
||||
|
||||
geom = reduce_tiny_poly(geom, nz, detail, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, tiny_polygon_size);
|
||||
geom = reduce_tiny_poly(geom, nz, det, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, tiny_polygon_size);
|
||||
} else {
|
||||
still_need_simplification_after_reduction = true;
|
||||
}
|
||||
|
||||
if (simplification > 0 && still_need_simplification_after_reduction) {
|
||||
if (t == VT_POLYGON) {
|
||||
geom = simplify_lines_basic(geom, nz, detail, simplification, 4);
|
||||
geom = simplify_lines_basic(geom, nz, det, simplification, 4);
|
||||
} else if (t == VT_LINE) {
|
||||
geom = simplify_lines_basic(geom, nz, detail, simplification, 0);
|
||||
geom = simplify_lines_basic(geom, nz, det, simplification, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1654,6 +1660,14 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
if (geom.size() == 0) {
|
||||
// simplified away
|
||||
if (deduplicate_by_id && feature.has_id) {
|
||||
deduplicate_by_id_set->insert(feature.id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
tile_feature tf;
|
||||
tf.geom = std::move(geom);
|
||||
tf.t = t;
|
||||
@@ -1667,8 +1681,11 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
}
|
||||
|
||||
if (pending_tile_features.size() > 0) {
|
||||
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool);
|
||||
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, unused, key_pool, -1, true, std::vector<clipbbox>(), nz, nx, ny, deduplicate_by_id_set);
|
||||
pending_tile_features.clear();
|
||||
if (outlayer->features.size() >= feature_limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (preserve_input_order) {
|
||||
@@ -1697,10 +1714,14 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
std::vector<source_tile> sts;
|
||||
sts.push_back(st);
|
||||
|
||||
// feature_limit arg is 1, because we just care whether there are any overzoomed features
|
||||
// left after clipping to the child tile, not about their actual content
|
||||
std::string child = overzoom(sts,
|
||||
nz + 1, nx * 2 + x, ny * 2 + y,
|
||||
detail, buffer, keep, false, NULL,
|
||||
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
|
||||
detail_or_unspecified, buffer, keep, exclude, exclude_prefix, false, NULL,
|
||||
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data,
|
||||
simplification, tiny_polygon_size, unused2, unused3, unused,
|
||||
1, unused4, deduplicate_by_id);
|
||||
if (child.size() > 0) {
|
||||
next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y);
|
||||
}
|
||||
@@ -1709,10 +1730,6 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
}
|
||||
}
|
||||
|
||||
if (bins.size() > 0) {
|
||||
outtile = assign_to_bins(outtile, bins, nz, nx, ny, detail);
|
||||
}
|
||||
|
||||
for (ssize_t i = outtile.layers.size() - 1; i >= 0; i--) {
|
||||
if (outtile.layers[i].features.size() == 0) {
|
||||
outtile.layers.erase(outtile.layers.begin() + i);
|
||||
@@ -1882,3 +1899,88 @@ drawvec fix_polygon(const drawvec &geom, bool use_winding, bool reverse_winding)
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool line_is_too_small(drawvec const &geometry, int z, int detail) {
|
||||
if (geometry.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
long long x = 0, y = 0;
|
||||
for (auto &g : geometry) {
|
||||
if (g.op == VT_MOVETO) {
|
||||
x = std::llround((double) g.x / (1LL << (32 - detail - z)));
|
||||
y = std::llround((double) g.y / (1LL << (32 - detail - z)));
|
||||
} else {
|
||||
long long xx = std::llround((double) g.x / (1LL << (32 - detail - z)));
|
||||
long long yy = std::llround((double) g.y / (1LL << (32 - detail - z)));
|
||||
|
||||
if (xx != x || yy != y) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void coalesce_polygon(drawvec &geom, bool scale_up) {
|
||||
// wagyu should be able to straightforwardly handle
|
||||
// anything under a few hundred thousand vertices
|
||||
if (geom.size() < 100000) {
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, scale_up);
|
||||
return;
|
||||
}
|
||||
|
||||
// These geometries were assembled in geometric order,
|
||||
// so sub-batches of them should hopefully union into
|
||||
// reasonable sets.
|
||||
//
|
||||
// Find the first outer ring after halfway point.
|
||||
|
||||
for (size_t i = geom.size() / 2; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (get_area(geom, i, j) > 0) {
|
||||
// If we have an outer ring, split there
|
||||
// and coalesce the two halves
|
||||
|
||||
// Copy second half to new vector
|
||||
std::vector<draw> geom2;
|
||||
geom2.resize(geom.size() - i);
|
||||
for (size_t k = i; k < geom.size(); k++) {
|
||||
geom2[k - i] = geom[k];
|
||||
}
|
||||
|
||||
// Resize vector to include only first half
|
||||
geom.resize(i);
|
||||
|
||||
// Clean each half individually
|
||||
coalesce_polygon(geom, scale_up);
|
||||
coalesce_polygon(geom2, scale_up);
|
||||
|
||||
// Copy second half back with first
|
||||
size_t brk = geom.size();
|
||||
geom.resize(brk + geom2.size());
|
||||
for (size_t k = 0; k < geom2.size(); k++) {
|
||||
geom[brk + k] = geom2[k];
|
||||
}
|
||||
geom2.clear();
|
||||
|
||||
// Clean the combined geometry
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, scale_up);
|
||||
return;
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Can't find a breakpoint; take what we can get.
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false, scale_up);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,641 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 17 September 2024 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2024 *
|
||||
* Purpose : This is the main polygon clipping module *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CLIPPER_ENGINE_H
|
||||
#define CLIPPER_ENGINE_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h> //#541
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
|
||||
#include "clipper2/clipper.core.h"
|
||||
|
||||
namespace Clipper2Lib {
|
||||
|
||||
struct Scanline;
|
||||
struct IntersectNode;
|
||||
struct Active;
|
||||
struct Vertex;
|
||||
struct LocalMinima;
|
||||
struct OutRec;
|
||||
struct HorzSegment;
|
||||
|
||||
//Note: all clipping operations except for Difference are commutative.
|
||||
enum class ClipType { NoClip, Intersection, Union, Difference, Xor };
|
||||
|
||||
enum class PathType { Subject, Clip };
|
||||
enum class JoinWith { NoJoin, Left, Right };
|
||||
|
||||
enum class VertexFlags : uint32_t {
|
||||
Empty = 0, OpenStart = 1, OpenEnd = 2, LocalMax = 4, LocalMin = 8
|
||||
};
|
||||
|
||||
constexpr enum VertexFlags operator &(enum VertexFlags a, enum VertexFlags b)
|
||||
{
|
||||
return (enum VertexFlags)(uint32_t(a) & uint32_t(b));
|
||||
}
|
||||
|
||||
constexpr enum VertexFlags operator |(enum VertexFlags a, enum VertexFlags b)
|
||||
{
|
||||
return (enum VertexFlags)(uint32_t(a) | uint32_t(b));
|
||||
}
|
||||
|
||||
struct Vertex {
|
||||
Point64 pt;
|
||||
Vertex* next = nullptr;
|
||||
Vertex* prev = nullptr;
|
||||
VertexFlags flags = VertexFlags::Empty;
|
||||
};
|
||||
|
||||
struct OutPt {
|
||||
Point64 pt;
|
||||
OutPt* next = nullptr;
|
||||
OutPt* prev = nullptr;
|
||||
OutRec* outrec;
|
||||
HorzSegment* horz = nullptr;
|
||||
|
||||
OutPt(const Point64& pt_, OutRec* outrec_): pt(pt_), outrec(outrec_) {
|
||||
next = this;
|
||||
prev = this;
|
||||
}
|
||||
};
|
||||
|
||||
class PolyPath;
|
||||
class PolyPath64;
|
||||
class PolyPathD;
|
||||
using PolyTree64 = PolyPath64;
|
||||
using PolyTreeD = PolyPathD;
|
||||
|
||||
struct OutRec;
|
||||
typedef std::vector<OutRec*> OutRecList;
|
||||
|
||||
//OutRec: contains a path in the clipping solution. Edges in the AEL will
|
||||
//have OutRec pointers assigned when they form part of the clipping solution.
|
||||
struct OutRec {
|
||||
size_t idx = 0;
|
||||
OutRec* owner = nullptr;
|
||||
Active* front_edge = nullptr;
|
||||
Active* back_edge = nullptr;
|
||||
OutPt* pts = nullptr;
|
||||
PolyPath* polypath = nullptr;
|
||||
OutRecList* splits = nullptr;
|
||||
OutRec* recursive_split = nullptr;
|
||||
Rect64 bounds = {};
|
||||
Path64 path;
|
||||
bool is_open = false;
|
||||
|
||||
~OutRec() {
|
||||
if (splits) delete splits;
|
||||
// nb: don't delete the split pointers
|
||||
// as these are owned by ClipperBase's outrec_list_
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//Important: UP and DOWN here are premised on Y-axis positive down
|
||||
//displays, which is the orientation used in Clipper's development.
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Active {
|
||||
Point64 bot;
|
||||
Point64 top;
|
||||
int64_t curr_x = 0; //current (updated at every new scanline)
|
||||
double dx = 0.0;
|
||||
int wind_dx = 1; //1 or -1 depending on winding direction
|
||||
int wind_cnt = 0;
|
||||
int wind_cnt2 = 0; //winding count of the opposite polytype
|
||||
OutRec* outrec = nullptr;
|
||||
//AEL: 'active edge list' (Vatti's AET - active edge table)
|
||||
// a linked list of all edges (from left to right) that are present
|
||||
// (or 'active') within the current scanbeam (a horizontal 'beam' that
|
||||
// sweeps from bottom to top over the paths in the clipping operation).
|
||||
Active* prev_in_ael = nullptr;
|
||||
Active* next_in_ael = nullptr;
|
||||
//SEL: 'sorted edge list' (Vatti's ST - sorted table)
|
||||
// linked list used when sorting edges into their new positions at the
|
||||
// top of scanbeams, but also (re)used to process horizontals.
|
||||
Active* prev_in_sel = nullptr;
|
||||
Active* next_in_sel = nullptr;
|
||||
Active* jump = nullptr;
|
||||
Vertex* vertex_top = nullptr;
|
||||
LocalMinima* local_min = nullptr; // the bottom of an edge 'bound' (also Vatti)
|
||||
bool is_left_bound = false;
|
||||
JoinWith join_with = JoinWith::NoJoin;
|
||||
};
|
||||
|
||||
struct LocalMinima {
|
||||
Vertex* vertex;
|
||||
PathType polytype;
|
||||
bool is_open;
|
||||
LocalMinima(Vertex* v, PathType pt, bool open) :
|
||||
vertex(v), polytype(pt), is_open(open){}
|
||||
};
|
||||
|
||||
struct IntersectNode {
|
||||
Point64 pt;
|
||||
Active* edge1;
|
||||
Active* edge2;
|
||||
IntersectNode() : pt(Point64(0,0)), edge1(NULL), edge2(NULL) {}
|
||||
IntersectNode(Active* e1, Active* e2, Point64& pt_) :
|
||||
pt(pt_), edge1(e1), edge2(e2) {}
|
||||
};
|
||||
|
||||
struct HorzSegment {
|
||||
OutPt* left_op;
|
||||
OutPt* right_op = nullptr;
|
||||
bool left_to_right = true;
|
||||
HorzSegment() : left_op(nullptr) { }
|
||||
explicit HorzSegment(OutPt* op) : left_op(op) { }
|
||||
};
|
||||
|
||||
struct HorzJoin {
|
||||
OutPt* op1 = nullptr;
|
||||
OutPt* op2 = nullptr;
|
||||
HorzJoin() {};
|
||||
explicit HorzJoin(OutPt* ltr, OutPt* rtl) : op1(ltr), op2(rtl) { }
|
||||
};
|
||||
|
||||
#ifdef USINGZ
|
||||
typedef std::function<void(const Point64& e1bot, const Point64& e1top,
|
||||
const Point64& e2bot, const Point64& e2top, Point64& pt)> ZCallback64;
|
||||
|
||||
typedef std::function<void(const PointD& e1bot, const PointD& e1top,
|
||||
const PointD& e2bot, const PointD& e2top, PointD& pt)> ZCallbackD;
|
||||
#endif
|
||||
|
||||
typedef std::vector<HorzSegment> HorzSegmentList;
|
||||
typedef std::unique_ptr<LocalMinima> LocalMinima_ptr;
|
||||
typedef std::vector<LocalMinima_ptr> LocalMinimaList;
|
||||
typedef std::vector<IntersectNode> IntersectNodeList;
|
||||
|
||||
// ReuseableDataContainer64 ------------------------------------------------
|
||||
|
||||
class ReuseableDataContainer64 {
|
||||
private:
|
||||
friend class ClipperBase;
|
||||
LocalMinimaList minima_list_;
|
||||
std::vector<Vertex*> vertex_lists_;
|
||||
void AddLocMin(Vertex& vert, PathType polytype, bool is_open);
|
||||
public:
|
||||
virtual ~ReuseableDataContainer64();
|
||||
void Clear();
|
||||
void AddPaths(const Paths64& paths, PathType polytype, bool is_open);
|
||||
};
|
||||
|
||||
// ClipperBase -------------------------------------------------------------
|
||||
|
||||
class ClipperBase {
|
||||
private:
|
||||
ClipType cliptype_ = ClipType::NoClip;
|
||||
FillRule fillrule_ = FillRule::EvenOdd;
|
||||
FillRule fillpos = FillRule::Positive;
|
||||
int64_t bot_y_ = 0;
|
||||
bool minima_list_sorted_ = false;
|
||||
bool using_polytree_ = false;
|
||||
Active* actives_ = nullptr;
|
||||
Active *sel_ = nullptr;
|
||||
LocalMinimaList minima_list_; //pointers in case of memory reallocs
|
||||
LocalMinimaList::iterator current_locmin_iter_;
|
||||
std::vector<Vertex*> vertex_lists_;
|
||||
std::priority_queue<int64_t> scanline_list_;
|
||||
IntersectNodeList intersect_nodes_;
|
||||
HorzSegmentList horz_seg_list_;
|
||||
std::vector<HorzJoin> horz_join_list_;
|
||||
void Reset();
|
||||
inline void InsertScanline(int64_t y);
|
||||
inline bool PopScanline(int64_t &y);
|
||||
inline bool PopLocalMinima(int64_t y, LocalMinima*& local_minima);
|
||||
void DisposeAllOutRecs();
|
||||
void DisposeVerticesAndLocalMinima();
|
||||
void DeleteEdges(Active*& e);
|
||||
inline void AddLocMin(Vertex &vert, PathType polytype, bool is_open);
|
||||
bool IsContributingClosed(const Active &e) const;
|
||||
inline bool IsContributingOpen(const Active &e) const;
|
||||
void SetWindCountForClosedPathEdge(Active &edge);
|
||||
void SetWindCountForOpenPathEdge(Active &e);
|
||||
void InsertLocalMinimaIntoAEL(int64_t bot_y);
|
||||
void InsertLeftEdge(Active &e);
|
||||
inline void PushHorz(Active &e);
|
||||
inline bool PopHorz(Active *&e);
|
||||
inline OutPt* StartOpenPath(Active &e, const Point64& pt);
|
||||
inline void UpdateEdgeIntoAEL(Active *e);
|
||||
void IntersectEdges(Active &e1, Active &e2, const Point64& pt);
|
||||
inline void DeleteFromAEL(Active &e);
|
||||
inline void AdjustCurrXAndCopyToSEL(const int64_t top_y);
|
||||
void DoIntersections(const int64_t top_y);
|
||||
void AddNewIntersectNode(Active &e1, Active &e2, const int64_t top_y);
|
||||
bool BuildIntersectList(const int64_t top_y);
|
||||
void ProcessIntersectList();
|
||||
void SwapPositionsInAEL(Active& edge1, Active& edge2);
|
||||
OutRec* NewOutRec();
|
||||
OutPt* AddOutPt(const Active &e, const Point64& pt);
|
||||
OutPt* AddLocalMinPoly(Active &e1, Active &e2,
|
||||
const Point64& pt, bool is_new = false);
|
||||
OutPt* AddLocalMaxPoly(Active &e1, Active &e2, const Point64& pt);
|
||||
void DoHorizontal(Active &horz);
|
||||
bool ResetHorzDirection(const Active &horz, const Vertex* max_vertex,
|
||||
int64_t &horz_left, int64_t &horz_right);
|
||||
void DoTopOfScanbeam(const int64_t top_y);
|
||||
Active *DoMaxima(Active &e);
|
||||
void JoinOutrecPaths(Active &e1, Active &e2);
|
||||
void FixSelfIntersects(OutRec* outrec);
|
||||
void DoSplitOp(OutRec* outRec, OutPt* splitOp);
|
||||
|
||||
inline void AddTrialHorzJoin(OutPt* op);
|
||||
void ConvertHorzSegsToJoins();
|
||||
void ProcessHorzJoins();
|
||||
|
||||
void Split(Active& e, const Point64& pt);
|
||||
inline void CheckJoinLeft(Active& e,
|
||||
const Point64& pt, bool check_curr_x = false);
|
||||
inline void CheckJoinRight(Active& e,
|
||||
const Point64& pt, bool check_curr_x = false);
|
||||
protected:
|
||||
bool preserve_collinear_ = true;
|
||||
bool reverse_solution_ = false;
|
||||
int error_code_ = 0;
|
||||
bool has_open_paths_ = false;
|
||||
bool succeeded_ = true;
|
||||
OutRecList outrec_list_; //pointers in case list memory reallocated
|
||||
bool ExecuteInternal(ClipType ct, FillRule ft, bool use_polytrees);
|
||||
void CleanCollinear(OutRec* outrec);
|
||||
bool CheckBounds(OutRec* outrec);
|
||||
bool CheckSplitOwner(OutRec* outrec, OutRecList* splits);
|
||||
void RecursiveCheckOwners(OutRec* outrec, PolyPath* polypath);
|
||||
#ifdef USINGZ
|
||||
ZCallback64 zCallback_ = nullptr;
|
||||
void SetZ(const Active& e1, const Active& e2, Point64& pt);
|
||||
#endif
|
||||
void CleanUp(); // unlike Clear, CleanUp preserves added paths
|
||||
void AddPath(const Path64& path, PathType polytype, bool is_open);
|
||||
void AddPaths(const Paths64& paths, PathType polytype, bool is_open);
|
||||
public:
|
||||
virtual ~ClipperBase();
|
||||
int ErrorCode() const { return error_code_; };
|
||||
void PreserveCollinear(bool val) { preserve_collinear_ = val; };
|
||||
bool PreserveCollinear() const { return preserve_collinear_;};
|
||||
void ReverseSolution(bool val) { reverse_solution_ = val; };
|
||||
bool ReverseSolution() const { return reverse_solution_; };
|
||||
void Clear();
|
||||
void AddReuseableData(const ReuseableDataContainer64& reuseable_data);
|
||||
#ifdef USINGZ
|
||||
int64_t DefaultZ = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
// PolyPath / PolyTree --------------------------------------------------------
|
||||
|
||||
//PolyTree: is intended as a READ-ONLY data structure for CLOSED paths returned
|
||||
//by clipping operations. While this structure is more complex than the
|
||||
//alternative Paths structure, it does preserve path 'ownership' - ie those
|
||||
//paths that contain (or own) other paths. This will be useful to some users.
|
||||
|
||||
class PolyPath {
|
||||
protected:
|
||||
PolyPath* parent_;
|
||||
public:
|
||||
PolyPath(PolyPath* parent = nullptr): parent_(parent){}
|
||||
virtual ~PolyPath() {};
|
||||
//https://en.cppreference.com/w/cpp/language/rule_of_three
|
||||
PolyPath(const PolyPath&) = delete;
|
||||
PolyPath& operator=(const PolyPath&) = delete;
|
||||
|
||||
unsigned Level() const
|
||||
{
|
||||
unsigned result = 0;
|
||||
const PolyPath* p = parent_;
|
||||
while (p) { ++result; p = p->parent_; }
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual PolyPath* AddChild(const Path64& path) = 0;
|
||||
|
||||
virtual void Clear() = 0;
|
||||
virtual size_t Count() const { return 0; }
|
||||
|
||||
const PolyPath* Parent() const { return parent_; }
|
||||
|
||||
bool IsHole() const
|
||||
{
|
||||
unsigned lvl = Level();
|
||||
//Even levels except level 0
|
||||
return lvl && !(lvl & 1);
|
||||
}
|
||||
};
|
||||
|
||||
typedef typename std::vector<std::unique_ptr<PolyPath64>> PolyPath64List;
|
||||
typedef typename std::vector<std::unique_ptr<PolyPathD>> PolyPathDList;
|
||||
|
||||
class PolyPath64 : public PolyPath {
|
||||
private:
|
||||
PolyPath64List childs_;
|
||||
Path64 polygon_;
|
||||
public:
|
||||
explicit PolyPath64(PolyPath64* parent = nullptr) : PolyPath(parent) {}
|
||||
explicit PolyPath64(PolyPath64* parent, const Path64& path) : PolyPath(parent) { polygon_ = path; }
|
||||
|
||||
~PolyPath64() {
|
||||
childs_.resize(0);
|
||||
}
|
||||
|
||||
PolyPath64* operator [] (size_t index) const
|
||||
{
|
||||
return childs_[index].get(); //std::unique_ptr
|
||||
}
|
||||
|
||||
PolyPath64* Child(size_t index) const
|
||||
{
|
||||
return childs_[index].get();
|
||||
}
|
||||
|
||||
PolyPath64List::const_iterator begin() const { return childs_.cbegin(); }
|
||||
PolyPath64List::const_iterator end() const { return childs_.cend(); }
|
||||
|
||||
PolyPath64* AddChild(const Path64& path) override
|
||||
{
|
||||
return childs_.emplace_back(std::make_unique<PolyPath64>(this, path)).get();
|
||||
}
|
||||
|
||||
void Clear() override
|
||||
{
|
||||
childs_.resize(0);
|
||||
}
|
||||
|
||||
size_t Count() const override
|
||||
{
|
||||
return childs_.size();
|
||||
}
|
||||
|
||||
const Path64& Polygon() const { return polygon_; };
|
||||
|
||||
double Area() const
|
||||
{
|
||||
return std::accumulate(childs_.cbegin(), childs_.cend(),
|
||||
Clipper2Lib::Area<int64_t>(polygon_),
|
||||
[](double a, const auto& child) {return a + child->Area(); });
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class PolyPathD : public PolyPath {
|
||||
private:
|
||||
PolyPathDList childs_;
|
||||
double scale_;
|
||||
PathD polygon_;
|
||||
public:
|
||||
explicit PolyPathD(PolyPathD* parent = nullptr) : PolyPath(parent)
|
||||
{
|
||||
scale_ = parent ? parent->scale_ : 1.0;
|
||||
}
|
||||
|
||||
explicit PolyPathD(PolyPathD* parent, const Path64& path) : PolyPath(parent)
|
||||
{
|
||||
scale_ = parent ? parent->scale_ : 1.0;
|
||||
int error_code = 0;
|
||||
polygon_ = ScalePath<double, int64_t>(path, scale_, error_code);
|
||||
}
|
||||
|
||||
explicit PolyPathD(PolyPathD* parent, const PathD& path) : PolyPath(parent)
|
||||
{
|
||||
scale_ = parent ? parent->scale_ : 1.0;
|
||||
polygon_ = path;
|
||||
}
|
||||
|
||||
~PolyPathD() {
|
||||
childs_.resize(0);
|
||||
}
|
||||
|
||||
PolyPathD* operator [] (size_t index) const
|
||||
{
|
||||
return childs_[index].get();
|
||||
}
|
||||
|
||||
PolyPathD* Child(size_t index) const
|
||||
{
|
||||
return childs_[index].get();
|
||||
}
|
||||
|
||||
PolyPathDList::const_iterator begin() const { return childs_.cbegin(); }
|
||||
PolyPathDList::const_iterator end() const { return childs_.cend(); }
|
||||
|
||||
void SetScale(double value) { scale_ = value; }
|
||||
double Scale() const { return scale_; }
|
||||
|
||||
PolyPathD* AddChild(const Path64& path) override
|
||||
{
|
||||
return childs_.emplace_back(std::make_unique<PolyPathD>(this, path)).get();
|
||||
}
|
||||
|
||||
PolyPathD* AddChild(const PathD& path)
|
||||
{
|
||||
return childs_.emplace_back(std::make_unique<PolyPathD>(this, path)).get();
|
||||
}
|
||||
|
||||
void Clear() override
|
||||
{
|
||||
childs_.resize(0);
|
||||
}
|
||||
|
||||
size_t Count() const override
|
||||
{
|
||||
return childs_.size();
|
||||
}
|
||||
|
||||
const PathD& Polygon() const { return polygon_; };
|
||||
|
||||
double Area() const
|
||||
{
|
||||
return std::accumulate(childs_.begin(), childs_.end(),
|
||||
Clipper2Lib::Area<double>(polygon_),
|
||||
[](double a, const auto& child) {return a + child->Area(); });
|
||||
}
|
||||
};
|
||||
|
||||
class Clipper64 : public ClipperBase
|
||||
{
|
||||
private:
|
||||
void BuildPaths64(Paths64& solutionClosed, Paths64* solutionOpen);
|
||||
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
|
||||
public:
|
||||
#ifdef USINGZ
|
||||
void SetZCallback(ZCallback64 cb) { zCallback_ = cb; }
|
||||
#endif
|
||||
|
||||
void AddSubject(const Paths64& subjects)
|
||||
{
|
||||
AddPaths(subjects, PathType::Subject, false);
|
||||
}
|
||||
void AddOpenSubject(const Paths64& open_subjects)
|
||||
{
|
||||
AddPaths(open_subjects, PathType::Subject, true);
|
||||
}
|
||||
void AddClip(const Paths64& clips)
|
||||
{
|
||||
AddPaths(clips, PathType::Clip, false);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type,
|
||||
FillRule fill_rule, Paths64& closed_paths)
|
||||
{
|
||||
Paths64 dummy;
|
||||
return Execute(clip_type, fill_rule, closed_paths, dummy);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type, FillRule fill_rule,
|
||||
Paths64& closed_paths, Paths64& open_paths)
|
||||
{
|
||||
closed_paths.clear();
|
||||
open_paths.clear();
|
||||
if (ExecuteInternal(clip_type, fill_rule, false))
|
||||
BuildPaths64(closed_paths, &open_paths);
|
||||
CleanUp();
|
||||
return succeeded_;
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type, FillRule fill_rule, PolyTree64& polytree)
|
||||
{
|
||||
Paths64 dummy;
|
||||
return Execute(clip_type, fill_rule, polytree, dummy);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type,
|
||||
FillRule fill_rule, PolyTree64& polytree, Paths64& open_paths)
|
||||
{
|
||||
if (ExecuteInternal(clip_type, fill_rule, true))
|
||||
{
|
||||
open_paths.clear();
|
||||
polytree.Clear();
|
||||
BuildTree64(polytree, open_paths);
|
||||
}
|
||||
CleanUp();
|
||||
return succeeded_;
|
||||
}
|
||||
};
|
||||
|
||||
class ClipperD : public ClipperBase {
|
||||
private:
|
||||
double scale_ = 1.0, invScale_ = 1.0;
|
||||
#ifdef USINGZ
|
||||
ZCallbackD zCallbackD_ = nullptr;
|
||||
#endif
|
||||
void BuildPathsD(PathsD& solutionClosed, PathsD* solutionOpen);
|
||||
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
|
||||
public:
|
||||
explicit ClipperD(int precision = 2) : ClipperBase()
|
||||
{
|
||||
CheckPrecisionRange(precision, error_code_);
|
||||
// to optimize scaling / descaling precision
|
||||
// set the scale to a power of double's radix (2) (#25)
|
||||
scale_ = std::pow(std::numeric_limits<double>::radix,
|
||||
std::ilogb(std::pow(10, precision)) + 1);
|
||||
invScale_ = 1 / scale_;
|
||||
}
|
||||
|
||||
#ifdef USINGZ
|
||||
void SetZCallback(ZCallbackD cb) { zCallbackD_ = cb; };
|
||||
|
||||
void ZCB(const Point64& e1bot, const Point64& e1top,
|
||||
const Point64& e2bot, const Point64& e2top, Point64& pt)
|
||||
{
|
||||
// de-scale (x & y)
|
||||
// temporarily convert integers to their initial float values
|
||||
// this will slow clipping marginally but will make it much easier
|
||||
// to understand the coordinates passed to the callback function
|
||||
PointD tmp = PointD(pt) * invScale_;
|
||||
PointD e1b = PointD(e1bot) * invScale_;
|
||||
PointD e1t = PointD(e1top) * invScale_;
|
||||
PointD e2b = PointD(e2bot) * invScale_;
|
||||
PointD e2t = PointD(e2top) * invScale_;
|
||||
zCallbackD_(e1b,e1t, e2b, e2t, tmp);
|
||||
pt.z = tmp.z; // only update 'z'
|
||||
};
|
||||
|
||||
void CheckCallback()
|
||||
{
|
||||
if(zCallbackD_)
|
||||
// if the user defined float point callback has been assigned
|
||||
// then assign the proxy callback function
|
||||
ClipperBase::zCallback_ =
|
||||
std::bind(&ClipperD::ZCB, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3,
|
||||
std::placeholders::_4, std::placeholders::_5);
|
||||
else
|
||||
ClipperBase::zCallback_ = nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void AddSubject(const PathsD& subjects)
|
||||
{
|
||||
AddPaths(ScalePaths<int64_t, double>(subjects, scale_, error_code_), PathType::Subject, false);
|
||||
}
|
||||
|
||||
void AddOpenSubject(const PathsD& open_subjects)
|
||||
{
|
||||
AddPaths(ScalePaths<int64_t, double>(open_subjects, scale_, error_code_), PathType::Subject, true);
|
||||
}
|
||||
|
||||
void AddClip(const PathsD& clips)
|
||||
{
|
||||
AddPaths(ScalePaths<int64_t, double>(clips, scale_, error_code_), PathType::Clip, false);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type, FillRule fill_rule, PathsD& closed_paths)
|
||||
{
|
||||
PathsD dummy;
|
||||
return Execute(clip_type, fill_rule, closed_paths, dummy);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type,
|
||||
FillRule fill_rule, PathsD& closed_paths, PathsD& open_paths)
|
||||
{
|
||||
#ifdef USINGZ
|
||||
CheckCallback();
|
||||
#endif
|
||||
if (ExecuteInternal(clip_type, fill_rule, false))
|
||||
{
|
||||
BuildPathsD(closed_paths, &open_paths);
|
||||
}
|
||||
CleanUp();
|
||||
return succeeded_;
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type, FillRule fill_rule, PolyTreeD& polytree)
|
||||
{
|
||||
PathsD dummy;
|
||||
return Execute(clip_type, fill_rule, polytree, dummy);
|
||||
}
|
||||
|
||||
bool Execute(ClipType clip_type,
|
||||
FillRule fill_rule, PolyTreeD& polytree, PathsD& open_paths)
|
||||
{
|
||||
#ifdef USINGZ
|
||||
CheckCallback();
|
||||
#endif
|
||||
if (ExecuteInternal(clip_type, fill_rule, true))
|
||||
{
|
||||
polytree.Clear();
|
||||
polytree.SetScale(invScale_);
|
||||
open_paths.clear();
|
||||
BuildTreeD(polytree, open_paths);
|
||||
}
|
||||
CleanUp();
|
||||
return succeeded_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // CLIPPER_ENGINE_H
|
||||
@@ -0,0 +1,827 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 17 September 2024 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2024 *
|
||||
* Purpose : This module exports the Clipper2 Library (ie DLL/so) *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
Boolean clipping:
|
||||
cliptype: NoClip=0, Intersection=1, Union=2, Difference=3, Xor=4
|
||||
fillrule: EvenOdd=0, NonZero=1, Positive=2, Negative=3
|
||||
|
||||
Polygon offsetting (inflate/deflate):
|
||||
jointype: Square=0, Bevel=1, Round=2, Miter=3
|
||||
endtype: Polygon=0, Joined=1, Butt=2, Square=3, Round=4
|
||||
|
||||
The path structures used extensively in other parts of this library are all
|
||||
based on std::vector classes. Since C++ classes can't be accessed by other
|
||||
languages, these paths are converted here into very simple array data
|
||||
structures that can be parsed by just about any programming language.
|
||||
|
||||
These 2D paths are defined by series of x and y coordinates together with an
|
||||
optional user-defined 'z' value (see Z-values below). Hence, a vertex refers
|
||||
to a single x and y coordinate (+/- a user-defined value). These values will
|
||||
be either type int64_t or type double. Data structures have names that
|
||||
indicate the array type by a suffixed '64' or a 'D'. For example, the data
|
||||
structure CPath64 contains an array of int64_t values, whereas the data
|
||||
structure CPathD contains an array of double. Where documentation omits
|
||||
the type suffix (eg CPath), it is simply agnostic to the array's data type.
|
||||
|
||||
For conciseness, the following letters are used in the diagrams below:
|
||||
N: Number of vertices in a given path
|
||||
C: Count of structure's paths
|
||||
A: Array size (as distinct from the size in memory)
|
||||
|
||||
|
||||
CPath64 and CPathD:
|
||||
These are arrays of consecutive vertices preceeded by a pair of values
|
||||
containing the number of vertices (N) in the path, and a 0 value.
|
||||
_______________________________________________________________
|
||||
| counters | vertex1 | vertex2 | ... | vertexN |
|
||||
| N, 0 | x1, y1, (z1) | x2, y2, (z2) | ... | xN, yN, (zN) |
|
||||
---------------------------------------------------------------
|
||||
|
||||
|
||||
CPaths64 and CPathsD:
|
||||
These are also arrays containing any number of consecutive CPath
|
||||
structures. Preceeding these consecutive paths, there is a pair of
|
||||
values that contain the length of the array structure (A) and
|
||||
the count of following CPath structures (C).
|
||||
Memory allocation for CPaths64 = A * sizeof(int64_t)
|
||||
Memory allocation for CPathsD = A * sizeof(double)
|
||||
__________________________________________
|
||||
| counters | path1 | path2 | ... | pathC |
|
||||
| A, C | | | ... | |
|
||||
------------------------------------------
|
||||
|
||||
|
||||
CPolytree64 and CPolytreeD:
|
||||
These structures consist of two values followed by a series of CPolyPath
|
||||
structures. The first value indicates the total length of the array (A).
|
||||
The second value indicates the number of following CPolyPath structures
|
||||
that are the top level CPolyPath in the CPolytree (C). These CPolyPath
|
||||
may, in turn, contain their own nested CPolyPath children that
|
||||
collectively make a tree structure.
|
||||
_________________________________________________________
|
||||
| counters | CPolyPath1 | CPolyPath2 | ... | CPolyPathC |
|
||||
| A, C | | | ... | |
|
||||
---------------------------------------------------------
|
||||
|
||||
|
||||
CPolyPath64 and CPolyPathD:
|
||||
These array structures consist of a pair of counter values followed by a
|
||||
series of polygon vertices and a series of nested CPolyPath children.
|
||||
The first counter values indicates the number of vertices in the
|
||||
polygon (N), and the second counter indicates the CPolyPath child count (C).
|
||||
_____________________________________________________________________________
|
||||
|cntrs |vertex1 |vertex2 |...|vertexN |child1|child2|...|childC|
|
||||
|N, C |x1, y1, (z1)| x2, y2, (z2)|...|xN, yN, (zN)| | |...| |
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
DisposeArray64 & DisposeArrayD:
|
||||
All array structures are allocated in heap memory which will eventually
|
||||
need to be released. However, since applications linking to these DLL
|
||||
functions may use different memory managers, the only safe way to release
|
||||
this memory is to use the exported DisposeArray functions.
|
||||
|
||||
|
||||
(Optional) Z-Values:
|
||||
Structures will only contain user-defined z-values when the USINGZ
|
||||
pre-processor identifier is used. The library does not assign z-values
|
||||
because this field is intended for users to assign custom values to vertices.
|
||||
Z-values in input paths (subject and clip) will be copied to solution paths.
|
||||
New vertices at path intersections will generate a callback event that allows
|
||||
users to assign z-values at these new vertices. The user's callback function
|
||||
must conform with the DLLZCallback definition and be registered with the
|
||||
DLL via SetZCallback. To assist the user in assigning z-values, the library
|
||||
passes in the callback function the new intersection point together with
|
||||
the four vertices that define the two segments that are intersecting.
|
||||
|
||||
*/
|
||||
#ifndef CLIPPER2_EXPORT_H
|
||||
#define CLIPPER2_EXPORT_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include "clipper2/clipper.core.h"
|
||||
#include "clipper2/clipper.engine.h"
|
||||
#include "clipper2/clipper.offset.h"
|
||||
#include "clipper2/clipper.rectclip.h"
|
||||
|
||||
namespace Clipper2Lib {
|
||||
|
||||
typedef int64_t* CPath64;
|
||||
typedef int64_t* CPaths64;
|
||||
typedef double* CPathD;
|
||||
typedef double* CPathsD;
|
||||
|
||||
typedef int64_t* CPolyPath64;
|
||||
typedef int64_t* CPolyTree64;
|
||||
typedef double* CPolyPathD;
|
||||
typedef double* CPolyTreeD;
|
||||
|
||||
template <typename T>
|
||||
struct CRect {
|
||||
T left;
|
||||
T top;
|
||||
T right;
|
||||
T bottom;
|
||||
};
|
||||
|
||||
typedef CRect<int64_t> CRect64;
|
||||
typedef CRect<double> CRectD;
|
||||
|
||||
template <typename T>
|
||||
inline bool CRectIsEmpty(const CRect<T>& rect)
|
||||
{
|
||||
return (rect.right <= rect.left) || (rect.bottom <= rect.top);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Rect<T> CRectToRect(const CRect<T>& rect)
|
||||
{
|
||||
Rect<T> result;
|
||||
result.left = rect.left;
|
||||
result.top = rect.top;
|
||||
result.right = rect.right;
|
||||
result.bottom = rect.bottom;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline T1 Reinterpret(T2 value) {
|
||||
return *reinterpret_cast<T1*>(&value);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define EXTERN_DLL_EXPORT extern "C"
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EXPORTED FUNCTION DECLARATIONS
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
EXTERN_DLL_EXPORT const char* Version();
|
||||
|
||||
EXTERN_DLL_EXPORT void DisposeArray64(int64_t*& p)
|
||||
{
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT void DisposeArrayD(double*& p)
|
||||
{
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp64(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPaths64 subjects,
|
||||
const CPaths64 subjects_open, const CPaths64 clips,
|
||||
CPaths64& solution, CPaths64& solution_open,
|
||||
bool preserve_collinear = true, bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp_PolyTree64(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPaths64 subjects,
|
||||
const CPaths64 subjects_open, const CPaths64 clips,
|
||||
CPolyTree64& sol_tree, CPaths64& solution_open,
|
||||
bool preserve_collinear = true, bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOpD(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPathsD subjects,
|
||||
const CPathsD subjects_open, const CPathsD clips,
|
||||
CPathsD& solution, CPathsD& solution_open, int precision = 2,
|
||||
bool preserve_collinear = true, bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp_PolyTreeD(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPathsD subjects,
|
||||
const CPathsD subjects_open, const CPathsD clips,
|
||||
CPolyTreeD& solution, CPathsD& solution_open, int precision = 2,
|
||||
bool preserve_collinear = true, bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
double miter_limit = 2.0, double arc_tolerance = 0.0,
|
||||
bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
int precision = 2, double miter_limit = 2.0,
|
||||
double arc_tolerance = 0.0, bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 InflatePath64(const CPath64 path,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
double miter_limit = 2.0, double arc_tolerance = 0.0,
|
||||
bool reverse_solution = false);
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD InflatePathD(const CPathD path,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
int precision = 2, double miter_limit = 2.0,
|
||||
double arc_tolerance = 0.0, bool reverse_solution = false);
|
||||
|
||||
// RectClip & RectClipLines:
|
||||
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect,
|
||||
const CPaths64 paths);
|
||||
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect,
|
||||
const CPathsD paths, int precision = 2);
|
||||
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
|
||||
const CPaths64 paths);
|
||||
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
|
||||
const CPathsD paths, int precision = 2);
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// INTERNAL FUNCTIONS
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
#ifdef USINGZ
|
||||
ZCallback64 dllCallback64 = nullptr;
|
||||
ZCallbackD dllCallbackD = nullptr;
|
||||
|
||||
constexpr int EXPORT_VERTEX_DIMENSIONALITY = 3;
|
||||
#else
|
||||
constexpr int EXPORT_VERTEX_DIMENSIONALITY = 2;
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
static void GetPathCountAndCPathsArrayLen(const Paths<T>& paths,
|
||||
size_t& cnt, size_t& array_len)
|
||||
{
|
||||
array_len = 2;
|
||||
cnt = 0;
|
||||
for (const Path<T>& path : paths)
|
||||
if (path.size())
|
||||
{
|
||||
array_len += path.size() * EXPORT_VERTEX_DIMENSIONALITY + 2;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t GetPolyPathArrayLen64(const PolyPath64& pp)
|
||||
{
|
||||
size_t result = 2; // poly_length + child_count
|
||||
result += pp.Polygon().size() * EXPORT_VERTEX_DIMENSIONALITY;
|
||||
//plus nested children :)
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
result += GetPolyPathArrayLen64(*pp[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
static size_t GetPolyPathArrayLenD(const PolyPathD& pp)
|
||||
{
|
||||
size_t result = 2; // poly_length + child_count
|
||||
result += pp.Polygon().size() * EXPORT_VERTEX_DIMENSIONALITY;
|
||||
//plus nested children :)
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
result += GetPolyPathArrayLenD(*pp[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void GetPolytreeCountAndCStorageSize64(const PolyTree64& tree,
|
||||
size_t& cnt, size_t& array_len)
|
||||
{
|
||||
cnt = tree.Count(); // nb: top level count only
|
||||
array_len = GetPolyPathArrayLen64(tree);
|
||||
}
|
||||
|
||||
static void GetPolytreeCountAndCStorageSizeD(const PolyTreeD& tree,
|
||||
size_t& cnt, size_t& array_len)
|
||||
{
|
||||
cnt = tree.Count(); // nb: top level count only
|
||||
array_len = GetPolyPathArrayLenD(tree);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T* CreateCPathsFromPathsT(const Paths<T>& paths)
|
||||
{
|
||||
size_t cnt = 0, array_len = 0;
|
||||
GetPathCountAndCPathsArrayLen(paths, cnt, array_len);
|
||||
T* result = new T[array_len], * v = result;
|
||||
*v++ = array_len;
|
||||
*v++ = cnt;
|
||||
for (const Path<T>& path : paths)
|
||||
{
|
||||
if (!path.size()) continue;
|
||||
*v++ = path.size();
|
||||
*v++ = 0;
|
||||
for (const Point<T>& pt : path)
|
||||
{
|
||||
*v++ = pt.x;
|
||||
*v++ = pt.y;
|
||||
#ifdef USINGZ
|
||||
*v++ = Reinterpret<T>(pt.z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CPathsD CreateCPathsDFromPathsD(const PathsD& paths)
|
||||
{
|
||||
if (!paths.size()) return nullptr;
|
||||
size_t cnt, array_len;
|
||||
GetPathCountAndCPathsArrayLen(paths, cnt, array_len);
|
||||
CPathsD result = new double[array_len], v = result;
|
||||
*v++ = (double)array_len;
|
||||
*v++ = (double)cnt;
|
||||
for (const PathD& path : paths)
|
||||
{
|
||||
if (!path.size()) continue;
|
||||
*v = (double)path.size();
|
||||
++v; *v++ = 0;
|
||||
for (const PointD& pt : path)
|
||||
{
|
||||
*v++ = pt.x;
|
||||
*v++ = pt.y;
|
||||
#ifdef USINGZ
|
||||
* v++ = Reinterpret<double>(pt.z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CPathsD CreateCPathsDFromPaths64(const Paths64& paths, double scale)
|
||||
{
|
||||
if (!paths.size()) return nullptr;
|
||||
size_t cnt, array_len;
|
||||
GetPathCountAndCPathsArrayLen(paths, cnt, array_len);
|
||||
CPathsD result = new double[array_len], v = result;
|
||||
*v++ = (double)array_len;
|
||||
*v++ = (double)cnt;
|
||||
for (const Path64& path : paths)
|
||||
{
|
||||
if (!path.size()) continue;
|
||||
*v = (double)path.size();
|
||||
++v; *v++ = 0;
|
||||
for (const Point64& pt : path)
|
||||
{
|
||||
*v++ = pt.x * scale;
|
||||
*v++ = pt.y * scale;
|
||||
#ifdef USINGZ
|
||||
*v++ = Reinterpret<double>(pt.z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static Path<T> ConvertCPathToPathT(T* path)
|
||||
{
|
||||
Path<T> result;
|
||||
if (!path) return result;
|
||||
T* v = path;
|
||||
size_t cnt = static_cast<size_t>(*v);
|
||||
v += 2; // skip 0 value
|
||||
result.reserve(cnt);
|
||||
for (size_t j = 0; j < cnt; ++j)
|
||||
{
|
||||
T x = *v++, y = *v++;
|
||||
#ifdef USINGZ
|
||||
z_type z = Reinterpret<z_type>(*v++);
|
||||
result.push_back(Point<T>(x, y, z));
|
||||
#else
|
||||
result.push_back(Point<T>(x, y));
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static Paths<T> ConvertCPathsToPathsT(T* paths)
|
||||
{
|
||||
Paths<T> result;
|
||||
if (!paths) return result;
|
||||
T* v = paths; ++v;
|
||||
size_t cnt = static_cast<size_t>(*v++);
|
||||
result.reserve(cnt);
|
||||
for (size_t i = 0; i < cnt; ++i)
|
||||
{
|
||||
size_t cnt2 = static_cast<size_t>(*v);
|
||||
v += 2;
|
||||
Path<T> path;
|
||||
path.reserve(cnt2);
|
||||
for (size_t j = 0; j < cnt2; ++j)
|
||||
{
|
||||
T x = *v++, y = *v++;
|
||||
#ifdef USINGZ
|
||||
z_type z = Reinterpret<z_type>(*v++);
|
||||
path.push_back(Point<T>(x, y, z));
|
||||
#else
|
||||
path.push_back(Point<T>(x, y));
|
||||
#endif
|
||||
}
|
||||
result.push_back(path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Path64 ConvertCPathDToPath64WithScale(const CPathD path, double scale)
|
||||
{
|
||||
Path64 result;
|
||||
if (!path) return result;
|
||||
double* v = path;
|
||||
size_t cnt = static_cast<size_t>(*v);
|
||||
v += 2; // skip 0 value
|
||||
result.reserve(cnt);
|
||||
for (size_t j = 0; j < cnt; ++j)
|
||||
{
|
||||
double x = *v++ * scale;
|
||||
double y = *v++ * scale;
|
||||
#ifdef USINGZ
|
||||
z_type z = Reinterpret<z_type>(*v++);
|
||||
result.push_back(Point64(x, y, z));
|
||||
#else
|
||||
result.push_back(Point64(x, y));
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Paths64 ConvertCPathsDToPaths64(const CPathsD paths, double scale)
|
||||
{
|
||||
Paths64 result;
|
||||
if (!paths) return result;
|
||||
double* v = paths;
|
||||
++v; // skip the first value (0)
|
||||
size_t cnt = static_cast<size_t>(*v++);
|
||||
result.reserve(cnt);
|
||||
for (size_t i = 0; i < cnt; ++i)
|
||||
{
|
||||
size_t cnt2 = static_cast<size_t>(*v);
|
||||
v += 2;
|
||||
Path64 path;
|
||||
path.reserve(cnt2);
|
||||
for (size_t j = 0; j < cnt2; ++j)
|
||||
{
|
||||
double x = *v++ * scale;
|
||||
double y = *v++ * scale;
|
||||
#ifdef USINGZ
|
||||
z_type z = Reinterpret<z_type>(*v++);
|
||||
path.push_back(Point64(x, y, z));
|
||||
#else
|
||||
path.push_back(Point64(x, y));
|
||||
#endif
|
||||
}
|
||||
result.push_back(path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void CreateCPolyPath64(const PolyPath64* pp, int64_t*& v)
|
||||
{
|
||||
*v++ = static_cast<int64_t>(pp->Polygon().size());
|
||||
*v++ = static_cast<int64_t>(pp->Count());
|
||||
for (const Point64& pt : pp->Polygon())
|
||||
{
|
||||
*v++ = pt.x;
|
||||
*v++ = pt.y;
|
||||
#ifdef USINGZ
|
||||
* v++ = Reinterpret<int64_t>(pt.z); // raw memory copy
|
||||
#endif
|
||||
}
|
||||
for (size_t i = 0; i < pp->Count(); ++i)
|
||||
CreateCPolyPath64(pp->Child(i), v);
|
||||
}
|
||||
|
||||
static void CreateCPolyPathD(const PolyPathD* pp, double*& v)
|
||||
{
|
||||
*v++ = static_cast<double>(pp->Polygon().size());
|
||||
*v++ = static_cast<double>(pp->Count());
|
||||
for (const PointD& pt : pp->Polygon())
|
||||
{
|
||||
*v++ = pt.x;
|
||||
*v++ = pt.y;
|
||||
#ifdef USINGZ
|
||||
* v++ = Reinterpret<double>(pt.z); // raw memory copy
|
||||
#endif
|
||||
}
|
||||
for (size_t i = 0; i < pp->Count(); ++i)
|
||||
CreateCPolyPathD(pp->Child(i), v);
|
||||
}
|
||||
|
||||
static int64_t* CreateCPolyTree64(const PolyTree64& tree)
|
||||
{
|
||||
size_t cnt, array_len;
|
||||
GetPolytreeCountAndCStorageSize64(tree, cnt, array_len);
|
||||
if (!cnt) return nullptr;
|
||||
// allocate storage
|
||||
int64_t* result = new int64_t[array_len];
|
||||
int64_t* v = result;
|
||||
*v++ = static_cast<int64_t>(array_len);
|
||||
*v++ = static_cast<int64_t>(tree.Count());
|
||||
for (size_t i = 0; i < tree.Count(); ++i)
|
||||
CreateCPolyPath64(tree.Child(i), v);
|
||||
return result;
|
||||
}
|
||||
|
||||
static double* CreateCPolyTreeD(const PolyTreeD& tree)
|
||||
{
|
||||
double scale = std::log10(tree.Scale());
|
||||
size_t cnt, array_len;
|
||||
GetPolytreeCountAndCStorageSizeD(tree, cnt, array_len);
|
||||
if (!cnt) return nullptr;
|
||||
// allocate storage
|
||||
double* result = new double[array_len];
|
||||
double* v = result;
|
||||
*v++ = static_cast<double>(array_len);
|
||||
*v++ = static_cast<double>(tree.Count());
|
||||
for (size_t i = 0; i < tree.Count(); ++i)
|
||||
CreateCPolyPathD(tree.Child(i), v);
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// EXPORTED FUNCTION DEFINITIONS
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
EXTERN_DLL_EXPORT const char* Version()
|
||||
{
|
||||
return CLIPPER2_VERSION;
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp64(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPaths64 subjects,
|
||||
const CPaths64 subjects_open, const CPaths64 clips,
|
||||
CPaths64& solution, CPaths64& solution_open,
|
||||
bool preserve_collinear, bool reverse_solution)
|
||||
{
|
||||
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
|
||||
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
|
||||
|
||||
Paths64 sub, sub_open, clp, sol, sol_open;
|
||||
sub = ConvertCPathsToPathsT(subjects);
|
||||
sub_open = ConvertCPathsToPathsT(subjects_open);
|
||||
clp = ConvertCPathsToPathsT(clips);
|
||||
|
||||
Clipper64 clipper;
|
||||
clipper.PreserveCollinear(preserve_collinear);
|
||||
clipper.ReverseSolution(reverse_solution);
|
||||
#ifdef USINGZ
|
||||
if (dllCallback64)
|
||||
clipper.SetZCallback(dllCallback64);
|
||||
#endif
|
||||
if (sub.size() > 0) clipper.AddSubject(sub);
|
||||
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
|
||||
if (clp.size() > 0) clipper.AddClip(clp);
|
||||
if (!clipper.Execute(ClipType(cliptype), FillRule(fillrule), sol, sol_open))
|
||||
return -1; // clipping bug - should never happen :)
|
||||
solution = CreateCPathsFromPathsT(sol);
|
||||
solution_open = CreateCPathsFromPathsT(sol_open);
|
||||
return 0; //success !!
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp_PolyTree64(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPaths64 subjects,
|
||||
const CPaths64 subjects_open, const CPaths64 clips,
|
||||
CPolyTree64& sol_tree, CPaths64& solution_open,
|
||||
bool preserve_collinear, bool reverse_solution)
|
||||
{
|
||||
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
|
||||
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
|
||||
Paths64 sub, sub_open, clp, sol_open;
|
||||
sub = ConvertCPathsToPathsT(subjects);
|
||||
sub_open = ConvertCPathsToPathsT(subjects_open);
|
||||
clp = ConvertCPathsToPathsT(clips);
|
||||
|
||||
PolyTree64 tree;
|
||||
Clipper64 clipper;
|
||||
clipper.PreserveCollinear(preserve_collinear);
|
||||
clipper.ReverseSolution(reverse_solution);
|
||||
#ifdef USINGZ
|
||||
if (dllCallback64)
|
||||
clipper.SetZCallback(dllCallback64);
|
||||
#endif
|
||||
if (sub.size() > 0) clipper.AddSubject(sub);
|
||||
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
|
||||
if (clp.size() > 0) clipper.AddClip(clp);
|
||||
if (!clipper.Execute(ClipType(cliptype), FillRule(fillrule), tree, sol_open))
|
||||
return -1; // clipping bug - should never happen :)
|
||||
|
||||
sol_tree = CreateCPolyTree64(tree);
|
||||
solution_open = CreateCPathsFromPathsT(sol_open);
|
||||
return 0; //success !!
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOpD(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPathsD subjects,
|
||||
const CPathsD subjects_open, const CPathsD clips,
|
||||
CPathsD& solution, CPathsD& solution_open, int precision,
|
||||
bool preserve_collinear, bool reverse_solution)
|
||||
{
|
||||
if (precision < -8 || precision > 8) return -5;
|
||||
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
|
||||
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
|
||||
//const double scale = std::pow(10, precision);
|
||||
|
||||
PathsD sub, sub_open, clp, sol, sol_open;
|
||||
sub = ConvertCPathsToPathsT(subjects);
|
||||
sub_open = ConvertCPathsToPathsT(subjects_open);
|
||||
clp = ConvertCPathsToPathsT(clips);
|
||||
|
||||
ClipperD clipper(precision);
|
||||
clipper.PreserveCollinear(preserve_collinear);
|
||||
clipper.ReverseSolution(reverse_solution);
|
||||
#ifdef USINGZ
|
||||
if (dllCallbackD)
|
||||
clipper.SetZCallback(dllCallbackD);
|
||||
#endif
|
||||
if (sub.size() > 0) clipper.AddSubject(sub);
|
||||
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
|
||||
if (clp.size() > 0) clipper.AddClip(clp);
|
||||
if (!clipper.Execute(ClipType(cliptype),
|
||||
FillRule(fillrule), sol, sol_open)) return -1;
|
||||
solution = CreateCPathsDFromPathsD(sol);
|
||||
solution_open = CreateCPathsDFromPathsD(sol_open);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT int BooleanOp_PolyTreeD(uint8_t cliptype,
|
||||
uint8_t fillrule, const CPathsD subjects,
|
||||
const CPathsD subjects_open, const CPathsD clips,
|
||||
CPolyTreeD& solution, CPathsD& solution_open, int precision,
|
||||
bool preserve_collinear, bool reverse_solution)
|
||||
{
|
||||
if (precision < -8 || precision > 8) return -5;
|
||||
if (cliptype > static_cast<uint8_t>(ClipType::Xor)) return -4;
|
||||
if (fillrule > static_cast<uint8_t>(FillRule::Negative)) return -3;
|
||||
//double scale = std::pow(10, precision);
|
||||
|
||||
int err = 0;
|
||||
PathsD sub, sub_open, clp, sol_open;
|
||||
sub = ConvertCPathsToPathsT(subjects);
|
||||
sub_open = ConvertCPathsToPathsT(subjects_open);
|
||||
clp = ConvertCPathsToPathsT(clips);
|
||||
|
||||
PolyTreeD tree;
|
||||
ClipperD clipper(precision);
|
||||
clipper.PreserveCollinear(preserve_collinear);
|
||||
clipper.ReverseSolution(reverse_solution);
|
||||
#ifdef USINGZ
|
||||
if (dllCallbackD)
|
||||
clipper.SetZCallback(dllCallbackD);
|
||||
#endif
|
||||
if (sub.size() > 0) clipper.AddSubject(sub);
|
||||
if (sub_open.size() > 0) clipper.AddOpenSubject(sub_open);
|
||||
if (clp.size() > 0) clipper.AddClip(clp);
|
||||
if (!clipper.Execute(ClipType(cliptype), FillRule(fillrule), tree, sol_open))
|
||||
return -1; // clipping bug - should never happen :)
|
||||
|
||||
solution = CreateCPolyTreeD(tree);
|
||||
solution_open = CreateCPathsDFromPathsD(sol_open);
|
||||
return 0; //success !!
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
|
||||
double delta, uint8_t jointype, uint8_t endtype, double miter_limit,
|
||||
double arc_tolerance, bool reverse_solution)
|
||||
{
|
||||
Paths64 pp;
|
||||
pp = ConvertCPathsToPathsT(paths);
|
||||
ClipperOffset clip_offset( miter_limit,
|
||||
arc_tolerance, reverse_solution);
|
||||
clip_offset.AddPaths(pp, JoinType(jointype), EndType(endtype));
|
||||
Paths64 result;
|
||||
clip_offset.Execute(delta, result);
|
||||
return CreateCPathsFromPathsT(result);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
int precision, double miter_limit,
|
||||
double arc_tolerance, bool reverse_solution)
|
||||
{
|
||||
if (precision < -8 || precision > 8 || !paths) return nullptr;
|
||||
|
||||
const double scale = std::pow(10, precision);
|
||||
ClipperOffset clip_offset(miter_limit, arc_tolerance, reverse_solution);
|
||||
Paths64 pp = ConvertCPathsDToPaths64(paths, scale);
|
||||
clip_offset.AddPaths(pp, JoinType(jointype), EndType(endtype));
|
||||
Paths64 result;
|
||||
clip_offset.Execute(delta * scale, result);
|
||||
return CreateCPathsDFromPaths64(result, 1 / scale);
|
||||
}
|
||||
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 InflatePath64(const CPath64 path,
|
||||
double delta, uint8_t jointype, uint8_t endtype, double miter_limit,
|
||||
double arc_tolerance, bool reverse_solution)
|
||||
{
|
||||
Path64 pp;
|
||||
pp = ConvertCPathToPathT(path);
|
||||
ClipperOffset clip_offset(miter_limit,
|
||||
arc_tolerance, reverse_solution);
|
||||
clip_offset.AddPath(pp, JoinType(jointype), EndType(endtype));
|
||||
Paths64 result;
|
||||
clip_offset.Execute(delta, result);
|
||||
return CreateCPathsFromPathsT(result);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD InflatePathD(const CPathD path,
|
||||
double delta, uint8_t jointype, uint8_t endtype,
|
||||
int precision, double miter_limit,
|
||||
double arc_tolerance, bool reverse_solution)
|
||||
{
|
||||
if (precision < -8 || precision > 8 || !path) return nullptr;
|
||||
|
||||
const double scale = std::pow(10, precision);
|
||||
ClipperOffset clip_offset(miter_limit, arc_tolerance, reverse_solution);
|
||||
Path64 pp = ConvertCPathDToPath64WithScale(path, scale);
|
||||
clip_offset.AddPath(pp, JoinType(jointype), EndType(endtype));
|
||||
Paths64 result;
|
||||
clip_offset.Execute(delta * scale, result);
|
||||
|
||||
return CreateCPathsDFromPaths64(result, 1 / scale);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect, const CPaths64 paths)
|
||||
{
|
||||
if (CRectIsEmpty(rect) || !paths) return nullptr;
|
||||
Rect64 r64 = CRectToRect(rect);
|
||||
class RectClip64 rc(r64);
|
||||
Paths64 pp = ConvertCPathsToPathsT(paths);
|
||||
Paths64 result = rc.Execute(pp);
|
||||
return CreateCPathsFromPathsT(result);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect, const CPathsD paths, int precision)
|
||||
{
|
||||
if (CRectIsEmpty(rect) || !paths) return nullptr;
|
||||
if (precision < -8 || precision > 8) return nullptr;
|
||||
const double scale = std::pow(10, precision);
|
||||
|
||||
RectD r = CRectToRect(rect);
|
||||
Rect64 rec = ScaleRect<int64_t, double>(r, scale);
|
||||
Paths64 pp = ConvertCPathsDToPaths64(paths, scale);
|
||||
class RectClip64 rc(rec);
|
||||
Paths64 result = rc.Execute(pp);
|
||||
|
||||
return CreateCPathsDFromPaths64(result, 1 / scale);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
|
||||
const CPaths64 paths)
|
||||
{
|
||||
if (CRectIsEmpty(rect) || !paths) return nullptr;
|
||||
Rect64 r = CRectToRect(rect);
|
||||
class RectClipLines64 rcl (r);
|
||||
Paths64 pp = ConvertCPathsToPathsT(paths);
|
||||
Paths64 result = rcl.Execute(pp);
|
||||
return CreateCPathsFromPathsT(result);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
|
||||
const CPathsD paths, int precision)
|
||||
{
|
||||
if (CRectIsEmpty(rect) || !paths) return nullptr;
|
||||
if (precision < -8 || precision > 8) return nullptr;
|
||||
|
||||
const double scale = std::pow(10, precision);
|
||||
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
|
||||
class RectClipLines64 rcl(r);
|
||||
Paths64 pp = ConvertCPathsDToPaths64(paths, scale);
|
||||
Paths64 result = rcl.Execute(pp);
|
||||
return CreateCPathsDFromPaths64(result, 1 / scale);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 MinkowskiSum64(const CPath64& cpattern, const CPath64& cpath, bool is_closed)
|
||||
{
|
||||
Path64 path = ConvertCPathToPathT(cpath);
|
||||
Path64 pattern = ConvertCPathToPathT(cpattern);
|
||||
Paths64 solution = MinkowskiSum(pattern, path, is_closed);
|
||||
return CreateCPathsFromPathsT(solution);
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT CPaths64 MinkowskiDiff64(const CPath64& cpattern, const CPath64& cpath, bool is_closed)
|
||||
{
|
||||
Path64 path = ConvertCPathToPathT(cpath);
|
||||
Path64 pattern = ConvertCPathToPathT(cpattern);
|
||||
Paths64 solution = MinkowskiDiff(pattern, path, is_closed);
|
||||
return CreateCPathsFromPathsT(solution);
|
||||
}
|
||||
|
||||
#ifdef USINGZ
|
||||
typedef void (*DLLZCallback64)(const Point64& e1bot, const Point64& e1top, const Point64& e2bot, const Point64& e2top, Point64& pt);
|
||||
typedef void (*DLLZCallbackD)(const PointD& e1bot, const PointD& e1top, const PointD& e2bot, const PointD& e2top, PointD& pt);
|
||||
|
||||
EXTERN_DLL_EXPORT void SetZCallback64(DLLZCallback64 callback)
|
||||
{
|
||||
dllCallback64 = callback;
|
||||
}
|
||||
|
||||
EXTERN_DLL_EXPORT void SetZCallbackD(DLLZCallbackD callback)
|
||||
{
|
||||
dllCallbackD = callback;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif // CLIPPER2_EXPORT_H
|
||||
@@ -0,0 +1,671 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 27 April 2024 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2024 *
|
||||
* Purpose : This module provides a simple interface to the Clipper Library *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CLIPPER_H
|
||||
#define CLIPPER_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "clipper2/clipper.core.h"
|
||||
#include "clipper2/clipper.engine.h"
|
||||
|
||||
namespace Clipper2Lib {
|
||||
|
||||
inline Paths64 BooleanOp(ClipType cliptype, FillRule fillrule,
|
||||
const Paths64& subjects, const Paths64& clips)
|
||||
{
|
||||
Paths64 result;
|
||||
Clipper64 clipper;
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.AddClip(clips);
|
||||
clipper.Execute(cliptype, fillrule, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void BooleanOp(ClipType cliptype, FillRule fillrule,
|
||||
const Paths64& subjects, const Paths64& clips, PolyTree64& solution)
|
||||
{
|
||||
Paths64 sol_open;
|
||||
Clipper64 clipper;
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.AddClip(clips);
|
||||
clipper.Execute(cliptype, fillrule, solution, sol_open);
|
||||
}
|
||||
|
||||
inline PathsD BooleanOp(ClipType cliptype, FillRule fillrule,
|
||||
const PathsD& subjects, const PathsD& clips, int precision = 2)
|
||||
{
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
PathsD result;
|
||||
if (error_code) return result;
|
||||
ClipperD clipper(precision);
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.AddClip(clips);
|
||||
clipper.Execute(cliptype, fillrule, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void BooleanOp(ClipType cliptype, FillRule fillrule,
|
||||
const PathsD& subjects, const PathsD& clips,
|
||||
PolyTreeD& polytree, int precision = 2)
|
||||
{
|
||||
polytree.Clear();
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (error_code) return;
|
||||
ClipperD clipper(precision);
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.AddClip(clips);
|
||||
clipper.Execute(cliptype, fillrule, polytree);
|
||||
}
|
||||
|
||||
inline Paths64 Intersect(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
|
||||
{
|
||||
return BooleanOp(ClipType::Intersection, fillrule, subjects, clips);
|
||||
}
|
||||
|
||||
inline PathsD Intersect(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
|
||||
{
|
||||
return BooleanOp(ClipType::Intersection, fillrule, subjects, clips, decimal_prec);
|
||||
}
|
||||
|
||||
inline Paths64 Union(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
|
||||
{
|
||||
return BooleanOp(ClipType::Union, fillrule, subjects, clips);
|
||||
}
|
||||
|
||||
inline PathsD Union(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
|
||||
{
|
||||
return BooleanOp(ClipType::Union, fillrule, subjects, clips, decimal_prec);
|
||||
}
|
||||
|
||||
inline Paths64 Union(const Paths64& subjects, FillRule fillrule)
|
||||
{
|
||||
Paths64 result;
|
||||
Clipper64 clipper;
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.Execute(ClipType::Union, fillrule, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline PathsD Union(const PathsD& subjects, FillRule fillrule, int precision = 2)
|
||||
{
|
||||
PathsD result;
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (error_code) return result;
|
||||
ClipperD clipper(precision);
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.Execute(ClipType::Union, fillrule, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Paths64 Difference(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
|
||||
{
|
||||
return BooleanOp(ClipType::Difference, fillrule, subjects, clips);
|
||||
}
|
||||
|
||||
inline PathsD Difference(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
|
||||
{
|
||||
return BooleanOp(ClipType::Difference, fillrule, subjects, clips, decimal_prec);
|
||||
}
|
||||
|
||||
inline Paths64 Xor(const Paths64& subjects, const Paths64& clips, FillRule fillrule)
|
||||
{
|
||||
return BooleanOp(ClipType::Xor, fillrule, subjects, clips);
|
||||
}
|
||||
|
||||
inline PathsD Xor(const PathsD& subjects, const PathsD& clips, FillRule fillrule, int decimal_prec = 2)
|
||||
{
|
||||
return BooleanOp(ClipType::Xor, fillrule, subjects, clips, decimal_prec);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> TranslatePath(const Path<T>& path, T dx, T dy)
|
||||
{
|
||||
Path<T> result;
|
||||
result.reserve(path.size());
|
||||
std::transform(path.begin(), path.end(), back_inserter(result),
|
||||
[dx, dy](const auto& pt) { return Point<T>(pt.x + dx, pt.y +dy); });
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Path64 TranslatePath(const Path64& path, int64_t dx, int64_t dy)
|
||||
{
|
||||
return TranslatePath<int64_t>(path, dx, dy);
|
||||
}
|
||||
|
||||
inline PathD TranslatePath(const PathD& path, double dx, double dy)
|
||||
{
|
||||
return TranslatePath<double>(path, dx, dy);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Paths<T> TranslatePaths(const Paths<T>& paths, T dx, T dy)
|
||||
{
|
||||
Paths<T> result;
|
||||
result.reserve(paths.size());
|
||||
std::transform(paths.begin(), paths.end(), back_inserter(result),
|
||||
[dx, dy](const auto& path) { return TranslatePath(path, dx, dy); });
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Paths64 TranslatePaths(const Paths64& paths, int64_t dx, int64_t dy)
|
||||
{
|
||||
return TranslatePaths<int64_t>(paths, dx, dy);
|
||||
}
|
||||
|
||||
inline PathsD TranslatePaths(const PathsD& paths, double dx, double dy)
|
||||
{
|
||||
return TranslatePaths<double>(paths, dx, dy);
|
||||
}
|
||||
|
||||
namespace details
|
||||
{
|
||||
|
||||
inline void PolyPathToPaths64(const PolyPath64& polypath, Paths64& paths)
|
||||
{
|
||||
paths.push_back(polypath.Polygon());
|
||||
for (const auto& child : polypath)
|
||||
PolyPathToPaths64(*child, paths);
|
||||
}
|
||||
|
||||
inline void PolyPathToPathsD(const PolyPathD& polypath, PathsD& paths)
|
||||
{
|
||||
paths.push_back(polypath.Polygon());
|
||||
for (const auto& child : polypath)
|
||||
PolyPathToPathsD(*child, paths);
|
||||
}
|
||||
|
||||
inline bool PolyPath64ContainsChildren(const PolyPath64& pp)
|
||||
{
|
||||
for (const auto& child : pp)
|
||||
{
|
||||
// return false if this child isn't fully contained by its parent
|
||||
|
||||
// checking for a single vertex outside is a bit too crude since
|
||||
// it doesn't account for rounding errors. It's better to check
|
||||
// for consecutive vertices found outside the parent's polygon.
|
||||
|
||||
int outsideCnt = 0;
|
||||
for (const Point64& pt : child->Polygon())
|
||||
{
|
||||
PointInPolygonResult result = PointInPolygon(pt, pp.Polygon());
|
||||
if (result == PointInPolygonResult::IsInside) --outsideCnt;
|
||||
else if (result == PointInPolygonResult::IsOutside) ++outsideCnt;
|
||||
if (outsideCnt > 1) return false;
|
||||
else if (outsideCnt < -1) break;
|
||||
}
|
||||
|
||||
// now check any nested children too
|
||||
if (child->Count() > 0 && !PolyPath64ContainsChildren(*child))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void OutlinePolyPath(std::ostream& os,
|
||||
size_t idx, bool isHole, size_t count, const std::string& preamble)
|
||||
{
|
||||
std::string plural = (count == 1) ? "." : "s.";
|
||||
if (isHole)
|
||||
os << preamble << "+- Hole (" << idx << ") contains " << count <<
|
||||
" nested polygon" << plural << std::endl;
|
||||
else
|
||||
os << preamble << "+- Polygon (" << idx << ") contains " << count <<
|
||||
" hole" << plural << std::endl;
|
||||
}
|
||||
|
||||
static void OutlinePolyPath64(std::ostream& os, const PolyPath64& pp,
|
||||
size_t idx, std::string preamble)
|
||||
{
|
||||
OutlinePolyPath(os, idx, pp.IsHole(), pp.Count(), preamble);
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
if (pp.Child(i)->Count())
|
||||
details::OutlinePolyPath64(os, *pp.Child(i), i, preamble + " ");
|
||||
}
|
||||
|
||||
static void OutlinePolyPathD(std::ostream& os, const PolyPathD& pp,
|
||||
size_t idx, std::string preamble)
|
||||
{
|
||||
OutlinePolyPath(os, idx, pp.IsHole(), pp.Count(), preamble);
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
if (pp.Child(i)->Count())
|
||||
details::OutlinePolyPathD(os, *pp.Child(i), i, preamble + " ");
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr void MakePathGeneric(const T an_array,
|
||||
size_t array_size, std::vector<U>& result)
|
||||
{
|
||||
result.reserve(array_size / 2);
|
||||
for (size_t i = 0; i < array_size; i +=2)
|
||||
#ifdef USINGZ
|
||||
result.push_back( U{ an_array[i], an_array[i + 1], 0} );
|
||||
#else
|
||||
result.push_back( U{ an_array[i], an_array[i + 1]} );
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end details namespace
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& os, const PolyTree64& pp)
|
||||
{
|
||||
std::string plural = (pp.Count() == 1) ? " polygon." : " polygons.";
|
||||
os << std::endl << "Polytree with " << pp.Count() << plural << std::endl;
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
if (pp.Child(i)->Count())
|
||||
details::OutlinePolyPath64(os, *pp.Child(i), i, " ");
|
||||
os << std::endl << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& os, const PolyTreeD& pp)
|
||||
{
|
||||
std::string plural = (pp.Count() == 1) ? " polygon." : " polygons.";
|
||||
os << std::endl << "Polytree with " << pp.Count() << plural << std::endl;
|
||||
for (size_t i = 0; i < pp.Count(); ++i)
|
||||
if (pp.Child(i)->Count())
|
||||
details::OutlinePolyPathD(os, *pp.Child(i), i, " ");
|
||||
os << std::endl << std::endl;
|
||||
if (!pp.Level()) os << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
inline Paths64 PolyTreeToPaths64(const PolyTree64& polytree)
|
||||
{
|
||||
Paths64 result;
|
||||
for (const auto& child : polytree)
|
||||
details::PolyPathToPaths64(*child, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline PathsD PolyTreeToPathsD(const PolyTreeD& polytree)
|
||||
{
|
||||
PathsD result;
|
||||
for (const auto& child : polytree)
|
||||
details::PolyPathToPathsD(*child, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline bool CheckPolytreeFullyContainsChildren(const PolyTree64& polytree)
|
||||
{
|
||||
for (const auto& child : polytree)
|
||||
if (child->Count() > 0 &&
|
||||
!details::PolyPath64ContainsChildren(*child))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
typename std::enable_if<
|
||||
std::is_integral<T>::value &&
|
||||
!std::is_same<char, T>::value, bool
|
||||
>::type = true>
|
||||
inline Path64 MakePath(const std::vector<T>& list)
|
||||
{
|
||||
const auto size = list.size() - list.size() % 2;
|
||||
if (list.size() != size)
|
||||
DoError(non_pair_error_i); // non-fatal without exception handling
|
||||
Path64 result;
|
||||
details::MakePathGeneric(list, size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N,
|
||||
typename std::enable_if<
|
||||
std::is_integral<T>::value &&
|
||||
!std::is_same<char, T>::value, bool
|
||||
>::type = true>
|
||||
inline Path64 MakePath(const T(&list)[N])
|
||||
{
|
||||
// Make the compiler error on unpaired value (i.e. no runtime effects).
|
||||
static_assert(N % 2 == 0, "MakePath requires an even number of arguments");
|
||||
Path64 result;
|
||||
details::MakePathGeneric(list, N, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
typename std::enable_if<
|
||||
std::is_arithmetic<T>::value &&
|
||||
!std::is_same<char, T>::value, bool
|
||||
>::type = true>
|
||||
inline PathD MakePathD(const std::vector<T>& list)
|
||||
{
|
||||
const auto size = list.size() - list.size() % 2;
|
||||
if (list.size() != size)
|
||||
DoError(non_pair_error_i); // non-fatal without exception handling
|
||||
PathD result;
|
||||
details::MakePathGeneric(list, size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N,
|
||||
typename std::enable_if<
|
||||
std::is_arithmetic<T>::value &&
|
||||
!std::is_same<char, T>::value, bool
|
||||
>::type = true>
|
||||
inline PathD MakePathD(const T(&list)[N])
|
||||
{
|
||||
// Make the compiler error on unpaired value (i.e. no runtime effects).
|
||||
static_assert(N % 2 == 0, "MakePath requires an even number of arguments");
|
||||
PathD result;
|
||||
details::MakePathGeneric(list, N, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef USINGZ
|
||||
template<typename T2, std::size_t N>
|
||||
inline Path64 MakePathZ(const T2(&list)[N])
|
||||
{
|
||||
static_assert(N % 3 == 0 && std::numeric_limits<T2>::is_integer,
|
||||
"MakePathZ requires integer values in multiples of 3");
|
||||
std::size_t size = N / 3;
|
||||
Path64 result(size);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[i] = Point64(list[i * 3],
|
||||
list[i * 3 + 1], list[i * 3 + 2]);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T2, std::size_t N>
|
||||
inline PathD MakePathZD(const T2(&list)[N])
|
||||
{
|
||||
static_assert(N % 3 == 0,
|
||||
"MakePathZD requires values in multiples of 3");
|
||||
std::size_t size = N / 3;
|
||||
PathD result(size);
|
||||
if constexpr (std::numeric_limits<T2>::is_integer)
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[i] = PointD(list[i * 3],
|
||||
list[i * 3 + 1], list[i * 3 + 2]);
|
||||
else
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[i] = PointD(list[i * 3], list[i * 3 + 1],
|
||||
static_cast<int64_t>(list[i * 3 + 2]));
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline Path64 TrimCollinear(const Path64& p, bool is_open_path = false)
|
||||
{
|
||||
size_t len = p.size();
|
||||
if (len < 3)
|
||||
{
|
||||
if (!is_open_path || len < 2 || p[0] == p[1]) return Path64();
|
||||
else return p;
|
||||
}
|
||||
|
||||
Path64 dst;
|
||||
dst.reserve(len);
|
||||
Path64::const_iterator srcIt = p.cbegin(), prevIt, stop = p.cend() - 1;
|
||||
|
||||
if (!is_open_path)
|
||||
{
|
||||
while (srcIt != stop && IsCollinear(*stop, *srcIt, *(srcIt + 1)))
|
||||
++srcIt;
|
||||
while (srcIt != stop && IsCollinear(*(stop - 1), *stop, *srcIt))
|
||||
--stop;
|
||||
if (srcIt == stop) return Path64();
|
||||
}
|
||||
|
||||
prevIt = srcIt++;
|
||||
dst.push_back(*prevIt);
|
||||
for (; srcIt != stop; ++srcIt)
|
||||
{
|
||||
if (!IsCollinear(*prevIt, *srcIt, *(srcIt + 1)))
|
||||
{
|
||||
prevIt = srcIt;
|
||||
dst.push_back(*prevIt);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_open_path)
|
||||
dst.push_back(*srcIt);
|
||||
else if (!IsCollinear(*prevIt, *stop, dst[0]))
|
||||
dst.push_back(*stop);
|
||||
else
|
||||
{
|
||||
while (dst.size() > 2 &&
|
||||
IsCollinear(dst[dst.size() - 1], dst[dst.size() - 2], dst[0]))
|
||||
dst.pop_back();
|
||||
if (dst.size() < 3) return Path64();
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
inline PathD TrimCollinear(const PathD& path, int precision, bool is_open_path = false)
|
||||
{
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (error_code) return PathD();
|
||||
const double scale = std::pow(10, precision);
|
||||
Path64 p = ScalePath<int64_t, double>(path, scale, error_code);
|
||||
if (error_code) return PathD();
|
||||
p = TrimCollinear(p, is_open_path);
|
||||
return ScalePath<double, int64_t>(p, 1/scale, error_code);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline double Distance(const Point<T> pt1, const Point<T> pt2)
|
||||
{
|
||||
return std::sqrt(DistanceSqr(pt1, pt2));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline double Length(const Path<T>& path, bool is_closed_path = false)
|
||||
{
|
||||
double result = 0.0;
|
||||
if (path.size() < 2) return result;
|
||||
auto it = path.cbegin(), stop = path.end() - 1;
|
||||
for (; it != stop; ++it)
|
||||
result += Distance(*it, *(it + 1));
|
||||
if (is_closed_path)
|
||||
result += Distance(*stop, *path.cbegin());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline bool NearCollinear(const Point<T>& pt1, const Point<T>& pt2, const Point<T>& pt3, double sin_sqrd_min_angle_rads)
|
||||
{
|
||||
double cp = std::abs(CrossProduct(pt1, pt2, pt3));
|
||||
return (cp * cp) / (DistanceSqr(pt1, pt2) * DistanceSqr(pt2, pt3)) < sin_sqrd_min_angle_rads;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> Ellipse(const Rect<T>& rect, size_t steps = 0)
|
||||
{
|
||||
return Ellipse(rect.MidPoint(),
|
||||
static_cast<double>(rect.Width()) *0.5,
|
||||
static_cast<double>(rect.Height()) * 0.5, steps);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> Ellipse(const Point<T>& center,
|
||||
double radiusX, double radiusY = 0, size_t steps = 0)
|
||||
{
|
||||
if (radiusX <= 0) return Path<T>();
|
||||
if (radiusY <= 0) radiusY = radiusX;
|
||||
if (steps <= 2)
|
||||
steps = static_cast<size_t>(PI * sqrt((radiusX + radiusY) / 2));
|
||||
|
||||
double si = std::sin(2 * PI / steps);
|
||||
double co = std::cos(2 * PI / steps);
|
||||
double dx = co, dy = si;
|
||||
Path<T> result;
|
||||
result.reserve(steps);
|
||||
result.push_back(Point<T>(center.x + radiusX, static_cast<double>(center.y)));
|
||||
for (size_t i = 1; i < steps; ++i)
|
||||
{
|
||||
result.push_back(Point<T>(center.x + radiusX * dx, center.y + radiusY * dy));
|
||||
double x = dx * co - dy * si;
|
||||
dy = dy * co + dx * si;
|
||||
dx = x;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline size_t GetNext(size_t current, size_t high,
|
||||
const std::vector<bool>& flags)
|
||||
{
|
||||
++current;
|
||||
while (current <= high && flags[current]) ++current;
|
||||
if (current <= high) return current;
|
||||
current = 0;
|
||||
while (flags[current]) ++current;
|
||||
return current;
|
||||
}
|
||||
|
||||
inline size_t GetPrior(size_t current, size_t high,
|
||||
const std::vector<bool>& flags)
|
||||
{
|
||||
if (current == 0) current = high;
|
||||
else --current;
|
||||
while (current > 0 && flags[current]) --current;
|
||||
if (!flags[current]) return current;
|
||||
current = high;
|
||||
while (flags[current]) --current;
|
||||
return current;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> SimplifyPath(const Path<T> &path,
|
||||
double epsilon, bool isClosedPath = true)
|
||||
{
|
||||
const size_t len = path.size(), high = len -1;
|
||||
const double epsSqr = Sqr(epsilon);
|
||||
if (len < 4) return Path<T>(path);
|
||||
|
||||
std::vector<bool> flags(len);
|
||||
std::vector<double> distSqr(len);
|
||||
size_t prior = high, curr = 0, start, next, prior2;
|
||||
if (isClosedPath)
|
||||
{
|
||||
distSqr[0] = PerpendicDistFromLineSqrd(path[0], path[high], path[1]);
|
||||
distSqr[high] = PerpendicDistFromLineSqrd(path[high], path[0], path[high - 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
distSqr[0] = MAX_DBL;
|
||||
distSqr[high] = MAX_DBL;
|
||||
}
|
||||
for (size_t i = 1; i < high; ++i)
|
||||
distSqr[i] = PerpendicDistFromLineSqrd(path[i], path[i - 1], path[i + 1]);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (distSqr[curr] > epsSqr)
|
||||
{
|
||||
start = curr;
|
||||
do
|
||||
{
|
||||
curr = GetNext(curr, high, flags);
|
||||
} while (curr != start && distSqr[curr] > epsSqr);
|
||||
if (curr == start) break;
|
||||
}
|
||||
|
||||
prior = GetPrior(curr, high, flags);
|
||||
next = GetNext(curr, high, flags);
|
||||
if (next == prior) break;
|
||||
|
||||
// flag for removal the smaller of adjacent 'distances'
|
||||
if (distSqr[next] < distSqr[curr])
|
||||
{
|
||||
prior2 = prior;
|
||||
prior = curr;
|
||||
curr = next;
|
||||
next = GetNext(next, high, flags);
|
||||
}
|
||||
else
|
||||
prior2 = GetPrior(prior, high, flags);
|
||||
|
||||
flags[curr] = true;
|
||||
curr = next;
|
||||
next = GetNext(next, high, flags);
|
||||
|
||||
if (isClosedPath || ((curr != high) && (curr != 0)))
|
||||
distSqr[curr] = PerpendicDistFromLineSqrd(path[curr], path[prior], path[next]);
|
||||
if (isClosedPath || ((prior != 0) && (prior != high)))
|
||||
distSqr[prior] = PerpendicDistFromLineSqrd(path[prior], path[prior2], path[curr]);
|
||||
}
|
||||
Path<T> result;
|
||||
result.reserve(len);
|
||||
for (typename Path<T>::size_type i = 0; i < len; ++i)
|
||||
if (!flags[i]) result.push_back(path[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Paths<T> SimplifyPaths(const Paths<T> &paths,
|
||||
double epsilon, bool isClosedPath = true)
|
||||
{
|
||||
Paths<T> result;
|
||||
result.reserve(paths.size());
|
||||
for (const auto& path : paths)
|
||||
result.push_back(SimplifyPath(path, epsilon, isClosedPath));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void RDP(const Path<T> path, std::size_t begin,
|
||||
std::size_t end, double epsSqrd, std::vector<bool>& flags)
|
||||
{
|
||||
typename Path<T>::size_type idx = 0;
|
||||
double max_d = 0;
|
||||
while (end > begin && path[begin] == path[end]) flags[end--] = false;
|
||||
for (typename Path<T>::size_type i = begin + 1; i < end; ++i)
|
||||
{
|
||||
// PerpendicDistFromLineSqrd - avoids expensive Sqrt()
|
||||
double d = PerpendicDistFromLineSqrd(path[i], path[begin], path[end]);
|
||||
if (d <= max_d) continue;
|
||||
max_d = d;
|
||||
idx = i;
|
||||
}
|
||||
if (max_d <= epsSqrd) return;
|
||||
flags[idx] = true;
|
||||
if (idx > begin + 1) RDP(path, begin, idx, epsSqrd, flags);
|
||||
if (idx < end - 1) RDP(path, idx, end, epsSqrd, flags);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> RamerDouglasPeucker(const Path<T>& path, double epsilon)
|
||||
{
|
||||
const typename Path<T>::size_type len = path.size();
|
||||
if (len < 5) return Path<T>(path);
|
||||
std::vector<bool> flags(len);
|
||||
flags[0] = true;
|
||||
flags[len - 1] = true;
|
||||
RDP(path, 0, len - 1, Sqr(epsilon), flags);
|
||||
Path<T> result;
|
||||
result.reserve(len);
|
||||
for (typename Path<T>::size_type i = 0; i < len; ++i)
|
||||
if (flags[i])
|
||||
result.push_back(path[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Paths<T> RamerDouglasPeucker(const Paths<T>& paths, double epsilon)
|
||||
{
|
||||
Paths<T> result;
|
||||
result.reserve(paths.size());
|
||||
std::transform(paths.begin(), paths.end(), back_inserter(result),
|
||||
[epsilon](const auto& path)
|
||||
{ return RamerDouglasPeucker<T>(path, epsilon); });
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end Clipper2Lib namespace
|
||||
|
||||
#endif // CLIPPER_H
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef CLIPPER_VERSION_H
|
||||
#define CLIPPER_VERSION_H
|
||||
|
||||
constexpr auto CLIPPER2_VERSION = "1.4.0";
|
||||
|
||||
#endif // CLIPPER_VERSION_H
|
||||
File diff suppressed because it is too large
Load Diff
+57
-36
@@ -24,10 +24,12 @@
|
||||
#include "dirtiles.hpp"
|
||||
#include "pmtiles_file.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "usage.hpp"
|
||||
|
||||
int minzoom = 0;
|
||||
int maxzoom = 32;
|
||||
bool force = false;
|
||||
std::set<std::string> include_attr;
|
||||
|
||||
bool progress_time() {
|
||||
return false;
|
||||
@@ -217,7 +219,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::st
|
||||
} else if (coordinate_mode == 2) { // integer
|
||||
scale = 1;
|
||||
}
|
||||
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state, scale);
|
||||
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state, scale, include_attr);
|
||||
|
||||
if (!pipeline) {
|
||||
if (true) {
|
||||
@@ -246,23 +248,26 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
|
||||
if (fd >= 0) {
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == 0) {
|
||||
if (st.st_size < 50 * 1024 * 1024) {
|
||||
char *map = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (map != NULL && map != MAP_FAILED) {
|
||||
if (strcmp(map, "SQLite format 3") != 0 && strncmp(map, "PMTiles", 7) != 0) {
|
||||
if (z >= 0) {
|
||||
char *map = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (map != NULL && map != MAP_FAILED) {
|
||||
if (strcmp(map, "SQLite format 3") != 0 && strncmp(map, "PMTiles", 7) != 0) {
|
||||
if (z >= 0) {
|
||||
if (st.st_size > 250 * 1024 * 1024) {
|
||||
fprintf(stderr, "%s: unrealistically large single-tile size %zu\n", fname, (size_t) st.st_size);
|
||||
exit(EXIT_MEMORY);
|
||||
} else {
|
||||
std::string s = std::string(map, st.st_size);
|
||||
handle(s, z, x, y, to_decode, pipeline, stats, state, coordinate_mode);
|
||||
munmap(map, st.st_size);
|
||||
return;
|
||||
} else {
|
||||
fprintf(stderr, "Must specify zoom/x/y to decode a single pbf file\n");
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Must specify zoom/x/y to decode a single pbf file\n");
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
}
|
||||
munmap(map, st.st_size);
|
||||
}
|
||||
munmap(map, st.st_size);
|
||||
} else {
|
||||
perror("fstat");
|
||||
}
|
||||
@@ -545,8 +550,42 @@ 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) {
|
||||
fprintf(stderr, "Usage: %s [-s projection] [-Z minzoom] [-z maxzoom] [-l layer ...] file.mbtiles [zoom x y]\n", argv[0]);
|
||||
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");
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
|
||||
@@ -560,32 +599,10 @@ int main(int argc, char **argv) {
|
||||
std::set<std::string> exclude_meta;
|
||||
int coordinate_mode = 0;
|
||||
|
||||
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'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
strip_usage_headings(long_options, real_long_options);
|
||||
std::string getopt_str = getopt_string(real_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(':');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, NULL)) != -1) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
break;
|
||||
@@ -630,6 +647,10 @@ int main(int argc, char **argv) {
|
||||
exclude_meta.insert(optarg);
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
include_attr.insert(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(argv);
|
||||
}
|
||||
|
||||
+19
-2
@@ -1,8 +1,11 @@
|
||||
#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;
|
||||
@@ -48,8 +51,20 @@ 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) {
|
||||
fprintf(stderr, "Usage: %s file.mbtiles ...\n", argv[0]);
|
||||
static const char *const forms[] = {
|
||||
"file.mbtiles ...",
|
||||
NULL,
|
||||
};
|
||||
|
||||
print_usage(stderr, argv[0], forms, long_options, NULL);
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
|
||||
@@ -58,7 +73,9 @@ int main(int argc, char **argv) {
|
||||
// extern char *optarg;
|
||||
int i;
|
||||
|
||||
while ((i = getopt(argc, argv, "")) != -1) {
|
||||
std::string getopt_str = getopt_string(long_options);
|
||||
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
|
||||
usage(argv);
|
||||
}
|
||||
|
||||
|
||||
+1
-322
@@ -9,170 +9,6 @@
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "text.hpp"
|
||||
|
||||
static std::string mvt_value_to_string(mvt_value const &one, bool &fail, std::vector<std::string> const &unidecode_data) {
|
||||
switch (one.type) {
|
||||
case mvt_string:
|
||||
if (unidecode_data.size() > 0) {
|
||||
return unidecode_smash(unidecode_data, one.c_str());
|
||||
} else {
|
||||
return one.get_string_value();
|
||||
}
|
||||
case mvt_float:
|
||||
return milo::dtoa_milo(one.numeric_value.float_value);
|
||||
case mvt_double:
|
||||
return milo::dtoa_milo(one.numeric_value.double_value);
|
||||
case mvt_int:
|
||||
return std::to_string(one.numeric_value.int_value);
|
||||
case mvt_uint:
|
||||
return std::to_string(one.numeric_value.uint_value);
|
||||
case mvt_sint:
|
||||
return std::to_string(one.numeric_value.sint_value);
|
||||
case mvt_bool:
|
||||
return one.numeric_value.bool_value ? "true" : "false";
|
||||
case mvt_null:
|
||||
fail = true; // null op string => null
|
||||
return "";
|
||||
case mvt_no_such_key:
|
||||
default:
|
||||
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
// Alter the JSON parse tree in place to replace the original match string
|
||||
// with its unidecode-smashed version.
|
||||
//
|
||||
// To avoid repeated re-smashings of the same JSON object, objects that have
|
||||
// already been smashed are marked by setting their refcon to the unidecode data.
|
||||
static void smash(std::vector<std::string> const &unidecode_data, json_object *j) {
|
||||
if (j->value.string.refcon == (void *) &unidecode_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string s = unidecode_smash(unidecode_data, j->value.string.string);
|
||||
j->value.string.string = (char *) realloc(j->value.string.string, s.size() + 1);
|
||||
if (j->value.string.string == NULL) {
|
||||
perror("realloc for unidecode_smash");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
strcpy(j->value.string.string, s.c_str());
|
||||
j->value.string.refcon = (void *) &unidecode_data;
|
||||
}
|
||||
|
||||
int compare_fsl(mvt_value const &one, json_object *two, bool &fail, std::vector<std::string> const &unidecode_data) {
|
||||
// In FSL expressions, the attribute value is coerced to the type
|
||||
// of the JSON literal value it is being compared to.
|
||||
//
|
||||
// If it cannot be converted, the comparison returns null
|
||||
// (which is distinct from true and false but is falsy if
|
||||
// it is the final output value).
|
||||
|
||||
if (two->type == JSON_NULL) {
|
||||
fail = true; // anything op null => null
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (two->type == JSON_NUMBER) {
|
||||
double lhs;
|
||||
|
||||
switch (one.type) {
|
||||
case mvt_string: {
|
||||
char *endptr = NULL;
|
||||
const char *s = one.c_str();
|
||||
lhs = strtod(s, &endptr);
|
||||
if (endptr == s) {
|
||||
fail = true; // non-numeric-string op number => null
|
||||
return 0;
|
||||
}
|
||||
} break;
|
||||
case mvt_float:
|
||||
lhs = one.numeric_value.float_value;
|
||||
break;
|
||||
case mvt_double:
|
||||
lhs = one.numeric_value.double_value;
|
||||
break;
|
||||
case mvt_int:
|
||||
lhs = one.numeric_value.int_value;
|
||||
break;
|
||||
case mvt_uint:
|
||||
lhs = one.numeric_value.uint_value;
|
||||
break;
|
||||
case mvt_sint:
|
||||
lhs = one.numeric_value.sint_value;
|
||||
break;
|
||||
case mvt_bool:
|
||||
lhs = one.numeric_value.bool_value;
|
||||
break;
|
||||
case mvt_null:
|
||||
fail = true; // null op number => null
|
||||
return 0;
|
||||
default:
|
||||
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
if (lhs < two->value.number.number) {
|
||||
return -1;
|
||||
} else if (lhs > two->value.number.number) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (two->type == JSON_STRING) {
|
||||
std::string lhs = mvt_value_to_string(one, fail, unidecode_data);
|
||||
|
||||
if (unidecode_data.size() > 0) {
|
||||
smash(unidecode_data, two);
|
||||
}
|
||||
|
||||
return strcmp(lhs.c_str(), two->value.string.string);
|
||||
}
|
||||
|
||||
if (two->type == JSON_TRUE || two->type == JSON_FALSE) {
|
||||
bool lhs;
|
||||
|
||||
switch (one.type) {
|
||||
case mvt_string:
|
||||
lhs = one.get_string_view().size() > 0;
|
||||
break;
|
||||
case mvt_float:
|
||||
lhs = one.numeric_value.float_value != 0;
|
||||
break;
|
||||
case mvt_double:
|
||||
lhs = one.numeric_value.double_value != 0;
|
||||
break;
|
||||
case mvt_int:
|
||||
lhs = one.numeric_value.int_value != 0;
|
||||
break;
|
||||
case mvt_uint:
|
||||
lhs = one.numeric_value.uint_value != 0;
|
||||
break;
|
||||
case mvt_sint:
|
||||
lhs = one.numeric_value.sint_value != 0;
|
||||
break;
|
||||
case mvt_bool:
|
||||
lhs = one.numeric_value.bool_value;
|
||||
break;
|
||||
case mvt_null:
|
||||
fail = true; // null op bool => null
|
||||
return 0;
|
||||
|
||||
case mvt_no_such_key:
|
||||
default:
|
||||
fprintf(stderr, "unhandled mvt_type %d\n", one.type);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
bool rhs = two->type == JSON_TRUE;
|
||||
return lhs - rhs;
|
||||
}
|
||||
|
||||
fprintf(stderr, "unhandled JSON type %d\n", two->type);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
int compare(mvt_value const &one, json_object *two, bool &fail) {
|
||||
switch (one.type) {
|
||||
case mvt_string:
|
||||
@@ -262,7 +98,7 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
|
||||
} else if (f->type == JSON_FALSE) {
|
||||
return 0;
|
||||
} else if (f->type == JSON_NULL) {
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (f->type == JSON_NUMBER) {
|
||||
@@ -292,163 +128,6 @@ static int eval(std::function<mvt_value(std::string const &)> feature, json_obje
|
||||
exit(EXIT_FILTER);
|
||||
}
|
||||
|
||||
// FSL conjunctions
|
||||
if (f->value.array.length == 3 &&
|
||||
f->value.array.array[1]->type == JSON_STRING &&
|
||||
(strcmp(f->value.array.array[1]->value.string.string, "or") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "and") == 0)) {
|
||||
int lhs;
|
||||
|
||||
if (f->value.array.array[0]->type == JSON_STRING) {
|
||||
// if LHS of a boolean conjunction is a string, it is an attribute reference
|
||||
mvt_value ff = feature(std::string(f->value.array.array[0]->value.string.string));
|
||||
if (ff.type != mvt_no_such_key) {
|
||||
if (ff.type == mvt_bool) {
|
||||
lhs = ff.numeric_value.bool_value;
|
||||
} else {
|
||||
lhs = -1; // not boolean: null
|
||||
}
|
||||
} else {
|
||||
lhs = -1; // not found: null
|
||||
}
|
||||
} else {
|
||||
lhs = eval(feature, f->value.array.array[0], exclude_attributes, unidecode_data);
|
||||
}
|
||||
|
||||
int rhs = eval(feature, f->value.array.array[2], exclude_attributes, unidecode_data);
|
||||
if (lhs < 0 && rhs < 0) {
|
||||
return -1; // null op null => null
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "or") == 0) {
|
||||
return (lhs > 0) || (rhs > 0);
|
||||
} else {
|
||||
return (lhs > 0) && (rhs > 0);
|
||||
}
|
||||
}
|
||||
|
||||
// FSL comparators
|
||||
if (f->value.array.length == 3 &&
|
||||
f->value.array.array[0]->type == JSON_STRING &&
|
||||
f->value.array.array[1]->type == JSON_STRING &&
|
||||
(strcmp(f->value.array.array[1]->value.string.string, "lt") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "gt") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "le") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "ge") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "eq") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "ne") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "cn") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "nc") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "in") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "ni") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "is") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "isnt") == 0 ||
|
||||
false)) {
|
||||
mvt_value lhs = feature(std::string(f->value.array.array[0]->value.string.string));
|
||||
if (lhs.type == mvt_no_such_key) {
|
||||
lhs.type = mvt_null;
|
||||
}
|
||||
|
||||
if (f->value.array.array[2]->type == JSON_NULL && strcmp(f->value.array.array[1]->value.string.string, "is") == 0) {
|
||||
return lhs.type == mvt_null; // null is null => true, anything is null => false
|
||||
}
|
||||
if (f->value.array.array[2]->type == JSON_NULL && strcmp(f->value.array.array[1]->value.string.string, "isnt") == 0) {
|
||||
return lhs.type != mvt_null; // null isnt null => false, anything isnt null => true
|
||||
}
|
||||
|
||||
bool fail = false;
|
||||
|
||||
if (f->value.array.array[2]->type == JSON_STRING &&
|
||||
(strcmp(f->value.array.array[1]->value.string.string, "cn") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "nc") == 0)) {
|
||||
if (lhs.type == mvt_null) {
|
||||
return -1; // null cn/nc anything => null
|
||||
}
|
||||
|
||||
std::string s = mvt_value_to_string(lhs, fail, unidecode_data);
|
||||
if (fail) {
|
||||
return -1; // null cn anything => false
|
||||
}
|
||||
|
||||
bool contains;
|
||||
if (unidecode_data.size() > 0) {
|
||||
smash(unidecode_data, f->value.array.array[2]);
|
||||
}
|
||||
contains = strstr(s.c_str(), f->value.array.array[2]->value.string.string);
|
||||
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "cn") == 0) {
|
||||
return contains;
|
||||
} else {
|
||||
return !contains;
|
||||
}
|
||||
}
|
||||
|
||||
if (f->value.array.array[2]->type == JSON_ARRAY &&
|
||||
(strcmp(f->value.array.array[1]->value.string.string, "in") == 0 ||
|
||||
strcmp(f->value.array.array[1]->value.string.string, "ni") == 0)) {
|
||||
// no null check here, since null can be in or not in
|
||||
|
||||
bool contains = false;
|
||||
for (size_t i = 0; i < f->value.array.array[2]->value.array.length; i++) {
|
||||
if (lhs.type == mvt_null) {
|
||||
if (f->value.array.array[2]->value.array.array[i]->type == JSON_NULL) {
|
||||
contains = true; // null is null
|
||||
break;
|
||||
} else {
|
||||
contains = false; // null isnt non-null
|
||||
}
|
||||
} else {
|
||||
fail = false;
|
||||
static std::vector<std::string> no_unidecode_data;
|
||||
int cmp = compare_fsl(lhs, f->value.array.array[2]->value.array.array[i], fail, no_unidecode_data);
|
||||
|
||||
if (fail) {
|
||||
contains = false; // non-null isnt null
|
||||
} else if (cmp == 0) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "in") == 0) {
|
||||
return contains;
|
||||
} else {
|
||||
return !contains;
|
||||
}
|
||||
}
|
||||
|
||||
if (lhs.type == mvt_null) {
|
||||
return -1; // null compared to anything => null
|
||||
}
|
||||
|
||||
int cmp = compare_fsl(lhs, f->value.array.array[2], fail, unidecode_data);
|
||||
if (fail) {
|
||||
return -1; // null
|
||||
}
|
||||
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "eq") == 0) {
|
||||
return cmp == 0;
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "ne") == 0) {
|
||||
return cmp != 0;
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "gt") == 0) {
|
||||
return cmp > 0;
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "ge") == 0) {
|
||||
return cmp >= 0;
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "lt") == 0) {
|
||||
return cmp < 0;
|
||||
}
|
||||
if (strcmp(f->value.array.array[1]->value.string.string, "le") == 0) {
|
||||
return cmp <= 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "expression fsl comparison: can't happen %s\n", f->value.array.array[1]->value.string.string);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
if (f->value.array.array[0]->type != JSON_STRING) {
|
||||
fprintf(stderr, "Filter operation is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FILTER);
|
||||
|
||||
+18
-13
@@ -146,8 +146,9 @@ void readFeature(const FlatGeobuf::Feature *feature, long long feature_sequence_
|
||||
sf.geometry = dv;
|
||||
sf.t = drawvec_type;
|
||||
|
||||
std::vector<std::string> full_keys;
|
||||
std::vector<std::shared_ptr<std::string>> full_keys;
|
||||
std::vector<serial_val> full_values;
|
||||
key_pool key_pool;
|
||||
|
||||
// assume tabular schema with columns in header
|
||||
size_t p_pos = 0;
|
||||
@@ -162,13 +163,13 @@ void readFeature(const FlatGeobuf::Feature *feature, long long feature_sequence_
|
||||
|
||||
serial_val sv;
|
||||
if (col_type == FlatGeobuf::ColumnType_Byte) {
|
||||
sv.type = mvt_sint;
|
||||
sv.type = mvt_double;
|
||||
int8_t byte_val;
|
||||
memcpy(&byte_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(byte_val));
|
||||
sv.s = std::to_string(byte_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(byte_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_UByte) {
|
||||
sv.type = mvt_uint;
|
||||
sv.type = mvt_double;
|
||||
uint8_t ubyte_val;
|
||||
memcpy(&ubyte_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(ubyte_val));
|
||||
sv.s = std::to_string(ubyte_val);
|
||||
@@ -177,46 +178,50 @@ void readFeature(const FlatGeobuf::Feature *feature, long long feature_sequence_
|
||||
sv.type = mvt_bool;
|
||||
uint8_t bool_val;
|
||||
memcpy(&bool_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(bool_val));
|
||||
sv.s = std::to_string(bool_val);
|
||||
if (bool_val) {
|
||||
sv.s = "true";
|
||||
} else {
|
||||
sv.s = "false";
|
||||
}
|
||||
p_pos += sizeof(uint16_t) + sizeof(bool_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_Short) {
|
||||
sv.type = mvt_sint;
|
||||
sv.type = mvt_double;
|
||||
int16_t short_val;
|
||||
memcpy(&short_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(short_val));
|
||||
sv.s = std::to_string(short_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(short_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_UShort) {
|
||||
sv.type = mvt_uint;
|
||||
sv.type = mvt_double;
|
||||
uint16_t ushort_val;
|
||||
memcpy(&ushort_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(ushort_val));
|
||||
sv.s = std::to_string(ushort_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(ushort_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_Int) {
|
||||
sv.type = mvt_sint;
|
||||
sv.type = mvt_double;
|
||||
int32_t int_val;
|
||||
memcpy(&int_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(int_val));
|
||||
sv.s = std::to_string(int_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(int_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_UInt) {
|
||||
sv.type = mvt_uint;
|
||||
sv.type = mvt_double;
|
||||
uint32_t uint_val;
|
||||
memcpy(&uint_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(uint_val));
|
||||
sv.s = std::to_string(uint_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(uint_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_Long) {
|
||||
sv.type = mvt_sint;
|
||||
sv.type = mvt_double;
|
||||
int64_t long_val;
|
||||
memcpy(&long_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(long_val));
|
||||
sv.s = std::to_string(long_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(long_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_ULong) {
|
||||
sv.type = mvt_uint;
|
||||
int64_t ulong_val;
|
||||
sv.type = mvt_double;
|
||||
uint64_t ulong_val;
|
||||
memcpy(&ulong_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(ulong_val));
|
||||
sv.s = std::to_string(ulong_val);
|
||||
p_pos += sizeof(uint16_t) + sizeof(ulong_val);
|
||||
} else if (col_type == FlatGeobuf::ColumnType_Float) {
|
||||
sv.type = mvt_float;
|
||||
sv.type = mvt_double;
|
||||
float float_val;
|
||||
memcpy(&float_val, feature->properties()->data() + p_pos + sizeof(uint16_t), sizeof(float_val));
|
||||
sv.s = milo::dtoa_milo(float_val);
|
||||
@@ -239,7 +244,7 @@ void readFeature(const FlatGeobuf::Feature *feature, long long feature_sequence_
|
||||
fprintf(stderr, "flatgeobuf has unsupported column type %u\n", (unsigned int)col_type);
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
full_keys.push_back(h_column_names[col_idx]);
|
||||
full_keys.push_back(key_pool.pool(h_column_names[col_idx]));
|
||||
full_values.push_back(sv);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -270,14 +270,14 @@ std::vector<drawvec_type> readGeometry(protozero::pbf_reader &pbf, size_t dim, d
|
||||
return ret;
|
||||
}
|
||||
|
||||
void readFeature(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<std::string> &keys, struct serialization_state *sst, int layer, std::string layername) {
|
||||
void readFeature(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<std::string> &keys, struct serialization_state *sst, int layer, std::string layername, key_pool &key_pool) {
|
||||
std::vector<drawvec_type> dv;
|
||||
long long id = 0;
|
||||
bool has_id = false;
|
||||
std::vector<serial_val> values;
|
||||
std::map<std::string, serial_val> other;
|
||||
|
||||
std::vector<std::string> full_keys;
|
||||
std::vector<std::shared_ptr<std::string>> full_keys;
|
||||
std::vector<serial_val> full_values;
|
||||
|
||||
while (pbf.next()) {
|
||||
@@ -338,7 +338,7 @@ void readFeature(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<s
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
full_keys.push_back(keys[properties[i]]);
|
||||
full_keys.push_back(key_pool.pool(keys[properties[i]]));
|
||||
full_values.push_back(values[properties[i + 1]]);
|
||||
}
|
||||
|
||||
@@ -434,10 +434,11 @@ struct queue_run_arg {
|
||||
|
||||
void *run_parse_feature(void *v) {
|
||||
struct queue_run_arg *qra = (struct queue_run_arg *) v;
|
||||
key_pool key_pool;
|
||||
|
||||
for (size_t i = qra->start; i < qra->end; i++) {
|
||||
struct queued_feature &qf = feature_queue[i];
|
||||
readFeature(qf.pbf, qf.dim, qf.e, *qf.keys, &(*qf.sst)[qra->segment], qf.layer, qf.layername);
|
||||
readFeature(qf.pbf, qf.dim, qf.e, *qf.keys, &(*qf.sst)[qra->segment], qf.layer, qf.layername, key_pool);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
+3
-2
@@ -58,6 +58,7 @@ void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fnam
|
||||
}
|
||||
|
||||
size_t seq = 0;
|
||||
key_pool key_pool;
|
||||
while ((s = csv_getline(f)).size() > 0) {
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
@@ -89,7 +90,7 @@ void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fnam
|
||||
drawvec dv;
|
||||
dv.push_back(draw(VT_MOVETO, x, y));
|
||||
|
||||
std::vector<std::string> full_keys;
|
||||
std::vector<std::shared_ptr<std::string>> full_keys;
|
||||
std::vector<serial_val> full_values;
|
||||
|
||||
for (size_t i = 0; i < line.size(); i++) {
|
||||
@@ -107,7 +108,7 @@ void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fnam
|
||||
}
|
||||
sv.s = line[i];
|
||||
|
||||
full_keys.push_back(header[i]);
|
||||
full_keys.push_back(key_pool.pool(header[i]));
|
||||
full_values.push_back(sv);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -182,23 +182,24 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
nprop = properties->value.object.length;
|
||||
}
|
||||
|
||||
std::vector<std::string> keys;
|
||||
std::vector<std::shared_ptr<std::string>> full_keys;
|
||||
std::vector<serial_val> values;
|
||||
|
||||
keys.reserve(nprop);
|
||||
full_keys.reserve(nprop);
|
||||
values.reserve(nprop);
|
||||
key_pool key_pool;
|
||||
|
||||
for (size_t i = 0; i < nprop; i++) {
|
||||
if (properties->value.object.keys[i]->type == JSON_STRING) {
|
||||
serial_val sv = stringify_value(properties->value.object.values[i], sst->fname, sst->line, feature);
|
||||
|
||||
keys.emplace_back(properties->value.object.keys[i]->value.string.string);
|
||||
full_keys.emplace_back(key_pool.pool(properties->value.object.keys[i]->value.string.string));
|
||||
values.push_back(std::move(sv));
|
||||
}
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, sst->fname, sst->line, feature);
|
||||
parse_coordinates(t, coordinates, dv, VT_MOVETO, sst->fname, sst->line, feature);
|
||||
|
||||
serial_feature sf;
|
||||
sf.layer = layer;
|
||||
@@ -211,7 +212,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
sf.geometry = dv;
|
||||
sf.feature_minzoom = 0; // Will be filled in during index merging
|
||||
sf.seq = *(sst->layer_seq);
|
||||
sf.full_keys = std::move(keys);
|
||||
sf.full_keys = std::move(full_keys);
|
||||
sf.full_values = std::move(values);
|
||||
|
||||
return serialize_feature(sst, sf, tippecanoe_layername);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "main.hpp"
|
||||
#include "options.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "projection.hpp"
|
||||
|
||||
drawvec decode_geometry(const char **meta, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y) {
|
||||
drawvec out;
|
||||
|
||||
+44
-4
@@ -99,8 +99,13 @@ drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long
|
||||
drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
||||
void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t retain);
|
||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
||||
bool pnpoly_mp(drawvec const &geom, long long x, long long y);
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
||||
|
||||
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds);
|
||||
drawvec clip_lines_poly(drawvec const &geom, drawvec const &bounds);
|
||||
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds);
|
||||
|
||||
struct input_tile {
|
||||
std::string tile;
|
||||
int z;
|
||||
@@ -115,25 +120,60 @@ struct source_tile {
|
||||
int y;
|
||||
};
|
||||
|
||||
struct clipbbox {
|
||||
double lon1;
|
||||
double lat1;
|
||||
double lon2;
|
||||
double lat2;
|
||||
|
||||
long long minx;
|
||||
long long miny;
|
||||
long long maxx;
|
||||
long long maxy;
|
||||
|
||||
drawvec dv; // empty, or arbitrary clipping polygon
|
||||
};
|
||||
|
||||
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
int detail, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix,
|
||||
bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::vector<std::string> const &unidecode_data, double simplification,
|
||||
double tiny_polygon_size, std::vector<mvt_layer> const &bins);
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &bins, std::string const &bin_by_id_list,
|
||||
std::string const &accumulate_numeric, size_t feature_limit,
|
||||
std::vector<clipbbox> const &clipbboxes,
|
||||
bool deduplicate_by_id);
|
||||
|
||||
std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
|
||||
int detail, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
std::set<std::string> const &exclude,
|
||||
std::vector<std::string> const &exclude_prefix,
|
||||
bool do_compress,
|
||||
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
|
||||
bool demultiply, json_object *filter, bool preserve_input_order,
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::vector<std::string> const &unidecode_data, double simplification,
|
||||
double tiny_polygon_size, std::vector<mvt_layer> const &bins);
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &bins, std::string const &bin_by_id_list,
|
||||
std::string const &accumulate_numeric, size_t feature_limit,
|
||||
std::vector<clipbbox> const &clipbboxes,
|
||||
bool deduplicate_by_id);
|
||||
|
||||
draw center_of_mass_mp(const drawvec &dv);
|
||||
|
||||
void get_quadkey_bounds(long long xmin, long long ymin, long long xmax, long long ymax,
|
||||
unsigned long long *start, unsigned long long *end);
|
||||
|
||||
clipbbox parse_clip_poly(std::string arg);
|
||||
|
||||
bool line_is_too_small(drawvec const &geometry, int z, int detail);
|
||||
void coalesce_polygon(drawvec &geom, bool scale_up);
|
||||
|
||||
#endif
|
||||
|
||||
+34
-23
@@ -13,6 +13,7 @@
|
||||
#include "geojson-loop.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "errors.hpp"
|
||||
#include "usage.hpp"
|
||||
|
||||
int fail = EXIT_SUCCESS;
|
||||
bool wrap = false;
|
||||
@@ -407,34 +408,45 @@ 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 main(int argc, char **argv) {
|
||||
const char *csv = NULL;
|
||||
|
||||
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(':');
|
||||
}
|
||||
}
|
||||
}
|
||||
strip_usage_headings(long_options, real_long_options);
|
||||
std::string getopt_str = getopt_string(real_long_options);
|
||||
|
||||
extern int optind;
|
||||
int i;
|
||||
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, NULL)) != -1) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
break;
|
||||
@@ -461,8 +473,7 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unexpected option -%c\n", i);
|
||||
exit(EXIT_ARGS);
|
||||
usage(argv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
*.zip
|
||||
tmp/*
|
||||
@@ -1,34 +0,0 @@
|
||||
# Build the tippecanoe layer (binary)
|
||||
|
||||
1. On an AWS Linux 2 instance or image:
|
||||
|
||||
sudo yum update
|
||||
sudo yum install git clang sqlite-devel zlib-devel
|
||||
|
||||
2. Create a ZIP archive with the `tippecanoe` binary at `bin/tippecanoe` and upload as a Lambda layer
|
||||
3. Copy [lambda_function.py](lambda_function.py) (python 3.9 runtime)
|
||||
4. set the environment variable `OUTPUT_BUCKET` to your output bucket; give lambda IAM role access to input/output buckets
|
||||
5. Enable ACLs on the output bucket
|
||||
|
||||
```json
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "AllowGet",
|
||||
"Effect": "Allow",
|
||||
"Action": "s3:GetObject",
|
||||
"Resource": "arn:aws:s3:::protomaps-tippecanoe-test/*"
|
||||
},
|
||||
{
|
||||
"Sid": "AllowPut",
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject",
|
||||
"s3:PutObjectAcl"
|
||||
],
|
||||
"Resource": "arn:aws:s3:::protomaps-tippecanoe-test-output/*"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -1,2 +0,0 @@
|
||||
boto3==1.20.32
|
||||
botocore==1.23.32
|
||||
@@ -1,49 +0,0 @@
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import boto3
|
||||
from botocore import UNSIGNED
|
||||
from botocore.config import Config
|
||||
|
||||
# if the input bucket is publicly readable
|
||||
#s3 = boto3.client('s3',config=Config(signature_version=UNSIGNED))
|
||||
|
||||
def lambda_handler(event, context):
|
||||
bucket_name = event['Records'][0]['s3']['bucket']['name']
|
||||
input_key = event['Records'][0]['s3']['object']['key']
|
||||
tmpdir = '/tmp'
|
||||
run_tippecanoe('tippecanoe',tmpdir,bucket_name, input_key)
|
||||
return {
|
||||
'statusCode': 200,
|
||||
'body': json.dumps('Done!')
|
||||
}
|
||||
|
||||
# input formats: "geojsonseq", "fgb", "geobuf", "geojson", "csv"
|
||||
def split_key(key):
|
||||
if key.endswith(".gz"):
|
||||
root, ext = os.path.splitext(key[0:-3])
|
||||
return root, ext + ".gz"
|
||||
else:
|
||||
return os.path.splitext(key)
|
||||
|
||||
def run_tippecanoe(executable, tmpdir, bucket_name, input_key):
|
||||
s3 = boto3.client('s3')
|
||||
root, ext = split_key(input_key)
|
||||
input_path = os.path.join(tmpdir,'input' + ext)
|
||||
output_path = os.path.join(tmpdir,'output.mbtiles')
|
||||
s3.download_file(bucket_name,input_key,input_path)
|
||||
p = subprocess.Popen([executable,'-o',output_path,input_path,'--force','-u','-U','5'],stderr=subprocess.PIPE)
|
||||
for line in p.stderr:
|
||||
try:
|
||||
j = json.loads(line)
|
||||
s3.put_object(Body=json.dumps(j),Bucket=os.environ['OUTPUT_BUCKET'],Key=root + ".progress",ACL="public-read",ContentType="application/json",ContentDisposition="inline")
|
||||
except json.decoder.JSONDecodeError:
|
||||
pass
|
||||
s3.upload_file(output_path,os.environ['OUTPUT_BUCKET'],root + ".mbtiles")
|
||||
|
||||
if __name__ == "__main__":
|
||||
tmpdir = 'tmp'
|
||||
bucket_name = sys.argv[1]
|
||||
input_key = sys.argv[2]
|
||||
run_tippecanoe('../tippecanoe', tmpdir, bucket_name, input_key)
|
||||
@@ -1,26 +0,0 @@
|
||||
from tippecanoe import split_key
|
||||
import unittest
|
||||
|
||||
class TestTippecanoe(unittest.TestCase):
|
||||
def test_basic(self):
|
||||
root, ext = split_key("file.json")
|
||||
self.assertEqual(root,"file")
|
||||
self.assertEqual(ext,".json")
|
||||
|
||||
def test_basic_gz(self):
|
||||
root, ext = split_key("file.csv.gz")
|
||||
self.assertEqual(root,"file")
|
||||
self.assertEqual(ext,".csv.gz")
|
||||
|
||||
def test_nested_key(self):
|
||||
root, ext = split_key("dir/file.fgb")
|
||||
self.assertEqual(root,"dir/file")
|
||||
self.assertEqual(ext,".fgb")
|
||||
|
||||
def test_nested_key_gz(self):
|
||||
root, ext = split_key("dir/file.geojsonseq.gz")
|
||||
self.assertEqual(root,"dir/file")
|
||||
self.assertEqual(ext,".geojsonseq.gz")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -24,18 +24,6 @@ struct index {
|
||||
}
|
||||
};
|
||||
|
||||
struct clipbbox {
|
||||
double lon1;
|
||||
double lat1;
|
||||
double lon2;
|
||||
double lat2;
|
||||
|
||||
long long minx;
|
||||
long long miny;
|
||||
long long maxx;
|
||||
long long maxy;
|
||||
};
|
||||
|
||||
extern std::vector<clipbbox> clipbboxes;
|
||||
|
||||
void checkdisk(std::vector<struct reader> *r);
|
||||
@@ -64,6 +52,7 @@ extern std::map<std::string, serial_val> set_attributes;
|
||||
extern long long extend_zooms_max;
|
||||
extern int retain_points_multiplier;
|
||||
extern size_t maximum_string_attribute_length;
|
||||
extern unsigned long long preserve_multiplier_density_threshold;
|
||||
|
||||
struct order_field {
|
||||
std::string name;
|
||||
|
||||
+586
-769
File diff suppressed because it is too large
Load Diff
@@ -1296,7 +1296,10 @@ void correct_tree(ring_manager<T>& manager) {
|
||||
}
|
||||
if (!found) {
|
||||
if ((*itr)->is_hole()) {
|
||||
throw std::runtime_error("Could not properly place hole to a parent.");
|
||||
// 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);
|
||||
} else {
|
||||
// Assign to base of tree by passing nullptr
|
||||
reassign_as_child(*itr, static_cast<ring_ptr<T>>(nullptr), manager);
|
||||
|
||||
+5
-2
@@ -700,8 +700,11 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
|
||||
|
||||
m.strategies_json = stringify_strategies(strategies);
|
||||
|
||||
if (isinf(droprate)) {
|
||||
droprate = LLONG_MAX;
|
||||
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;
|
||||
}
|
||||
if (basezoom != maxzoom || droprate != 2.5 || retain_points_multiplier != 1) {
|
||||
m.decisions_json = std::string("{") +
|
||||
|
||||
@@ -316,6 +316,10 @@ struct sorted_value {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator()(const std::shared_ptr<sorted_value> &a, const std::shared_ptr<sorted_value> &b) {
|
||||
return *a < *b;
|
||||
}
|
||||
};
|
||||
|
||||
std::string mvt_tile::encode() {
|
||||
@@ -334,7 +338,7 @@ std::string mvt_tile::encode() {
|
||||
layer_writer.add_string(3, layers[i].keys[j]); /* key */
|
||||
}
|
||||
|
||||
std::vector<sorted_value> sorted_values;
|
||||
std::vector<std::shared_ptr<sorted_value>> sorted_values;
|
||||
|
||||
for (size_t v = 0; v < layers[i].values.size(); v++) {
|
||||
std::string value_string;
|
||||
@@ -371,35 +375,40 @@ std::string mvt_tile::encode() {
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
sorted_value sv;
|
||||
sv.val = std::move(value_string);
|
||||
sv.orig = v;
|
||||
std::shared_ptr<sorted_value> sv = std::make_shared<sorted_value>();
|
||||
sv->val = std::move(value_string);
|
||||
sv->orig = v;
|
||||
sorted_values.push_back(std::move(sv));
|
||||
}
|
||||
|
||||
std::stable_sort(sorted_values.begin(), sorted_values.end());
|
||||
std::stable_sort(sorted_values.begin(), sorted_values.end(), sorted_value());
|
||||
std::vector<size_t> mapping;
|
||||
mapping.resize(sorted_values.size());
|
||||
|
||||
size_t value_index = 0;
|
||||
for (size_t v = 0; v < sorted_values.size(); v++) {
|
||||
mapping[sorted_values[v].orig] = value_index;
|
||||
layer_writer.add_message(4, sorted_values[v].val);
|
||||
mapping[sorted_values[v]->orig] = value_index;
|
||||
layer_writer.add_message(4, sorted_values[v]->val);
|
||||
|
||||
// crunch out duplicates that were missed by the hashing
|
||||
while (v + 1 < sorted_values.size() && sorted_values[v].val == sorted_values[v + 1].val) {
|
||||
mapping[sorted_values[v + 1].orig] = value_index;
|
||||
while (v + 1 < sorted_values.size() && sorted_values[v]->val == sorted_values[v + 1]->val) {
|
||||
sorted_values[v]->val.clear();
|
||||
mapping[sorted_values[v + 1]->orig] = value_index;
|
||||
v++;
|
||||
}
|
||||
|
||||
sorted_values[v]->val.clear();
|
||||
value_index++;
|
||||
}
|
||||
|
||||
sorted_values.clear();
|
||||
|
||||
for (size_t f = 0; f < layers[i].features.size(); f++) {
|
||||
std::string feature_string;
|
||||
protozero::pbf_writer feature_writer(feature_string);
|
||||
|
||||
feature_writer.add_enum(3, layers[i].features[f].type);
|
||||
if (layers[i].features[f].type >= 0)
|
||||
feature_writer.add_enum(3, layers[i].features[f].type);
|
||||
|
||||
std::vector<unsigned> sorted_tags = layers[i].features[f].tags;
|
||||
for (size_t v = 1; v < sorted_tags.size(); v += 2) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "text.hpp"
|
||||
@@ -76,8 +77,12 @@ enum mvt_value_type {
|
||||
mvt_no_such_key,
|
||||
};
|
||||
|
||||
struct mvt_value;
|
||||
double mvt_value_to_double(mvt_value const &v);
|
||||
|
||||
struct mvt_value {
|
||||
mvt_value_type type;
|
||||
long /* mvt_value_type */ type : 5;
|
||||
long count : 64 - 5;
|
||||
std::shared_ptr<std::string> s;
|
||||
|
||||
union {
|
||||
@@ -88,14 +93,27 @@ 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;
|
||||
} string_value = {0, 0};
|
||||
} 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 {
|
||||
return std::string(*s, numeric_value.string_value.off, numeric_value.string_value.len);
|
||||
if (type == mvt_string) {
|
||||
return std::string(*s, numeric_value.string_value.off, numeric_value.string_value.len);
|
||||
} else {
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view get_string_view() const {
|
||||
@@ -126,6 +144,14 @@ struct mvt_value {
|
||||
type == mvt_sint;
|
||||
}
|
||||
|
||||
double to_double() const {
|
||||
return mvt_value_to_double(*this);
|
||||
}
|
||||
|
||||
size_t get_count() const {
|
||||
return count;
|
||||
}
|
||||
|
||||
bool operator<(const mvt_value &o) const;
|
||||
bool operator==(const mvt_value &o) const;
|
||||
std::string toString() const;
|
||||
@@ -133,6 +159,19 @@ struct mvt_value {
|
||||
mvt_value() {
|
||||
this->type = mvt_double;
|
||||
this->numeric_value.double_value = 0;
|
||||
this->count = 0;
|
||||
}
|
||||
|
||||
mvt_value(double v) {
|
||||
this->type = mvt_double;
|
||||
this->numeric_value.double_value = v;
|
||||
this->count = 0;
|
||||
}
|
||||
|
||||
void set_double_count(double v, size_t c) {
|
||||
this->type = mvt_double;
|
||||
this->numeric_value.double_value = v;
|
||||
this->count = c;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -185,6 +224,10 @@ struct mvt_layer {
|
||||
// For tracking the key-value constants already used in this layer
|
||||
std::vector<ssize_t> key_dedup = std::vector<ssize_t>(65536, -1);
|
||||
std::vector<ssize_t> value_dedup = std::vector<ssize_t>(65536, -1);
|
||||
|
||||
int detail() const {
|
||||
return std::round(std::log(extent) / std::log(2));
|
||||
}
|
||||
};
|
||||
|
||||
struct mvt_tile {
|
||||
@@ -201,7 +244,6 @@ int dezig(unsigned n);
|
||||
|
||||
mvt_value stringified_to_mvt_value(int type, const char *s, std::shared_ptr<std::string> const &tile_stringpool);
|
||||
long long mvt_value_to_long_long(mvt_value const &v);
|
||||
double mvt_value_to_double(mvt_value const &v);
|
||||
|
||||
bool is_integer(const char *s, long long *v);
|
||||
bool is_unsigned_integer(const char *s, unsigned long long *v);
|
||||
|
||||
+2
-1
@@ -12,7 +12,6 @@
|
||||
#define A_PREFER_RADIX_SORT ((int) 'R')
|
||||
#define A_COALESCE_DENSEST_AS_NEEDED ((int) 'S')
|
||||
#define A_CALCULATE_INDEX ((int) 'X')
|
||||
#define A_ACCUMULATE_NUMERIC ((int) 'a')
|
||||
#define A_DETECT_SHARED_BORDERS ((int) 'b')
|
||||
#define A_COALESCE ((int) 'c')
|
||||
#define A_DROP_FRACTION_AS_NEEDED ((int) 'd')
|
||||
@@ -29,6 +28,8 @@
|
||||
#define A_VARIABLE_DEPTH_PYRAMID ((int) 't')
|
||||
#define A_VISVALINGAM ((int) 'v')
|
||||
#define A_DETECT_WRAPAROUND ((int) 'w')
|
||||
#define A_KEEP_POINT_CLUSTER_POSITION ((int) 'a')
|
||||
#define A_DROP_BY_ATTRIBUTE_AS_NEEDED ((int) 'A')
|
||||
|
||||
#define P_TILE_COMPRESSION ((int) 'C')
|
||||
#define P_DUPLICATION ((int) 'D')
|
||||
|
||||
+130
-67
@@ -10,6 +10,8 @@
|
||||
#include "attribute.hpp"
|
||||
#include "text.hpp"
|
||||
#include "read_json.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "usage.hpp"
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
@@ -17,68 +19,122 @@ extern int optind;
|
||||
int detail = 12; // tippecanoe-style: mvt extent == 1 << detail
|
||||
int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256;
|
||||
bool demultiply = false;
|
||||
bool do_compress = true;
|
||||
bool deduplicate_by_id = false;
|
||||
|
||||
std::string filter;
|
||||
bool preserve_input_order = false;
|
||||
std::unordered_map<std::string, attribute_op> attribute_accum;
|
||||
std::vector<std::string> unidecode_data;
|
||||
std::vector<mvt_layer> bins;
|
||||
|
||||
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) {
|
||||
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");
|
||||
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");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string read_json_file(const char *fname) {
|
||||
std::string out;
|
||||
|
||||
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)) != 0) {
|
||||
out += std::string(buf, nread);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
const char *outtile = NULL;
|
||||
const char *outfile = NULL;
|
||||
double simplification = 0;
|
||||
double tiny_polygon_size = 0;
|
||||
std::string assign_to_bins;
|
||||
|
||||
std::vector<input_tile> sources;
|
||||
|
||||
struct option long_options[] = {
|
||||
{"include", required_argument, 0, 'y'},
|
||||
{"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'},
|
||||
{"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'},
|
||||
{"assign-to-bins", required_argument, 0, 'b' & 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(':');
|
||||
}
|
||||
}
|
||||
}
|
||||
strip_usage_headings(long_options, real_long_options);
|
||||
std::string getopt_str = getopt_string(real_long_options);
|
||||
|
||||
int option_index = 0;
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, &option_index)) != -1) {
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), real_long_options, &option_index)) != -1) {
|
||||
switch (i) {
|
||||
case 'y':
|
||||
keep.insert(optarg);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
exclude.insert(optarg);
|
||||
break;
|
||||
|
||||
case 'x' & 0x1F:
|
||||
exclude_prefix.push_back(optarg);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
outfile = optarg;
|
||||
break;
|
||||
@@ -99,6 +155,10 @@ int main(int argc, char **argv) {
|
||||
filter = optarg;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
filter = read_json_file(optarg);
|
||||
break;
|
||||
|
||||
case 'o' & 0x1F:
|
||||
preserve_input_order = true;
|
||||
break;
|
||||
@@ -123,10 +183,15 @@ int main(int argc, char **argv) {
|
||||
simplification = atof(optarg);
|
||||
break;
|
||||
|
||||
case 'b' & 0x1F:
|
||||
assign_to_bins = optarg;
|
||||
case 'd' & 0x1F:
|
||||
do_compress = false;
|
||||
break;
|
||||
|
||||
case 'i' & 0x1F: {
|
||||
deduplicate_by_id = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized flag -%c\n", i);
|
||||
usage(argv);
|
||||
@@ -136,6 +201,11 @@ int 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");
|
||||
@@ -190,45 +260,38 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (assign_to_bins.size() != 0) {
|
||||
FILE *f = fopen(assign_to_bins.c_str(), "r");
|
||||
if (f == NULL) {
|
||||
perror(assign_to_bins.c_str());
|
||||
exit(EXIT_OPEN);
|
||||
std::string out;
|
||||
|
||||
{
|
||||
json_object *json_filter = NULL;
|
||||
if (filter.size() > 0) {
|
||||
json_filter = parse_filter(filter.c_str());
|
||||
}
|
||||
|
||||
bins = parse_layers(f, nz, nx, ny, 1LL << detail, true);
|
||||
fclose(f);
|
||||
}
|
||||
for (auto const &s : sources) {
|
||||
std::string tile;
|
||||
char buf[1000];
|
||||
int len;
|
||||
|
||||
json_object *json_filter = NULL;
|
||||
if (filter.size() > 0) {
|
||||
json_filter = parse_filter(filter.c_str());
|
||||
}
|
||||
FILE *f = fopen(s.tile.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
perror(s.tile.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (auto const &s : sources) {
|
||||
std::string tile;
|
||||
char buf[1000];
|
||||
int len;
|
||||
while ((len = fread(buf, sizeof(char), 1000, f)) > 0) {
|
||||
tile.append(std::string(buf, len));
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
FILE *f = fopen(s.tile.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
perror(s.tile.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
input_tile t = s;
|
||||
t.tile = std::move(tile);
|
||||
its.push_back(std::move(t));
|
||||
}
|
||||
|
||||
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);
|
||||
its.push_back(std::move(t));
|
||||
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);
|
||||
}
|
||||
|
||||
std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins);
|
||||
|
||||
FILE *f = fopen(outfile, "wb");
|
||||
if (f == NULL) {
|
||||
perror(outfile);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "platform.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include "errors.hpp"
|
||||
|
||||
long get_num_avail_cpus() {
|
||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||
}
|
||||
|
||||
long get_page_size() {
|
||||
return sysconf(_SC_PAGESIZE);
|
||||
}
|
||||
|
||||
size_t calc_memsize() {
|
||||
size_t mem;
|
||||
|
||||
#ifdef __APPLE__
|
||||
int64_t hw_memsize;
|
||||
size_t len = sizeof(int64_t);
|
||||
if (sysctlbyname("hw.memsize", &hw_memsize, &len, NULL, 0) < 0) {
|
||||
perror("sysctl hw.memsize");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
mem = hw_memsize;
|
||||
#else
|
||||
long long pagesize = sysconf(_SC_PAGESIZE);
|
||||
long long pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pages < 0 || pagesize < 0) {
|
||||
perror("sysconf _SC_PAGESIZE or _SC_PHYS_PAGES");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
|
||||
mem = (long long) pages * pagesize;
|
||||
#endif
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
size_t get_max_open_files() {
|
||||
struct rlimit rl;
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
perror("getrlimit");
|
||||
exit(EXIT_PTHREAD);
|
||||
}
|
||||
return rl.rlim_cur;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef PLATFORM_HPP
|
||||
#define PLATFORM_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
long get_num_avail_cpus();
|
||||
|
||||
long get_page_size();
|
||||
|
||||
size_t calc_memsize();
|
||||
|
||||
size_t get_max_open_files();
|
||||
|
||||
constexpr const char *get_null_device() {
|
||||
return "/dev/null";
|
||||
}
|
||||
|
||||
#endif // PLATFORM_HPP
|
||||
+4
-4
@@ -55,7 +55,7 @@ void *run_writer(void *a) {
|
||||
|
||||
json_writer state(fp);
|
||||
for (size_t i = 0; i < wa->layers->size(); i++) {
|
||||
layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, true, state, 0);
|
||||
layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, true, state, 0, std::set<std::string>());
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
@@ -145,7 +145,7 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
|
||||
}
|
||||
|
||||
// Reads from the prefilter
|
||||
serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, bool postfilter) {
|
||||
serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, bool postfilter, key_pool &key_pool) {
|
||||
serial_feature sf;
|
||||
|
||||
while (1) {
|
||||
@@ -223,7 +223,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
parse_coordinates(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv, false, false);
|
||||
}
|
||||
@@ -354,7 +354,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
|
||||
// would have already run before prefiltering
|
||||
|
||||
if (v.type != mvt_null) {
|
||||
sf.full_keys.push_back(std::string(properties->value.object.keys[i]->value.string.string));
|
||||
sf.full_keys.push_back(key_pool.pool(std::string(properties->value.object.keys[i]->value.string.string)));
|
||||
sf.full_values.push_back(v);
|
||||
|
||||
if (!postfilter) {
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
struct key_pool;
|
||||
std::vector<mvt_layer> filter_layers(const char *filter, std::vector<mvt_layer> &layer, unsigned z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, int extent);
|
||||
void setup_filter(const char *filter, int *write_to, int *read_from, pid_t *pid, unsigned z, unsigned x, unsigned y);
|
||||
serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, bool filters);
|
||||
serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::vector<std::map<std::string, layermap_entry>> *layermaps, size_t tiling_seg, std::vector<std::vector<std::string>> *layer_unmaps, bool filters, key_pool &key_pool);
|
||||
|
||||
+134
-121
@@ -53,7 +53,7 @@ void json_context(json_object *j) {
|
||||
free(s); // stringify
|
||||
}
|
||||
|
||||
void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature) {
|
||||
void parse_coordinates(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature) {
|
||||
if (j == NULL || j->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "%s:%d: expected array for geometry type %d: ", fname, line, t);
|
||||
json_context(feature);
|
||||
@@ -72,7 +72,7 @@ void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fna
|
||||
}
|
||||
}
|
||||
|
||||
parse_geometry(within, j->value.array.array[i], out, op, fname, line, feature);
|
||||
parse_coordinates(within, j->value.array.array[i], out, op, fname, line, feature);
|
||||
}
|
||||
} else {
|
||||
if (j->value.array.length >= 2 && j->value.array.array[0]->type == JSON_NUMBER && j->value.array.array[1]->type == JSON_NUMBER) {
|
||||
@@ -178,6 +178,129 @@ static std::vector<mvt_geometry> to_feature(drawvec &geom) {
|
||||
return out;
|
||||
}
|
||||
|
||||
std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, json_object *j,
|
||||
int z, int x, int y, long long extent, bool fix_longitudes, bool mvt_style) {
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: null geometry (additional not reported): ", jp->line);
|
||||
json_context(j);
|
||||
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);
|
||||
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);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
int t;
|
||||
for (t = 0; t < GEOM_TYPES; t++) {
|
||||
if (strcmp(geometry_type->value.string.string, geometry_names[t]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
parse_coordinates(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
|
||||
// handle longitude wraparound
|
||||
//
|
||||
// this is supposed to be data for a single tile,
|
||||
// so any jump from the left hand side edge of the world
|
||||
// to the right edge, or vice versa, is unexpected,
|
||||
// so move it to the other side.
|
||||
|
||||
if (fix_longitudes && mb_geometry[t] == VT_POLYGON) {
|
||||
const long long quarter_world = 1LL << 30;
|
||||
const long long world = 1LL << 32;
|
||||
|
||||
bool copy_to_left = false;
|
||||
bool copy_to_right = false;
|
||||
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
// is this vertex on a different side of the world
|
||||
// than the first vertex? then shift this one to match
|
||||
if (i > 0) {
|
||||
if ((dv[0].x < quarter_world) && (dv[i].x > 3 * quarter_world)) {
|
||||
dv[i].x -= world;
|
||||
}
|
||||
if ((dv[0].x > 3 * quarter_world) && (dv[i].x < quarter_world)) {
|
||||
dv[i].x += world;
|
||||
}
|
||||
}
|
||||
|
||||
// does it stick off the edge of the world?
|
||||
// then we need another copy on the other side of the world
|
||||
if (dv[i].x < 0) {
|
||||
copy_to_right = true;
|
||||
}
|
||||
if (dv[i].x > world) {
|
||||
copy_to_left = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (copy_to_left) {
|
||||
size_t n = dv.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dv.emplace_back(dv[i].op, dv[i].x - world, (long long) dv[i].y);
|
||||
}
|
||||
}
|
||||
if (copy_to_right) {
|
||||
size_t n = dv.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dv.emplace_back(dv[i].op, dv[i].x + world, (long long) dv[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv, false, false);
|
||||
}
|
||||
|
||||
// Offset and scale geometry from global to tile
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
long long scale = 1LL << (32 - z);
|
||||
|
||||
// offset to tile
|
||||
dv[i].x -= scale * x;
|
||||
dv[i].y -= scale * y;
|
||||
|
||||
// scale to tile
|
||||
dv[i].x = std::round(dv[i].x * (extent / (double) scale));
|
||||
dv[i].y = std::round(dv[i].y * (extent / (double) scale));
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
// don't try scaling up because we may have coordinates
|
||||
// on the other side of the world
|
||||
dv = clean_or_clip_poly(dv, z, 256, true, false);
|
||||
if (dv.size() < 3) {
|
||||
dv.clear();
|
||||
}
|
||||
}
|
||||
dv = remove_noop(dv, mb_geometry[t], 0);
|
||||
|
||||
if (mvt_style) {
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = close_poly(dv);
|
||||
}
|
||||
}
|
||||
|
||||
return std::pair<int, drawvec>(t, dv);
|
||||
}
|
||||
|
||||
std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int extent, bool fix_longitudes) {
|
||||
std::map<std::string, mvt_layer> ret;
|
||||
std::shared_ptr<std::string> tile_stringpool = std::make_shared<std::string>();
|
||||
@@ -208,14 +331,6 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: filtered feature with no geometry: ", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
if (properties == NULL || (properties->type != JSON_HASH && properties->type != JSON_NULL)) {
|
||||
fprintf(stderr, "Filter output:%d: feature without properties hash: ", jp->line);
|
||||
@@ -224,38 +339,6 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: null geometry (additional not reported): ", jp->line);
|
||||
json_context(j);
|
||||
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);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "Filter output:%d: feature without coordinates array: ", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
int t;
|
||||
for (t = 0; t < GEOM_TYPES; t++) {
|
||||
if (strcmp(geometry_type->value.string.string, geometry_names[t]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
std::string layername = "unknown";
|
||||
json_object *tippecanoe = json_hash_get(j, "tippecanoe");
|
||||
json_object *layer = NULL;
|
||||
@@ -276,88 +359,18 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
|
||||
}
|
||||
auto l = ret.find(layername);
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
|
||||
// handle longitude wraparound
|
||||
//
|
||||
// this is supposed to be data for a single tile,
|
||||
// so any jump from the left hand side edge of the world
|
||||
// to the right edge, or vice versa, is unexpected,
|
||||
// so move it to the other side.
|
||||
|
||||
if (fix_longitudes && mb_geometry[t] == VT_POLYGON) {
|
||||
const long long quarter_world = 1LL << 30;
|
||||
const long long world = 1LL << 32;
|
||||
|
||||
bool copy_to_left = false;
|
||||
bool copy_to_right = false;
|
||||
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
// is this vertex on a different side of the world
|
||||
// than the first vertex? then shift this one to match
|
||||
if (i > 0) {
|
||||
if ((dv[0].x < quarter_world) && (dv[i].x > 3 * quarter_world)) {
|
||||
dv[i].x -= world;
|
||||
}
|
||||
if ((dv[0].x > 3 * quarter_world) && (dv[i].x < quarter_world)) {
|
||||
dv[i].x += world;
|
||||
}
|
||||
}
|
||||
|
||||
// does it stick off the edge of the world?
|
||||
// then we need another copy on the other side of the world
|
||||
if (dv[i].x < 0) {
|
||||
copy_to_right = true;
|
||||
}
|
||||
if (dv[i].x > world) {
|
||||
copy_to_left = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (copy_to_left) {
|
||||
size_t n = dv.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dv.emplace_back(dv[i].op, dv[i].x - world, (long long) dv[i].y);
|
||||
}
|
||||
}
|
||||
if (copy_to_right) {
|
||||
size_t n = dv.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
dv.emplace_back(dv[i].op, dv[i].x + world, (long long) dv[i].y);
|
||||
}
|
||||
}
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: filtered feature with no geometry: ", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv, false, false);
|
||||
}
|
||||
std::pair<int, drawvec> parsed_geometry = parse_geometry(geometry, jp, j, z, x, y, extent, fix_longitudes, true);
|
||||
|
||||
// Offset and scale geometry from global to tile
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
long long scale = 1LL << (32 - z);
|
||||
|
||||
// offset to tile
|
||||
dv[i].x -= scale * x;
|
||||
dv[i].y -= scale * y;
|
||||
|
||||
// scale to tile
|
||||
dv[i].x = std::round(dv[i].x * extent / (double) scale);
|
||||
dv[i].y = std::round(dv[i].y * extent / (double) scale);
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
// don't try scaling up because we may have coordinates
|
||||
// on the other side of the world
|
||||
dv = clean_or_clip_poly(dv, z, 256, true, false);
|
||||
if (dv.size() < 3) {
|
||||
dv.clear();
|
||||
}
|
||||
}
|
||||
dv = remove_noop(dv, mb_geometry[t], 0);
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = close_poly(dv);
|
||||
}
|
||||
int t = parsed_geometry.first;
|
||||
drawvec &dv = parsed_geometry.second;
|
||||
|
||||
if (dv.size() > 0) {
|
||||
mvt_feature feature;
|
||||
|
||||
+3
-1
@@ -11,7 +11,9 @@ extern int geometry_within[GEOM_TYPES];
|
||||
extern int mb_geometry[GEOM_TYPES];
|
||||
|
||||
void json_context(json_object *j);
|
||||
void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature);
|
||||
void parse_coordinates(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature);
|
||||
std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, json_object *j,
|
||||
int z, int x, int y, long long extent, bool fix_longitudes, bool mvt_style);
|
||||
std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int extent, bool fix_longitudes);
|
||||
|
||||
serial_val stringify_value(json_object *value, const char *reading, int line, json_object *feature);
|
||||
|
||||
+22
-12
@@ -415,6 +415,7 @@ static void add_scaled_node(struct reader *r, serialization_state *sst, draw g)
|
||||
// called from frontends
|
||||
int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::string const &layername) {
|
||||
struct reader *r = &(*sst->readers)[sst->segment];
|
||||
key_pool key_pool;
|
||||
|
||||
sf.bbox[0] = LLONG_MAX;
|
||||
sf.bbox[1] = LLONG_MAX;
|
||||
@@ -664,10 +665,18 @@ 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.
|
||||
}
|
||||
|
||||
if (extent <= LLONG_MAX) {
|
||||
// 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) {
|
||||
sf.extent = (long long) extent;
|
||||
} else if (extent < 0) {
|
||||
sf.extent = LLONG_MIN;
|
||||
} else {
|
||||
sf.extent = LLONG_MAX;
|
||||
sf.extent = LLONG_MAX; // also the NaN case
|
||||
}
|
||||
|
||||
if (sst->want_dist && sf.t == VT_POLYGON) {
|
||||
@@ -714,7 +723,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
|
||||
bbox_index = encode_index(midx, midy);
|
||||
if (additional[A_CALCULATE_INDEX]) {
|
||||
sf.full_keys.push_back("tippecanoe:index");
|
||||
sf.full_keys.push_back(key_pool.pool("tippecanoe:index"));
|
||||
|
||||
serial_val sv;
|
||||
sv.type = mvt_double;
|
||||
@@ -744,6 +753,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
additional[A_GENERATE_POLYGON_LABEL_POINTS] ||
|
||||
sst->uses_gamma ||
|
||||
retain_points_multiplier > 1 ||
|
||||
preserve_multiplier_density_threshold > 0 ||
|
||||
cluster_distance != 0) {
|
||||
sf.index = bbox_index;
|
||||
} else {
|
||||
@@ -775,7 +785,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
for (auto &kv : set_attributes) {
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < sf.full_keys.size(); i++) {
|
||||
if (sf.full_keys[i] == kv.first) {
|
||||
if (*sf.full_keys[i] == kv.first) {
|
||||
sf.full_values[i] = kv.second;
|
||||
found = true;
|
||||
break;
|
||||
@@ -783,13 +793,13 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
sf.full_keys.push_back(kv.first);
|
||||
sf.full_keys.push_back(key_pool.pool(kv.first));
|
||||
sf.full_values.push_back(kv.second);
|
||||
}
|
||||
}
|
||||
|
||||
for (ssize_t i = (ssize_t) sf.full_keys.size() - 1; i >= 0; i--) {
|
||||
coerce_value(sf.full_keys[i], sf.full_values[i].type, sf.full_values[i].s, sst->attribute_types);
|
||||
coerce_value(*sf.full_keys[i], sf.full_values[i].type, sf.full_values[i].s, sst->attribute_types);
|
||||
|
||||
if (prevent[P_SINGLE_PRECISION]) {
|
||||
if (sf.full_values[i].type == mvt_double) {
|
||||
@@ -800,12 +810,12 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
}
|
||||
}
|
||||
|
||||
if (sf.full_keys[i] == attribute_for_id) {
|
||||
if (*sf.full_keys[i] == attribute_for_id) {
|
||||
if (sf.full_values[i].type != mvt_double && !additional[A_CONVERT_NUMERIC_IDS]) {
|
||||
static bool warned = false;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: Attribute \"%s\"=\"%s\" as feature ID is not a number\n", sf.full_keys[i].c_str(), sf.full_values[i].s.c_str());
|
||||
fprintf(stderr, "Warning: Attribute \"%s\"=\"%s\" as feature ID is not a number\n", sf.full_keys[i]->c_str(), sf.full_values[i].s.c_str());
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
@@ -838,12 +848,12 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
}
|
||||
|
||||
if (sst->exclude_all) {
|
||||
if (sst->include->count(sf.full_keys[i]) == 0) {
|
||||
if (sst->include->count(*sf.full_keys[i]) == 0) {
|
||||
sf.full_keys.erase(sf.full_keys.begin() + i);
|
||||
sf.full_values.erase(sf.full_values.begin() + i);
|
||||
continue;
|
||||
}
|
||||
} else if (sst->exclude->count(sf.full_keys[i]) != 0) {
|
||||
} else if (sst->exclude->count(*sf.full_keys[i]) != 0) {
|
||||
sf.full_keys.erase(sf.full_keys.begin() + i);
|
||||
sf.full_values.erase(sf.full_values.begin() + i);
|
||||
continue;
|
||||
@@ -853,7 +863,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
if (!sst->filters) {
|
||||
for (size_t i = 0; i < sf.full_keys.size(); i++) {
|
||||
auto ts = sst->layermap->find(layername);
|
||||
add_to_tilestats(ts->second.tilestats, sf.full_keys[i], sf.full_values[i]);
|
||||
add_to_tilestats(ts->second.tilestats, *sf.full_keys[i], sf.full_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -866,7 +876,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sf.full_keys.size(); i++) {
|
||||
sf.keys.push_back(addpool(r->poolfile, r->treefile, sf.full_keys[i].c_str(), mvt_string, r->key_dedup));
|
||||
sf.keys.push_back(addpool(r->poolfile, r->treefile, sf.full_keys[i]->c_str(), mvt_string, r->key_dedup));
|
||||
sf.values.push_back(addpool(r->poolfile, r->treefile, sf.full_values[i].s.c_str(), sf.full_values[i].type, r->value_dedup));
|
||||
}
|
||||
|
||||
|
||||
+54
-3
@@ -6,6 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <sys/stat.h>
|
||||
#include "geometry.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
@@ -49,6 +50,56 @@ struct serial_val {
|
||||
serial_val(int t, const std::string &val)
|
||||
: type(t), s(val) {
|
||||
}
|
||||
|
||||
// These functions for interface compatibility with mvt_value:
|
||||
|
||||
serial_val(double val) {
|
||||
type = mvt_double;
|
||||
s = milo::dtoa_milo(val);
|
||||
}
|
||||
|
||||
double to_double() const {
|
||||
return atof(s.c_str());
|
||||
}
|
||||
|
||||
std::string get_string_value() const {
|
||||
return s;
|
||||
}
|
||||
|
||||
void set_string_value(std::string const &val) {
|
||||
type = mvt_string;
|
||||
s = val;
|
||||
}
|
||||
|
||||
size_t get_count() const {
|
||||
size_t found = s.find('\0');
|
||||
if (found == std::string::npos) {
|
||||
return 0;
|
||||
} else {
|
||||
return atoll(s.c_str() + found + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void set_double_count(double v, size_t c) {
|
||||
type = mvt_double;
|
||||
s = milo::dtoa_milo(v) + '\0' + std::to_string(c);
|
||||
}
|
||||
};
|
||||
|
||||
struct key_pool {
|
||||
std::unordered_map<std::string, std::shared_ptr<std::string>> mapping;
|
||||
|
||||
std::shared_ptr<std::string> pool(std::string const &s) {
|
||||
auto f = mapping.find(s);
|
||||
if (f != mapping.end()) {
|
||||
return f->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::string> p = std::make_shared<std::string>();
|
||||
*p = s;
|
||||
mapping.emplace(s, p);
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
struct serial_feature {
|
||||
@@ -75,7 +126,7 @@ struct serial_feature {
|
||||
// to create the keys and values references into the string pool
|
||||
// during initial serialization
|
||||
|
||||
std::vector<std::string> full_keys{};
|
||||
std::vector<std::shared_ptr<std::string>> full_keys{};
|
||||
std::vector<serial_val> full_values{};
|
||||
|
||||
// These fields are generated from full_keys and full_values
|
||||
@@ -94,9 +145,11 @@ struct serial_feature {
|
||||
|
||||
#define FEATURE_DROPPED -1
|
||||
#define FEATURE_KEPT 0
|
||||
#define FEATURE_ADDED_FOR_MULTIPLIER_DENSITY INT_MAX
|
||||
// <0: dropped
|
||||
// 0: kept
|
||||
// >0: sequence number of additional feature kept by retain-points-multiplier
|
||||
// INT_MAX: additional feature kept by preserve-multiplier-density-threshold
|
||||
int dropped = FEATURE_DROPPED; // was this feature dropped by rate?
|
||||
|
||||
// unsigned long long drop_by; // dot-dropping priority
|
||||
@@ -112,8 +165,6 @@ struct serial_feature {
|
||||
long long clustered; // does this feature need the clustered/point_count attributes?
|
||||
const char *stringpool; // string pool for keys/values lookup
|
||||
std::shared_ptr<std::string> tile_stringpool; // string pool for mvt_value construction
|
||||
std::set<std::string> need_tilestats;
|
||||
std::unordered_map<std::string, accum_state> attribute_accum_state;
|
||||
|
||||
int z; // tile being produced
|
||||
int tx;
|
||||
|
||||
+47
-47
@@ -83,13 +83,13 @@ bool edges_same(std::pair<std::vector<edge>::iterator, std::vector<edge>::iterat
|
||||
return true;
|
||||
}
|
||||
|
||||
bool find_common_edges(std::vector<serial_feature> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction) {
|
||||
bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction) {
|
||||
size_t merge_count = ceil((1 - merge_fraction) * features.size());
|
||||
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
if (features[i].t == VT_POLYGON) {
|
||||
if (features[i]->t == VT_POLYGON) {
|
||||
{
|
||||
drawvec &g = features[i].geometry;
|
||||
drawvec &g = features[i]->geometry;
|
||||
drawvec out;
|
||||
|
||||
for (size_t k = 0; k < g.size(); k++) {
|
||||
@@ -100,7 +100,7 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
}
|
||||
}
|
||||
|
||||
features[i].geometry = out;
|
||||
features[i]->geometry = out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,21 +112,21 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
std::vector<edge> edges;
|
||||
size_t ring = 0;
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
if (features[i].t == VT_POLYGON) {
|
||||
if (features[i]->t == VT_POLYGON) {
|
||||
{
|
||||
for (size_t k = 0; k + 1 < features[i].geometry.size(); k++) {
|
||||
if (features[i].geometry[k].op == VT_MOVETO) {
|
||||
for (size_t k = 0; k + 1 < features[i]->geometry.size(); k++) {
|
||||
if (features[i]->geometry[k].op == VT_MOVETO) {
|
||||
ring++;
|
||||
}
|
||||
|
||||
if (features[i].geometry[k + 1].op == VT_LINETO) {
|
||||
if (features[i]->geometry[k + 1].op == VT_LINETO) {
|
||||
drawvec dv;
|
||||
if (features[i].geometry[k] < features[i].geometry[k + 1]) {
|
||||
dv.push_back(features[i].geometry[k]);
|
||||
dv.push_back(features[i].geometry[k + 1]);
|
||||
if (features[i]->geometry[k] < features[i]->geometry[k + 1]) {
|
||||
dv.push_back(features[i]->geometry[k]);
|
||||
dv.push_back(features[i]->geometry[k + 1]);
|
||||
} else {
|
||||
dv.push_back(features[i].geometry[k + 1]);
|
||||
dv.push_back(features[i].geometry[k]);
|
||||
dv.push_back(features[i]->geometry[k + 1]);
|
||||
dv.push_back(features[i]->geometry[k]);
|
||||
}
|
||||
|
||||
edges.push_back(edge(dv[0].x, dv[0].y, dv[1].x, dv[1].y, ring));
|
||||
@@ -143,9 +143,9 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
// is not the same as the set of rings using the edge on the other side.
|
||||
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
if (features[i].t == VT_POLYGON) {
|
||||
if (features[i]->t == VT_POLYGON) {
|
||||
{
|
||||
drawvec &g = features[i].geometry;
|
||||
drawvec &g = features[i]->geometry;
|
||||
|
||||
for (size_t k = 0; k < g.size(); k++) {
|
||||
g[k].necessary = 0;
|
||||
@@ -223,9 +223,9 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
// Roll rings that include a necessary point around so they start at one
|
||||
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
if (features[i].t == VT_POLYGON) {
|
||||
if (features[i]->t == VT_POLYGON) {
|
||||
{
|
||||
drawvec &g = features[i].geometry;
|
||||
drawvec &g = features[i]->geometry;
|
||||
|
||||
for (size_t k = 0; k < g.size(); k++) {
|
||||
if (necessaries.count(g[k]) != 0) {
|
||||
@@ -315,21 +315,21 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
// Add new arc
|
||||
size_t added = arcs.size() + 1;
|
||||
arcs.insert(std::pair<drawvec, size_t>(arc, added));
|
||||
features[i].arc_polygon.push_back(added);
|
||||
features[i]->arc_polygon.push_back(added);
|
||||
merge_candidates.insert(std::pair<ssize_t, size_t>(added, i));
|
||||
} else {
|
||||
features[i].arc_polygon.push_back(-(ssize_t) f2->second);
|
||||
features[i]->arc_polygon.push_back(-(ssize_t) f2->second);
|
||||
merge_candidates.insert(std::pair<ssize_t, size_t>(-(ssize_t) f2->second, i));
|
||||
}
|
||||
} else {
|
||||
features[i].arc_polygon.push_back(f->second);
|
||||
features[i]->arc_polygon.push_back(f->second);
|
||||
merge_candidates.insert(std::pair<ssize_t, size_t>(f->second, i));
|
||||
}
|
||||
|
||||
m = n - 1;
|
||||
}
|
||||
|
||||
features[i].arc_polygon.push_back(0);
|
||||
features[i]->arc_polygon.push_back(0);
|
||||
|
||||
k = l - 1;
|
||||
}
|
||||
@@ -385,10 +385,10 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
if (r1i->second != r2i->second) {
|
||||
merge_order mo;
|
||||
mo.edge = i;
|
||||
if (features[r1i->second].index > features[r2i->second].index) {
|
||||
mo.gap = features[r1i->second].index - features[r2i->second].index;
|
||||
if (features[r1i->second]->index > features[r2i->second]->index) {
|
||||
mo.gap = features[r1i->second]->index - features[r2i->second]->index;
|
||||
} else {
|
||||
mo.gap = features[r2i->second].index - features[r1i->second].index;
|
||||
mo.gap = features[r2i->second]->index - features[r1i->second]->index;
|
||||
}
|
||||
mo.p1 = r1i->second;
|
||||
mo.p2 = r2i->second;
|
||||
@@ -406,19 +406,19 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
}
|
||||
|
||||
size_t i = order[o].p1;
|
||||
while (features[i].renamed >= 0) {
|
||||
i = features[i].renamed;
|
||||
while (features[i]->renamed >= 0) {
|
||||
i = features[i]->renamed;
|
||||
}
|
||||
size_t i2 = order[o].p2;
|
||||
while (features[i2].renamed >= 0) {
|
||||
i2 = features[i2].renamed;
|
||||
while (features[i2]->renamed >= 0) {
|
||||
i2 = features[i2]->renamed;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < features[i].arc_polygon.size() && merged < merge_count; j++) {
|
||||
if (features[i].arc_polygon[j] == order[o].edge) {
|
||||
for (size_t j = 0; j < features[i]->arc_polygon.size() && merged < merge_count; j++) {
|
||||
if (features[i]->arc_polygon[j] == order[o].edge) {
|
||||
{
|
||||
// XXX snap links
|
||||
if (features[order[o].p2].arc_polygon.size() > 0) {
|
||||
if (features[order[o].p2]->arc_polygon.size() > 0) {
|
||||
// This has to merge the ring that contains the anti-arc to this arc
|
||||
// into the current ring, and then add whatever other rings were in
|
||||
// that feature on to the end.
|
||||
@@ -427,11 +427,11 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
// the rings in order, but Wagyu should sort that out later
|
||||
|
||||
std::vector<ssize_t> additions;
|
||||
std::vector<ssize_t> &here = features[i].arc_polygon;
|
||||
std::vector<ssize_t> &other = features[i2].arc_polygon;
|
||||
std::vector<ssize_t> &here = features[i]->arc_polygon;
|
||||
std::vector<ssize_t> &other = features[i2]->arc_polygon;
|
||||
|
||||
#if 0
|
||||
printf("seeking %zd\n", features[i].arc_polygon[j]);
|
||||
printf("seeking %zd\n", features[i]->arc_polygon[j]);
|
||||
printf("before: ");
|
||||
for (size_t k = 0; k < here.size(); k++) {
|
||||
printf("%zd ", here[k]);
|
||||
@@ -464,7 +464,7 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
|
||||
size_t m;
|
||||
for (m = k; m <= l; m++) {
|
||||
if (other[m] == -features[i].arc_polygon[j]) {
|
||||
if (other[m] == -features[i]->arc_polygon[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -494,12 +494,12 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
k = l;
|
||||
}
|
||||
|
||||
features[i2].arc_polygon.clear();
|
||||
features[i2].renamed = i;
|
||||
features[i2]->arc_polygon.clear();
|
||||
features[i2]->renamed = i;
|
||||
merged++;
|
||||
|
||||
for (size_t k = 0; k < additions.size(); k++) {
|
||||
features[i].arc_polygon.push_back(additions[k]);
|
||||
features[i]->arc_polygon.push_back(additions[k]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -528,37 +528,37 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
|
||||
// Turn the arc representations of the polygons back into standard polygon geometries
|
||||
|
||||
for (size_t i = 0; i < features.size(); i++) {
|
||||
if (features[i].t == VT_POLYGON) {
|
||||
features[i].geometry.clear();
|
||||
if (features[i]->t == VT_POLYGON) {
|
||||
features[i]->geometry.clear();
|
||||
bool at_start = true;
|
||||
draw first(-1, 0, 0);
|
||||
|
||||
for (size_t j = 0; j < features[i].arc_polygon.size(); j++) {
|
||||
ssize_t p = features[i].arc_polygon[j];
|
||||
for (size_t j = 0; j < features[i]->arc_polygon.size(); j++) {
|
||||
ssize_t p = features[i]->arc_polygon[j];
|
||||
|
||||
if (p == 0) {
|
||||
if (first.op >= 0) {
|
||||
features[i].geometry.push_back(first);
|
||||
features[i]->geometry.push_back(first);
|
||||
first = draw(-1, 0, 0);
|
||||
}
|
||||
at_start = true;
|
||||
} else if (p > 0) {
|
||||
for (size_t k = 0; k + 1 < simplified_arcs[p].size(); k++) {
|
||||
if (at_start) {
|
||||
features[i].geometry.push_back(draw(VT_MOVETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
|
||||
features[i]->geometry.push_back(draw(VT_MOVETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
|
||||
first = draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y);
|
||||
} else {
|
||||
features[i].geometry.push_back(draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
|
||||
features[i]->geometry.push_back(draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
|
||||
}
|
||||
at_start = 0;
|
||||
}
|
||||
} else { /* p < 0 */
|
||||
for (ssize_t k = simplified_arcs[-p].size() - 1; k > 0; k--) {
|
||||
if (at_start) {
|
||||
features[i].geometry.push_back(draw(VT_MOVETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
|
||||
features[i]->geometry.push_back(draw(VT_MOVETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
|
||||
first = draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y);
|
||||
} else {
|
||||
features[i].geometry.push_back(draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
|
||||
features[i]->geometry.push_back(draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
|
||||
}
|
||||
at_start = 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
bool find_common_edges(std::vector<serial_feature> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction);
|
||||
bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define MAX_MEMORY (1024 * 1024 * 1024) // 1 GB
|
||||
|
||||
void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *, const void *), FILE *out, size_t mem) {
|
||||
void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *, const void *), FILE *out, size_t mem, const char *tmpdir) {
|
||||
std::string pivot;
|
||||
FILE *fp1, *fp2;
|
||||
|
||||
@@ -67,8 +67,8 @@ void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *,
|
||||
size_t pivot_off = width * (buf.size() / width / 2);
|
||||
pivot = std::string(buf, pivot_off, width);
|
||||
|
||||
std::string t1 = "/tmp/sort1.XXXXXX";
|
||||
std::string t2 = "/tmp/sort2.XXXXXX";
|
||||
std::string t1 = std::string(tmpdir) + "/sort1.XXXXXX";
|
||||
std::string t2 = std::string(tmpdir) + "/sort2.XXXXXX";
|
||||
|
||||
int fd1 = mkstemp((char *) t1.c_str());
|
||||
unlink(t1.c_str());
|
||||
@@ -117,11 +117,11 @@ void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *,
|
||||
|
||||
std::vector<FILE *> v1;
|
||||
v1.emplace_back(fp1);
|
||||
fqsort(v1, width, cmp, out, mem);
|
||||
fqsort(v1, width, cmp, out, mem, tmpdir);
|
||||
fclose(fp1);
|
||||
|
||||
std::vector<FILE *> v2;
|
||||
v2.emplace_back(fp2);
|
||||
fqsort(v2, width, cmp, out, mem);
|
||||
fqsort(v2, width, cmp, out, mem, tmpdir);
|
||||
fclose(fp2);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef SORT_HPP
|
||||
#define SORT_HPP
|
||||
|
||||
void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *, const void *), FILE *out, size_t mem);
|
||||
void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *, const void *), FILE *out, size_t mem, const char *tmpdir);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,565 @@
|
||||
ޢx
|
||||
parsed(�
felt:h3_index SCALERANKNATSCALE LABELRANK
|
||||
FEATURECLANAME NAMEASCIIADM0CAP WORLDCITYMEGACITYSOV0NAMESOV_A3ADM0NAMEADM0_A3ADM1NAMEISO_A2LATITUDE LONGITUDEPOP_MAXPOP_MIN POP_OTHERRANK_MAXRANK_MINLS_NAME MAX_POP10 MAX_POP20 MAX_POP50
|
||||
MAX_POP300
|
||||
MAX_POP310
|
||||
MAX_NATSCA
|
||||
MIN_AREAKM
|
||||
MAX_AREAKM
|
||||
MIN_AREAMI
|
||||
MAX_AREAMI MIN_PERKM MAX_PERKM MIN_PERMI MAX_PERMI
|
||||
MIN_BBXMIN
|
||||
MAX_BBXMIN
|
||||
MIN_BBXMAX
|
||||
MAX_BBXMAX
|
||||
MIN_BBYMIN
|
||||
MAX_BBYMIN
|
||||
MIN_BBYMAX
|
||||
MAX_BBYMAX MEAN_BBXC MEAN_BBYCUN_FIDPOP1950POP1955POP1960POP1965POP1970POP1975POP1980POP1985POP1990POP1995POP2000POP2005POP2010POP2015POP2020POP2025POP2050MIN_ZOOM
|
||||
WIKIDATAIDWOF_IDCAPALTNAME_ENNAME_DENAME_ESNAME_FRNAME_PTNAME_RUNAME_ZHNAME_ARNAME_BNNAME_ELNAME_HINAME_HUNAME_IDNAME_ITNAME_JANAME_KONAME_NLNAME_PLNAME_SVNAME_TRNAME_VINE_IDNAME_FANAME_HENAME_UKNAME_URNAME_ZHT
|
||||
GEONAMESIDfelt:cluster_size,tippecanoe:retain_points_multiplier_sequence)tippecanoe:retain_points_multiplier_firstPOP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990NAMEALTPOP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINTIMEZONEPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990POP_MINPOP1990NAMEPARPOP_MINPOP1990POP_MINPOP1990POP_MINPOP1990"
|
||||
CA"
|
||||
RU"
|
||||
US"
|
||||
CAN"
|
||||
RUS"
|
||||
USA"
|
||||
Kobuk"
|
||||
Alaska"
|
||||
Ambler"
|
||||
Barrow"
|
||||
Canada"
|
||||
Holman"
|
||||
Inuvik"
|
||||
Q79333"
|
||||
Q79350"
|
||||
Q79395"
|
||||
Q79408"
|
||||
Q79714"
|
||||
Q79717"
|
||||
Q79809"
|
||||
Q79810"
|
||||
Q79813"
|
||||
Q80033"
|
||||
Q80133"
|
||||
Russia"
|
||||
巴罗"
|
||||
巴羅"
|
||||
배로"
|
||||
코북"
|
||||
홀만"
|
||||
Atqasuk"
|
||||
Nunavut"
|
||||
Q338686"
|
||||
Q465235"
|
||||
Q602422"
|
||||
Q606622"
|
||||
Q718822"
|
||||
Q719547"
|
||||
Q719585"
|
||||
Q719605"
|
||||
Q719611"
|
||||
Q719707"
|
||||
Q924763"
|
||||
Selawik"
|
||||
Wiseman"
|
||||
İnuvik"
|
||||
|
||||
Enurmino"
|
||||
|
||||
Kaktovik"
|
||||
|
||||
Kivalina"
|
||||
|
||||
Kotzebue"
|
||||
|
||||
Paulatuk"
|
||||
|
||||
Q1013046"
|
||||
|
||||
Q1014088"
|
||||
|
||||
Q1014119"
|
||||
|
||||
Q1020259"
|
||||
|
||||
Q1938137"
|
||||
|
||||
Q2305684"
|
||||
|
||||
Resolute"
|
||||
|
||||
Taloyoak"
|
||||
|
||||
Zvezdnyi"
|
||||
|
||||
Zvezdnyj"
|
||||
|
||||
Zvezdnyy"
|
||||
|
||||
Zvjozdny"
|
||||
|
||||
בארו"
|
||||
|
||||
بارو"
|
||||
|
||||
بیرو"
|
||||
|
||||
کوبک"
|
||||
Allakaket"
|
||||
Enoermino"
|
||||
Enourmino"
|
||||
Kugluktuk"
|
||||
Utqiagvik"
|
||||
Zvëzdnyj"
|
||||
コブク"
|
||||
バロー"
|
||||
剑桥湾"
|
||||
劍橋灣"
|
||||
安布勒"
|
||||
懷斯曼"
|
||||
温赖特"
|
||||
科伯克"
|
||||
科策布"
|
||||
約阿港"
|
||||
育空堡"
|
||||
셀라윅"
|
||||
앰블러"
|
||||
앳쿼석"
|
||||
이누빅"
|
||||
코체부"
|
||||
|
||||
Fort Yukon"
|
||||
|
||||
Gjoa Haven"
|
||||
|
||||
Point Hope"
|
||||
|
||||
Ulukhaktok"
|
||||
|
||||
Utqiaġvik"
|
||||
|
||||
Wainwright"
|
||||
|
||||
Кобук"
|
||||
|
||||
אלקקט"
|
||||
|
||||
אמבלר"
|
||||
|
||||
חולמן"
|
||||
|
||||
קובוק"
|
||||
|
||||
امبلر"
|
||||
|
||||
انوئک"
|
||||
|
||||
رزلوت"
|
||||
|
||||
كوبوك"
|
||||
|
||||
کوبوک"
|
||||
Fort Yukón"
|
||||
Mys Chmidta"
|
||||
Mys Shmidta"
|
||||
Mys Sjmidta"
|
||||
Mys Szmidta"
|
||||
Mys Šmidta"
|
||||
Prudhoe Bay"
|
||||
Tuktoyaktuk"
|
||||
Ikaluktutiak"
|
||||
Mys Schmidta"
|
||||
Resolute Bay"
|
||||
Tsiigehtchic"
|
||||
Άμπλερ"
|
||||
Χόλμαν"
|
||||
Інувік"
|
||||
Амблер"
|
||||
Барроу"
|
||||
Инувик"
|
||||
Коцебу"
|
||||
וויזמן"
|
||||
טלויאק"
|
||||
קוצביו"
|
||||
רזולוט"
|
||||
أمبلير"
|
||||
إنوفيك"
|
||||
ایمبلر"
|
||||
سلاویک"
|
||||
سیلاوک"
|
||||
سیگیچک"
|
||||
هولمان"
|
||||
وایزمن"
|
||||
پالتاک"
|
||||
پولاٹک"
|
||||
ہولمان"
|
||||
努勒維特"
|
||||
因纽维克"
|
||||
基瓦利纳"
|
||||
塔洛約克"
|
||||
塞拉威克"
|
||||
施密特岬"
|
||||
波拉圖克"
|
||||
雷索卢特"
|
||||
齊格奇克"
|
||||
뚝토약툭"
|
||||
리솔루트"
|
||||
알라카켓"
|
||||
와이즈맨"
|
||||
치이게치"
|
||||
키발리나"
|
||||
탈로요크"
|
||||
파울라툭"
|
||||
Cambridge Bay"
|
||||
United States"
|
||||
포트 유콘"
|
||||
America/Inuvik"
|
||||
America/Juneau"
|
||||
Campbridge Bay"
|
||||
Fort McPherson"
|
||||
Prudhoe-öböl"
|
||||
Ινούβικ"
|
||||
Κομπούκ"
|
||||
Μπάροου"
|
||||
Σελαβίκ"
|
||||
Аткасук"
|
||||
Вайзмен"
|
||||
Полатук"
|
||||
Селавик"
|
||||
Селавік"
|
||||
Уайзмен"
|
||||
Цігечик"
|
||||
אטקאסוק"
|
||||
אינוויק"
|
||||
סלאוויק"
|
||||
קקטוביק"
|
||||
آتکاسوک"
|
||||
آلاکاکت"
|
||||
اینوویک"
|
||||
ایٹقاسک"
|
||||
بولاتوك"
|
||||
تالویوک"
|
||||
تسیگچیک"
|
||||
زویزڈنج"
|
||||
سيلاويك"
|
||||
كوتزبيو"
|
||||
نورمینو"
|
||||
وائزمین"
|
||||
وينرايت"
|
||||
وینرائٹ"
|
||||
وینرایت"
|
||||
ٹالویوک"
|
||||
کگ لک تک"
|
||||
کیکٹووک"
|
||||
Populated place"
|
||||
جوا ہیون"
|
||||
وايز مان"
|
||||
پرودو بی"
|
||||
कोबुक"
|
||||
কসেভো"
|
||||
কোবুক"
|
||||
アンブラー"
|
||||
エヌルミノ"
|
||||
カクトビク"
|
||||
キバリーナ"
|
||||
セラウィク"
|
||||
タロヨーク"
|
||||
ワイズマン"
|
||||
卡克托维克"
|
||||
普拉德霍湾"
|
||||
普拉德霍灣"
|
||||
波因特霍普"
|
||||
烏路卡托克"
|
||||
艾奴爾米諾"
|
||||
艾特跨萨克"
|
||||
茲韋茲德尼"
|
||||
迈斯施密达"
|
||||
阿拉卡基特"
|
||||
麥克弗森堡"
|
||||
麦克弗森堡"
|
||||
에누르미노"
|
||||
웨인라이트"
|
||||
카크토비크"
|
||||
쿠글룩투크"
|
||||
America/Resolute"
|
||||
Vịnh Cambridge"
|
||||
Αλακάκετ"
|
||||
Ατκασούκ"
|
||||
Ζβέζντιγ"
|
||||
Κάκτοβικ"
|
||||
Κιβαλίνα"
|
||||
Ρεσολούτ"
|
||||
Вейнрайт"
|
||||
Енурміно"
|
||||
Звёздный"
|
||||
Кактовик"
|
||||
Кактовік"
|
||||
Кивалина"
|
||||
Паулатук"
|
||||
Резольют"
|
||||
Талойоак"
|
||||
Уэйнрайт"
|
||||
Цигетчик"
|
||||
Энурмино"
|
||||
אנורמינו"
|
||||
ויינרייט"
|
||||
פאולאטוק"
|
||||
ציג'טצ'יק"
|
||||
קיוולינה"
|
||||
أتكيوسوك"
|
||||
ألاكاكيت"
|
||||
إنورمينو"
|
||||
انورمینو"
|
||||
تالويواك"
|
||||
ریسولوتی"
|
||||
زووزدنیج"
|
||||
زيفازدني"
|
||||
كاكتوفيك"
|
||||
كيفالينا"
|
||||
کاکتوویک"
|
||||
کوتزابیو"
|
||||
کوتزهبیو"
|
||||
کیوالینا"
|
||||
미스 슈미타"
|
||||
조아 헤이븐"
|
||||
포인트 호프"
|
||||
포트 맥퍼슨"
|
||||
프루도 베이"
|
||||
Форт-Юкон"
|
||||
פוינט הופ"
|
||||
פרודו ביי"
|
||||
بوينت هوب"
|
||||
پروڈہو بے"
|
||||
پوینت هوپ"
|
||||
کمبریج بی"
|
||||
کیمبرج بے"
|
||||
Γουάιζμαν"
|
||||
Ενουρμίνο"
|
||||
Ταλογιοάκ"
|
||||
Аллакакет"
|
||||
Звьоздний"
|
||||
Куглуктук"
|
||||
זביוזדניי"
|
||||
ایلاکاکیٹ"
|
||||
كوغلوكتوك"
|
||||
مایسشمیتا"
|
||||
ٹکٹویاکٹک"
|
||||
کوگلاکتوک"
|
||||
इनुविक"
|
||||
होलमैन"
|
||||
ইনুভিক"
|
||||
アラカキット"
|
||||
イヌヴィック"
|
||||
コッツビュー"
|
||||
シュミット岬"
|
||||
ズヴョズニィ"
|
||||
パウラトゥク"
|
||||
プルードー湾"
|
||||
レゾリュート"
|
||||
伊尔库茨克州"
|
||||
图克托亚图克"
|
||||
圖克托亞圖克"
|
||||
库格鲁克图克"
|
||||
庫格魯克圖克"
|
||||
즈베즈드니이"
|
||||
Μις Σμίντα"
|
||||
Йоа-Гейвен"
|
||||
Йоа-Хейвен"
|
||||
Мис Барроу"
|
||||
Мис Шмідта"
|
||||
Мыс Шмидта"
|
||||
Пойнт-Гоуп"
|
||||
Пойнт-Хоуп"
|
||||
Прадхо-Бей"
|
||||
מיס שמידטה"
|
||||
פורט יוקון"
|
||||
جیجوی هیون"
|
||||
فورت يوكون"
|
||||
فورت یوکان"
|
||||
فورٹ یوکون"
|
||||
ميس شميدتا"
|
||||
پوائنٹ ہوپ"
|
||||
캠브리지 베이"
|
||||
Γουέινραϊτ"
|
||||
Κοτζέμπουε"
|
||||
Παουλατούκ"
|
||||
Тактояктук"
|
||||
Туктояктук"
|
||||
Улукхакток"
|
||||
גג'ואה האבן"
|
||||
טוקטויאטוק"
|
||||
קוגלולקטוק"
|
||||
اولاکاکچوک"
|
||||
تسيجيهتشيك"
|
||||
Northwest Territories"
|
||||
Γκόα Χέιβεν"
|
||||
Πόιντ Χόουπ"
|
||||
خليج برودهو"
|
||||
فورٹ مکفرسن"
|
||||
مئیس شمیدتا"
|
||||
ऐम्ब्लर"
|
||||
पॉलातुक"
|
||||
रेसोलूट"
|
||||
वेनराइट"
|
||||
सेलाविक"
|
||||
ওয়েনরিট"
|
||||
তালোয়াক"
|
||||
সেলাউইক"
|
||||
アットカサック"
|
||||
ウェインライト"
|
||||
クグルクトゥク"
|
||||
ポイントホープ"
|
||||
توكتوياكتوك"
|
||||
توکتویاکتوک"
|
||||
Προύντο Μπέι"
|
||||
Φορτ Γιούκον"
|
||||
פורט מקפרסון"
|
||||
خليج كامبردج"
|
||||
قرية ريزولوت"
|
||||
Chukchi Autonomous Okrug"
|
||||
United States of America"
|
||||
Τσιγκέχτσιτς"
|
||||
فورت مک فرسون"
|
||||
قرية غوا هافن"
|
||||
अत्कासुक"
|
||||
अलाकाकेट"
|
||||
इनर्मिनो"
|
||||
किवालिना"
|
||||
टालोयोआक"
|
||||
वाइज़मैन"
|
||||
কাকতোভিক"
|
||||
কিভালিনা"
|
||||
পাউলাটুক"
|
||||
রেজোলিউট"
|
||||
সিগেটছিক"
|
||||
হোলম্যান"
|
||||
ウルクハクトーク"
|
||||
ジョア・ヘイヴン"
|
||||
トサイイジチック"
|
||||
フォートユーコン"
|
||||
Кеймбридж-Бей"
|
||||
Кеймбрідж-Бей"
|
||||
فورت ماكفرسون"
|
||||
पॉइंट होप"
|
||||
Κουγκλουκτούκ"
|
||||
קיימברדיג' ביי"
|
||||
Κέιμπριτζ Μπέι"
|
||||
Φορτ ΜακΦέρσον"
|
||||
Форт-Макферсон"
|
||||
काक्तोविक"
|
||||
এনিউরমিনো"
|
||||
ケンブリッジ・ベイ"
|
||||
トゥクトヤクトゥク"
|
||||
Τουκτογιάκτουκ"
|
||||
ज़ोआ हेवेन"
|
||||
प्रुदहो बे"
|
||||
मिस श्मिता"
|
||||
পয়েন্ট হোপ"
|
||||
ফোর্ট ইউকন"
|
||||
उत्कीग्विक"
|
||||
कुग्लुकटूक"
|
||||
कोटज़ेबूये"
|
||||
অ্যাম্বলার"
|
||||
আল্লাকাকেত"
|
||||
উৎকিয়াভিক"
|
||||
ওয়াইজম্যান"
|
||||
কুগ্লুকটুক"!
|
||||
গজোয়া হাভেন"!
|
||||
প্রুদোহে বে"#
|
||||
!त्सीगेत्चिक"#
|
||||
!フォートマクファーソン"$
|
||||
"कैम्ब्रिज बे"$
|
||||
"फ़ोर्ट यूकॉन"$
|
||||
"কেম্ব্রিজ বে"$
|
||||
"মাইস শ্মিদতা"&
|
||||
$অ্যাটকোয়াসুক"&
|
||||
$জেভেজদিনিয়াজ"&
|
||||
$তুকতোইয়াকতুক")
|
||||
'ज़्वेज़्दनिज़")
|
||||
'तुक्तोयाक्तुक"0
|
||||
.फ़ोर्ट मैकफ़र्सन"0
|
||||
.ফোর্ট ম্যাকফারসন" | ||||