mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-06-24 09:46:41 +00:00
Compare commits
19 Commits
master
...
wagyu-dyna
Author | SHA1 | Date | |
---|---|---|---|
5816822168 | |||
2b4202b567 | |||
3b8e48c0ee | |||
4aeeac6fba | |||
a52342b575 | |||
80f30b8df6 | |||
90841d3932 | |||
d03881e0d2 | |||
9954a6bbda | |||
efbf7353f2 | |||
66a47d2096 | |||
0f0131da22 | |||
0a22d52ad3 | |||
9861858280 | |||
2ad768175c | |||
15883b4758 | |||
e5635c37e7 | |||
ace8e19862 | |||
6da034dda9 |
@ -1,5 +0,0 @@
|
||||
# Don't copy Dockerfile or git items
|
||||
.gitignore
|
||||
.git
|
||||
Dockerfile
|
||||
Dockerfile.centos7
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -4,9 +4,6 @@
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Autogenerated dependencies
|
||||
*.d
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
@ -30,23 +27,3 @@
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
tippecanoe
|
||||
tile-join
|
||||
tippecanoe-decode
|
||||
tippecanoe-enumerate
|
||||
tippecanoe-json-tool
|
||||
unit
|
||||
|
||||
# Tests
|
||||
tests/**/*.mbtiles
|
||||
tests/**/*.check
|
||||
tests/**/*.geobuf
|
||||
|
||||
# Vim
|
||||
*.swp
|
||||
|
||||
# Mac
|
||||
.DS_Store
|
||||
|
||||
# Nodejs
|
||||
node_modules
|
||||
|
48
.travis.yml
48
.travis.yml
@ -1,37 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
language: generic
|
||||
|
||||
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
|
||||
@ -43,7 +15,7 @@ matrix:
|
||||
# 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
|
||||
env: CLANG_VERSION='3.8.0' BUILDTYPE=Debug ASAN_OPTIONS=detect_leaks=1 CC="clang-3.8" CXX="clang++-3.8" CXXFLAGS="-fsanitize=address" CFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address"
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test' ]
|
||||
@ -52,13 +24,6 @@ matrix:
|
||||
- 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' ]
|
||||
@ -103,8 +68,9 @@ 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;
|
||||
- BUILDTYPE=${BUILDTYPE} make test
|
||||
- if [ -n "${COVERAGE}" ]; then
|
||||
/usr/bin/llvm-cov-3.5 -lp *.o;
|
||||
pip install --user cpp-coveralls;
|
||||
~/.local/bin/coveralls --no-gcov -i ./ --exclude clipper;
|
||||
fi
|
||||
|
527
CHANGELOG.md
527
CHANGELOG.md
@ -1,530 +1,3 @@
|
||||
## 1.36.0
|
||||
|
||||
* Update Wagyu to version 0.5.0
|
||||
|
||||
## 1.35.0
|
||||
|
||||
* Fix calculation of mean when accumulating attributes in clusters
|
||||
|
||||
## 1.34.6
|
||||
|
||||
* Fix crash when there are null entries in the metadata table
|
||||
|
||||
## 1.34.5
|
||||
|
||||
* Fix line numbers in GeoJSON feature parsing error messages
|
||||
|
||||
## 1.34.4
|
||||
|
||||
* Be careful to avoid undefined behavior from shifting negative numbers
|
||||
|
||||
## 1.34.3
|
||||
|
||||
* Add an option to keep intersection nodes from being simplified away
|
||||
|
||||
## 1.34.2
|
||||
|
||||
* Be more consistent about when longitudes beyond 180 are allowed.
|
||||
Now if the entire feature is beyond 180, it will still appear.
|
||||
|
||||
## 1.34.1
|
||||
|
||||
* Don't run shell filters if the current zoom is below the minzoom
|
||||
* Fix -Z and -z for tile directories in tile-join and tippecanoe-decode
|
||||
* Return a successful error status for --help and --version
|
||||
|
||||
## 1.34.0
|
||||
|
||||
* Record the command line options in the tileset metadata
|
||||
|
||||
## 1.33.0
|
||||
|
||||
* MultiLineStrings were previously ignored in Geobuf input
|
||||
|
||||
## 1.32.12
|
||||
|
||||
* Accept .mvt as well as .pbf in directories of tiles
|
||||
* Allow tippecanoe-decode and tile-join of directories with no metadata
|
||||
|
||||
## 1.32.11
|
||||
* Don't let attribute exclusion apply to the attribute that has been specified
|
||||
to become the feature ID
|
||||
|
||||
## 1.32.10
|
||||
|
||||
* Fix a bug that disallowed a per-feature minzoom of 0
|
||||
|
||||
## 1.32.9
|
||||
|
||||
* Limit tile detail to 30 and buffer size to 127 to prevent coordinate
|
||||
delta overflow in vector tiles.
|
||||
|
||||
## 1.32.8
|
||||
|
||||
* Better error message if the output tileset already exists
|
||||
|
||||
## 1.32.7
|
||||
|
||||
* Point features may now be coalesced into MultiPoint features with --coalesce.
|
||||
* Add --hilbert option to put features in Hilbert Curve sequence
|
||||
|
||||
## 1.32.6
|
||||
|
||||
* Make it an error, not a warning, to have missing coordinates for a point
|
||||
|
||||
## 1.32.5
|
||||
|
||||
* Use less memory on lines and polygons that are too small for the tile
|
||||
* Fix coordinate rounding problem that was causing --grid-low-zooms grids
|
||||
to be lost at low zooms if the original polygons were not aligned to
|
||||
tile boundaries
|
||||
|
||||
## 1.32.4
|
||||
|
||||
* Ignore leading zeroes when converting string attributes to feature IDs
|
||||
|
||||
## 1.32.3
|
||||
|
||||
* Add an option to convert stringified number feature IDs to numbers
|
||||
* Add an option to use a specified feature attribute as the feature ID
|
||||
|
||||
## 1.32.2
|
||||
|
||||
* Warn in tile-join if tilesets being joined have inconsistent maxzooms
|
||||
|
||||
## 1.32.1
|
||||
|
||||
* Fix null pointer crash when reading filter output that does not
|
||||
tag features with their extent
|
||||
* Add `--clip-bounding-box` option to clip input geometry
|
||||
|
||||
## 1.32.0
|
||||
|
||||
* Fix a bug that allowed coalescing of features with mismatched attributes
|
||||
if they had been passed through a shell prefilter
|
||||
|
||||
## 1.31.7
|
||||
|
||||
* Create the output tile directory even if there are no valid features
|
||||
|
||||
## 1.31.6
|
||||
|
||||
* Issue an error message in tile-join if minzoom is greater than maxzoom
|
||||
|
||||
## 1.31.5
|
||||
|
||||
* Add options to change the tilestats limits
|
||||
|
||||
## 1.31.4
|
||||
|
||||
* Keep tile-join from generating a tileset name longer than 255 characters
|
||||
|
||||
## 1.31.3
|
||||
|
||||
* Fix the missing filename in JSON parsing warning messages
|
||||
|
||||
## 1.31.2
|
||||
|
||||
* Don't accept anything inside another JSON object's properties as a
|
||||
feature or geometry of its own.
|
||||
|
||||
## 1.31.1
|
||||
|
||||
* Add --exclude-all to tile-join
|
||||
|
||||
## 1.31.0
|
||||
|
||||
* Upgrade Wagyu to version 0.4.3
|
||||
|
||||
## 1.30.6
|
||||
|
||||
* Take cluster distance into account when guessing a maxzoom
|
||||
|
||||
## 1.30.4
|
||||
|
||||
* Features within the z0 tile buffer of the antimeridian (not only
|
||||
those that cross it) are duplicated on both sides.
|
||||
|
||||
## 1.30.3
|
||||
|
||||
* Add an option to automatically assign ids to features
|
||||
|
||||
## 1.30.2
|
||||
|
||||
* Don't guess a higher maxzoom than is allowed for manual selection
|
||||
|
||||
## 1.30.1
|
||||
|
||||
* Ensure that per-feature minzoom and maxzoom are integers
|
||||
* Report compression errors in tippecanoe-decode
|
||||
* Add the ability to specify the file format with -L{"format":"…"}
|
||||
* Add an option to treat empty CSV columns as nulls, not empty strings
|
||||
|
||||
## 1.30.0
|
||||
|
||||
* Add a filter extension to allow filtering individual attributes
|
||||
|
||||
## 1.29.3
|
||||
|
||||
* Include a generator field in tileset metadata with the Tippecanoe version
|
||||
|
||||
## 1.29.2
|
||||
|
||||
* Be careful to remove null attributes from prefilter/postfilter output
|
||||
|
||||
## 1.29.1
|
||||
|
||||
* Add --use-source-polygon-winding and --reverse-source-polygon-winding
|
||||
|
||||
## 1.29.0
|
||||
|
||||
* Add the option to specify layer file, name, and description as JSON
|
||||
* Add the option to specify the description for attributes in the
|
||||
tileset metadata
|
||||
* In CSV input, a trailing comma now counts as a trailing empty field
|
||||
* In tippecanoe-json-tool, an empty CSV field is now an empty string,
|
||||
not null (for consistency with tile-join)
|
||||
|
||||
## 1.28.1
|
||||
|
||||
* Explicitly check for infinite and not-a-number input coordinates
|
||||
|
||||
## 1.28.0
|
||||
|
||||
* Directly support gzipped GeoJSON as input files
|
||||
|
||||
## 1.27.16
|
||||
|
||||
* Fix thread safety issues related to the out-of-disk-space checker
|
||||
|
||||
## 1.27.15
|
||||
|
||||
* --extend-zooms-if-still-dropping now also extends zooms if features
|
||||
are dropped by --force-feature-limit
|
||||
|
||||
## 1.27.14
|
||||
|
||||
* Use an exit status of 100 if some zoom levels were successfully
|
||||
written but not all zoom levels could be tiled.
|
||||
|
||||
## 1.27.13
|
||||
|
||||
* Allow filtering features by zoom level in conditional expressions
|
||||
* Lines in CSV input with empty geometry columns will be ignored
|
||||
|
||||
## 1.27.12
|
||||
|
||||
* Check integrity of sqlite3 file before decoding or tile-joining
|
||||
|
||||
## 1.27.11
|
||||
|
||||
* Always include tile and layer in tippecanoe-decode, fixing corrupt JSON.
|
||||
* Clean up writing of JSON in general.
|
||||
|
||||
## 1.27.10
|
||||
|
||||
* Add --progress-interval setting to reduce progress indicator frequency
|
||||
|
||||
## 1.27.9
|
||||
|
||||
* Make clusters look better by averaging locations of clustered points
|
||||
|
||||
## 1.27.8
|
||||
|
||||
* Add --accumulate-attribute to keep attributes of dropped, coalesced,
|
||||
or clustered features
|
||||
* Make sure numeric command line arguments are actually numbers
|
||||
* Don't coalesce features whose non-string-pool attributes don't match
|
||||
|
||||
## 1.27.7
|
||||
|
||||
* Add an option to produce only a single tile
|
||||
* Retain non-ASCII characters in layernames generated from filenames
|
||||
* Remember to close input files after reading them
|
||||
* Add --coalesce-fraction-as-needed and --coalesce-densest-as-needed
|
||||
* Report distances in both feet and meters
|
||||
|
||||
## 1.27.6
|
||||
|
||||
* Fix opportunities for integer overflow and out-of-bounds references
|
||||
|
||||
## 1.27.5
|
||||
|
||||
* Add --cluster-densest-as-needed to cluster features
|
||||
* Add --maximum-tile-features to set the maximum number of features in a tile
|
||||
|
||||
## 1.27.4
|
||||
|
||||
* Support CSV point input
|
||||
* Don't coalesce features that have different IDs but are otherwise identical
|
||||
* Remove the 700-point limit on coalesced features, since polygon merging
|
||||
is no longer a performance problem
|
||||
|
||||
## 1.27.3
|
||||
|
||||
* Clean up duplicated code for reading tiles from a directory
|
||||
|
||||
## 1.27.2
|
||||
|
||||
* Tippecanoe-decode can decode directories of tiles, not just mbtiles
|
||||
* The --allow-existing option works on directories of tiles
|
||||
* Trim .geojson, not just .json, when making layer names from filenames
|
||||
|
||||
## 1.27.1
|
||||
|
||||
* Fix a potential null pointer when parsing GeoJSON with bare geometries
|
||||
* Fix a bug that could cause the wrong features to be coalesced when
|
||||
input was parsed in parallel
|
||||
|
||||
## 1.27.0
|
||||
|
||||
* Add tippecanoe-json-tool for sorting and joining GeoJSON files
|
||||
* Fix problem where --detect-shared-borders could simplify polygons away
|
||||
* Attach --coalesce-smallest-as-needed leftovers to the last feature, not the first
|
||||
* Fix overflow when iterating through 0-length lists backwards
|
||||
|
||||
## 1.26.7
|
||||
|
||||
* Add an option to quiet the progress indicator but not warnings
|
||||
* Enable more compiler warnings and fix related problems
|
||||
|
||||
## 1.26.6
|
||||
|
||||
* Be more careful about checking for overflow when parsing numbers
|
||||
|
||||
## 1.26.5
|
||||
|
||||
* Support UTF-16 surrogate pairs in JSON strings
|
||||
* Support arbitrarily long lines in CSV files.
|
||||
* Treat CSV fields as numbers only if they follow JSON number syntax
|
||||
|
||||
## 1.26.4
|
||||
|
||||
* Array bounds bug fix in binary to decimal conversion library
|
||||
|
||||
## 1.26.3
|
||||
|
||||
* Guard against impossible coordinates when decoding tilesets
|
||||
|
||||
## 1.26.2
|
||||
|
||||
* Make sure to encode tile-joined integers as ints, not doubles
|
||||
|
||||
## 1.26.1
|
||||
|
||||
* Add tile-join option to rename layers
|
||||
|
||||
## 1.26.0
|
||||
|
||||
Fix error when parsing attributes with empty-string keys
|
||||
|
||||
## 1.25.0
|
||||
|
||||
* Add --coalesce-smallest-as-needed strategy for reducing tile sizes
|
||||
* Add --stats option to tipppecanoe-decode
|
||||
|
||||
## 1.24.1
|
||||
|
||||
* Limit the size and depth of the string pool for better performance
|
||||
|
||||
## 1.24.0
|
||||
|
||||
* Add feature filters using the Mapbox GL Style Specification filter syntax
|
||||
|
||||
## 1.23.0
|
||||
|
||||
* Add input support for Geobuf file format
|
||||
|
||||
## 1.22.2
|
||||
|
||||
* Add better diagnostics for NaN or Infinity in input JSON
|
||||
|
||||
## 1.22.1
|
||||
|
||||
* Fix tilestats generation when long string attribute values are elided
|
||||
* Add option not to produce tilestats
|
||||
* Add tile-join options to select zoom levels to copy
|
||||
|
||||
## 1.22.0
|
||||
|
||||
* Add options to filter each tile's contents through a shell pipeline
|
||||
|
||||
## 1.21.0
|
||||
|
||||
* Generate layer, feature, and attribute statistics as part of tileset metadata
|
||||
|
||||
## 1.20.1
|
||||
|
||||
* Close mbtiles file properly when there are no valid features in the input
|
||||
|
||||
## 1.20.0
|
||||
|
||||
* Add long options to tippecanoe-decode and tile-join. Add --quiet to tile-join.
|
||||
|
||||
## 1.19.3
|
||||
|
||||
* Upgrade protozero to version 1.5.2
|
||||
|
||||
## 1.19.2
|
||||
|
||||
* Ignore UTF-8 byte order mark if present
|
||||
|
||||
## 1.19.1
|
||||
|
||||
* Add an option to increase maxzoom if features are still being dropped
|
||||
|
||||
## 1.19.0
|
||||
|
||||
* Tile-join can merge and create directories, not only mbtiles
|
||||
* Maxzoom guessing (-zg) takes into account resolution within each feature
|
||||
|
||||
## 1.18.2
|
||||
|
||||
* Fix crash with very long (>128K) attribute values
|
||||
|
||||
## 1.18.1
|
||||
|
||||
* Only warn once about invalid polygons in tippecanoe-decode
|
||||
|
||||
## 1.18.0
|
||||
|
||||
* Fix compression of tiles in tile-join
|
||||
* Calculate the tileset bounding box in tile-join from the tile boundaries
|
||||
|
||||
## 1.17.7
|
||||
|
||||
* Enforce polygon winding and closure rules in tippecanoe-decode
|
||||
|
||||
## 1.17.6
|
||||
|
||||
* Add tile-join options to set name, attribution, description
|
||||
|
||||
## 1.17.5
|
||||
|
||||
* Preserve the tileset names from the source mbtiles in tile-join
|
||||
|
||||
## 1.17.4
|
||||
|
||||
* Fix RFC 8142 support: Don't try to split *all* memory mapped files
|
||||
|
||||
## 1.17.3
|
||||
|
||||
* Support RFC 8142 GeoJSON text sequences
|
||||
|
||||
## 1.17.2
|
||||
|
||||
* Organize usage output the same way as in the README
|
||||
|
||||
## 1.17.1
|
||||
|
||||
* Add -T option to coerce the types of feature attributes
|
||||
|
||||
## 1.17.0
|
||||
|
||||
* Add -zg option to guess an appropriate maxzoom
|
||||
|
||||
## 1.16.17
|
||||
|
||||
* Clean up JSON parsing at the end of each FeatureCollection
|
||||
to avoid running out of memory
|
||||
|
||||
## 1.16.16
|
||||
|
||||
* Add tile-join options to include or exclude specific layers
|
||||
|
||||
## 1.16.15
|
||||
|
||||
* Add --output-to-directory and --no-tile-compression options
|
||||
|
||||
## 1.16.14
|
||||
|
||||
* Add --description option for mbtiles metadata
|
||||
* Clean up some utility functions
|
||||
|
||||
## 1.16.13
|
||||
|
||||
* Add --detect-longitude-wraparound option
|
||||
|
||||
## 1.16.12
|
||||
|
||||
* Stop processing higher zooms when a feature reaches its explicit maxzoom tag
|
||||
|
||||
## 1.16.11
|
||||
|
||||
* Remove polygon splitting, since polygon cleaning is now fast enough
|
||||
|
||||
## 1.16.10
|
||||
|
||||
* Add a tippecanoe-decode option to specify layer names
|
||||
|
||||
## 1.16.9
|
||||
|
||||
* Clean up layer name handling to fix layer merging crash
|
||||
|
||||
## 1.16.8
|
||||
|
||||
* Fix some code that could sometimes try to divide by zero
|
||||
* Add check for $TIPPECANOE_MAX_THREADS environmental variable
|
||||
|
||||
## 1.16.7
|
||||
|
||||
* Fix area of placeholders for degenerate multipolygons
|
||||
|
||||
## 1.16.6
|
||||
|
||||
* Upgrade Wagyu to 0.3.0; downgrade C++ requirement to C++ 11
|
||||
|
||||
## 1.16.5
|
||||
|
||||
* Add -z and -Z options to tippecanoe-decode
|
||||
|
||||
## 1.16.4
|
||||
|
||||
* Use Wagyu's quick_lr_clip() instead of a separate implementation
|
||||
|
||||
## 1.16.3
|
||||
|
||||
* Upgrade Wagyu to bfbf2893
|
||||
|
||||
## 1.16.2
|
||||
|
||||
* Associate attributes with the right layer when explicitly tagged
|
||||
|
||||
## 1.16.1
|
||||
|
||||
* Choose a deeper starting tile than 0/0/0 if there is one that contains
|
||||
all the features
|
||||
|
||||
## 1.16.0
|
||||
|
||||
* Switch from Clipper to Wagyu for polygon topology correction
|
||||
|
||||
## 1.15.4
|
||||
|
||||
* Dot-dropping with -r/-B doesn't apply if there is a per-feature minzoom tag
|
||||
|
||||
## 1.15.3
|
||||
|
||||
* Round coordinates in low-zoom grid math instead of truncating
|
||||
|
||||
## 1.15.2
|
||||
|
||||
* Add --grid-low-zooms option to snap low-zoom features to the tile grid
|
||||
|
||||
## 1.15.1
|
||||
|
||||
* Stop --drop-smallest-as-needed from always dropping all points
|
||||
|
||||
## 1.15.0
|
||||
|
||||
* New strategies for making tiles smaller, with uniform behavior across
|
||||
the whole zoom level: --increase-gamma-as-needed,
|
||||
--drop-densest-as-needed, --drop-fraction-as-needed,
|
||||
--drop-smallest-as-needed.
|
||||
* Option to specify the maximum tile size in bytes
|
||||
* Option to turn off tiny polygon reduction
|
||||
* Better error checking in JSON parsing
|
||||
|
||||
## 1.14.4
|
||||
|
||||
* Make -B/-r feature-dropping consistent between tiles and zoom levels
|
||||
|
19
Dockerfile
19
Dockerfile
@ -1,19 +0,0 @@
|
||||
# Start from ubuntu
|
||||
FROM ubuntu:16.04
|
||||
|
||||
# Update repos and install dependencies
|
||||
RUN apt-get update \
|
||||
&& apt-get -y upgrade \
|
||||
&& apt-get -y install build-essential libsqlite3-dev zlib1g-dev
|
||||
|
||||
# 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
|
@ -1,15 +0,0 @@
|
||||
FROM centos:7
|
||||
|
||||
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
|
@ -1,4 +1,4 @@
|
||||
## [Visualizing a Month of Lightning](http://rousseau.io/2015/03/23/visualizing-a-month-of-lightning) by Jordan Rousseau
|
||||
## [Visualizing a Month of Lightning](http://rousseau.io/2015/03/23/visualizing-a-month-of-lightning/) by Jordan Rousseau
|
||||
|
||||

|
||||
|
||||
|
282
Makefile
282
Makefile
@ -7,9 +7,9 @@ SHELL = /bin/bash
|
||||
CC := $(CC)
|
||||
CXX := $(CXX)
|
||||
CFLAGS := $(CFLAGS)
|
||||
CXXFLAGS := $(CXXFLAGS) -std=c++11
|
||||
CXXFLAGS := $(CXXFLAGS) -std=c++14
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
WARNING_FLAGS := -Wall -Wshadow -Wsign-compare -Wextra -Wunreachable-code -Wuninitialized -Wshadow
|
||||
WARNING_FLAGS := -Wall -Wshadow -Wsign-compare
|
||||
RELEASE_FLAGS := -O3 -DNDEBUG
|
||||
DEBUG_FLAGS := -O0 -DDEBUG -fno-inline-functions -fno-omit-frame-pointer
|
||||
|
||||
@ -19,23 +19,19 @@ else
|
||||
FINAL_FLAGS := -g $(WARNING_FLAGS) $(DEBUG_FLAGS)
|
||||
endif
|
||||
|
||||
all: tippecanoe tippecanoe-enumerate tippecanoe-decode tile-join unit tippecanoe-json-tool
|
||||
all: tippecanoe tippecanoe-enumerate tippecanoe-decode tile-join unit
|
||||
|
||||
docs: man/tippecanoe.1
|
||||
|
||||
install: tippecanoe tippecanoe-enumerate tippecanoe-decode tile-join tippecanoe-json-tool
|
||||
install: tippecanoe tippecanoe-enumerate tippecanoe-decode tile-join
|
||||
mkdir -p $(PREFIX)/bin
|
||||
mkdir -p $(MANDIR)
|
||||
cp tippecanoe $(PREFIX)/bin/tippecanoe
|
||||
cp tippecanoe-enumerate $(PREFIX)/bin/tippecanoe-enumerate
|
||||
cp tippecanoe-decode $(PREFIX)/bin/tippecanoe-decode
|
||||
cp tippecanoe-json-tool $(PREFIX)/bin/tippecanoe-json-tool
|
||||
cp tile-join $(PREFIX)/bin/tile-join
|
||||
cp man/tippecanoe.1 $(MANDIR)/tippecanoe.1
|
||||
|
||||
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
|
||||
|
||||
man/tippecanoe.1: README.md
|
||||
md2man-roff README.md > man/tippecanoe.1
|
||||
|
||||
@ -44,22 +40,19 @@ PG=
|
||||
H = $(wildcard *.h) $(wildcard *.hpp)
|
||||
C = $(wildcard *.c) $(wildcard *.cpp)
|
||||
|
||||
INCLUDES = -I/usr/local/include -I.
|
||||
INCLUDES = -Iwagyu/include -I.
|
||||
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 plugin.o read_json.o write_json.o geobuf.o evaluator.o geocsv.o csv.o geojson-loop.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 text.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-enumerate: enumerate.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lsqlite3
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lsqlite3
|
||||
|
||||
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o
|
||||
tippecanoe-decode: decode.o projection.o mvt.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
|
||||
|
||||
tile-join: tile-join.o projection.o pool.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.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
|
||||
tile-join: tile-join.o projection.o pool.o mbtiles.o mvt.o memfile.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
unit: unit.o text.o
|
||||
@ -74,7 +67,7 @@ unit: unit.o text.o
|
||||
$(CXX) -MMD $(PG) $(INCLUDES) $(FINAL_FLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f ./tippecanoe ./tippecanoe-* ./tile-join ./unit *.o *.d */*.o */*.d tests/**/*.mbtiles tests/**/*.check
|
||||
rm -f tippecanoe *.o *.d */*.o */*.d
|
||||
|
||||
indent:
|
||||
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false, SortIncludes: false}" $(C) $(H)
|
||||
@ -82,259 +75,68 @@ 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
|
||||
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) parallel-test pbf-test join-test enumerate-test unit
|
||||
./unit
|
||||
|
||||
suffixes = json json.gz
|
||||
|
||||
# Work around Makefile and filename punctuation limits: _ for space, @ for :, % for /
|
||||
%.json.check:
|
||||
./tippecanoe -q -a@ -f -o $@.mbtiles $(subst @,:,$(subst %,/,$(subst _, ,$(patsubst %.json.check,%,$(word 4,$(subst /, ,$@)))))) $(foreach suffix,$(suffixes),$(sort $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.$(suffix)))) < /dev/null
|
||||
./tippecanoe-decode -x generator $@.mbtiles > $@.out
|
||||
cmp $@.out $(patsubst %.check,%,$@)
|
||||
rm $@.out $@.mbtiles
|
||||
|
||||
# Don't test overflow with geobuf, because it fails (https://github.com/mapbox/geobuf/issues/87)
|
||||
# Don't test stringids with geobuf, because it fails
|
||||
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
|
||||
|
||||
# XXX Use proper makefile rules instead of a for loop
|
||||
%.json.checkbuf:
|
||||
for i in $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json); do ./tippecanoe-json-tool -w $$i | ./node_modules/geobuf/bin/json2geobuf > $$i.geobuf; done
|
||||
for i in $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json.gz); do gzip -dc $$i | ./tippecanoe-json-tool -w | ./node_modules/geobuf/bin/json2geobuf > $$i.geobuf; done
|
||||
./tippecanoe -q -a@ -f -o $@.mbtiles $(subst @,:,$(subst %,/,$(subst _, ,$(patsubst %.json.checkbuf,%,$(word 4,$(subst /, ,$@)))))) $(foreach suffix,$(suffixes),$(addsuffix .geobuf,$(sort $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.$(suffix))))) < /dev/null
|
||||
./tippecanoe-decode -x generator $@.mbtiles | sed 's/checkbuf/check/g' | sed 's/\.geobuf//g' > $@.out
|
||||
cmp $@.out $(patsubst %.checkbuf,%,$@)
|
||||
./tippecanoe -aD -f -o $@.mbtiles $(subst @,:,$(subst %,/,$(subst _, ,$(patsubst %.json.check,%,$(word 4,$(subst /, ,$@)))))) $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json) < /dev/null
|
||||
./tippecanoe-decode $@.mbtiles > $@.out
|
||||
cmp $(patsubst %.check,%,$@) $@.out
|
||||
rm $@.out $@.mbtiles
|
||||
|
||||
parallel-test:
|
||||
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
|
||||
perl -e 'for ($$i = 0; $$i < 20; $$i++) { $$lon = rand(360) - 180; $$lat = rand(180) - 90; print "{ \"type\": \"Feature\", \"properties\": { \"yes\": \"no\", \"who\": 1 }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ $$lon, $$lat ] } }\n"; }' > tests/parallel/in1.json
|
||||
perl -e 'for ($$i = 0; $$i < 300000; $$i++) { $$lon = rand(360) - 180; $$lat = rand(180) - 90; print "{ \"type\": \"Feature\", \"properties\": { }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ $$lon, $$lat ] } }\n"; }' > tests/parallel/in2.json
|
||||
perl -e 'for ($$i = 0; $$i < 20; $$i++) { $$lon = rand(360) - 180; $$lat = rand(180) - 90; print "{ \"type\": \"Feature\", \"properties\": { }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ $$lon, $$lat ] } }\n"; }' > tests/parallel/in3.json
|
||||
perl -e 'for ($$i = 0; $$i < 20; $$i++) { $$lon = rand(360) - 180; $$lat = rand(180) - 90; $$v = rand(1); print "{ \"type\": \"Feature\", \"properties\": { }, \"tippecanoe\": { \"layer\": \"$$v\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ $$lon, $$lat ] } }\n"; }' > tests/parallel/in4.json
|
||||
echo -n "" > tests/parallel/empty1.json
|
||||
echo "" > tests/parallel/empty2.json
|
||||
./tippecanoe -q -z5 -f -pi -l test -n test -o tests/parallel/linear-file.mbtiles tests/parallel/in[1234].json tests/parallel/empty[12].json
|
||||
./tippecanoe -q -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-file.mbtiles tests/parallel/in[1234].json tests/parallel/empty[12].json
|
||||
cat tests/parallel/in[1234].json | ./tippecanoe -q -z5 -f -pi -l test -n test -o tests/parallel/linear-pipe.mbtiles
|
||||
cat tests/parallel/in[1234].json | ./tippecanoe -q -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-pipe.mbtiles
|
||||
cat tests/parallel/in[1234].json | sed 's/^/@/' | tr '@' '\036' | ./tippecanoe -q -z5 -f -pi -l test -n test -o tests/parallel/implicit-pipe.mbtiles
|
||||
./tippecanoe -q -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-pipes.mbtiles <(cat tests/parallel/in1.json) <(cat tests/parallel/empty1.json) <(cat tests/parallel/empty2.json) <(cat tests/parallel/in2.json) /dev/null <(cat tests/parallel/in3.json) <(cat tests/parallel/in4.json)
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/linear-file.mbtiles > tests/parallel/linear-file.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/parallel-file.mbtiles > tests/parallel/parallel-file.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/linear-pipe.mbtiles > tests/parallel/linear-pipe.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/parallel-pipe.mbtiles > tests/parallel/parallel-pipe.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/implicit-pipe.mbtiles > tests/parallel/implicit-pipe.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/parallel/parallel-pipes.mbtiles > tests/parallel/parallel-pipes.json
|
||||
./tippecanoe -z5 -f -pi -l test -n test -o tests/parallel/linear-file.mbtiles tests/parallel/in[123].json tests/parallel/empty[12].json
|
||||
./tippecanoe -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-file.mbtiles tests/parallel/in[123].json tests/parallel/empty[12].json
|
||||
cat tests/parallel/in[123].json | ./tippecanoe -z5 -f -pi -l test -n test -o tests/parallel/linear-pipe.mbtiles
|
||||
cat tests/parallel/in[123].json | ./tippecanoe -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-pipe.mbtiles
|
||||
./tippecanoe -z5 -f -pi -l test -n test -P -o tests/parallel/parallel-pipes.mbtiles <(cat tests/parallel/in1.json) <(cat tests/parallel/empty1.json) <(cat tests/parallel/empty2.json) <(cat tests/parallel/in2.json) /dev/null <(cat tests/parallel/in3.json)
|
||||
./tippecanoe-decode tests/parallel/linear-file.mbtiles > tests/parallel/linear-file.json
|
||||
./tippecanoe-decode tests/parallel/parallel-file.mbtiles > tests/parallel/parallel-file.json
|
||||
./tippecanoe-decode tests/parallel/linear-pipe.mbtiles > tests/parallel/linear-pipe.json
|
||||
./tippecanoe-decode tests/parallel/parallel-pipe.mbtiles > tests/parallel/parallel-pipe.json
|
||||
./tippecanoe-decode tests/parallel/parallel-pipes.mbtiles > tests/parallel/parallel-pipes.json
|
||||
cmp tests/parallel/linear-file.json tests/parallel/parallel-file.json
|
||||
cmp tests/parallel/linear-file.json tests/parallel/linear-pipe.json
|
||||
cmp tests/parallel/linear-file.json tests/parallel/parallel-pipe.json
|
||||
cmp tests/parallel/linear-file.json tests/parallel/implicit-pipe.json
|
||||
cmp tests/parallel/linear-file.json tests/parallel/parallel-pipes.json
|
||||
rm tests/parallel/*.mbtiles tests/parallel/*.json
|
||||
|
||||
raw-tiles-test:
|
||||
./tippecanoe -q -f -e tests/raw-tiles/raw-tiles -r1 -pC tests/raw-tiles/hackspots.geojson
|
||||
./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles > tests/raw-tiles/raw-tiles.json.check
|
||||
cmp tests/raw-tiles/raw-tiles.json.check tests/raw-tiles/raw-tiles.json
|
||||
# Test that -z and -Z work in tippecanoe-decode
|
||||
./tippecanoe-decode -x generator -Z6 -z7 tests/raw-tiles/raw-tiles > tests/raw-tiles/raw-tiles-z67.json.check
|
||||
cmp tests/raw-tiles/raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67.json
|
||||
# Test that -z and -Z work in tile-join
|
||||
./tile-join -q -f -Z6 -z7 -e tests/raw-tiles/raw-tiles-z67 tests/raw-tiles/raw-tiles
|
||||
./tippecanoe-decode -x generator tests/raw-tiles/raw-tiles-z67 > tests/raw-tiles/raw-tiles-z67-join.json.check
|
||||
cmp tests/raw-tiles/raw-tiles-z67-join.json.check tests/raw-tiles/raw-tiles-z67-join.json
|
||||
rm -rf tests/raw-tiles/raw-tiles tests/raw-tiles/raw-tiles-z67 tests/raw-tiles/raw-tiles.json.check raw-tiles-z67.json.check tests/raw-tiles/raw-tiles-z67-join.json.check
|
||||
# Test that metadata.json is created even if all features are clipped away
|
||||
./tippecanoe -q -f -e tests/raw-tiles/nothing tests/raw-tiles/nothing.geojson
|
||||
./tippecanoe-decode -x generator tests/raw-tiles/nothing > tests/raw-tiles/nothing.json.check
|
||||
cmp tests/raw-tiles/nothing.json.check tests/raw-tiles/nothing.json
|
||||
rm -r tests/raw-tiles/nothing tests/raw-tiles/nothing.json.check
|
||||
|
||||
decode-test:
|
||||
mkdir -p tests/muni/decode
|
||||
./tippecanoe -q -z11 -Z11 -f -o tests/muni/decode/multi.mbtiles tests/muni/*.json
|
||||
./tippecanoe-decode -x generator -l subway tests/muni/decode/multi.mbtiles > tests/muni/decode/multi.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator -c tests/muni/decode/multi.mbtiles > tests/muni/decode/multi.mbtiles.pipeline.json.check
|
||||
./tippecanoe-decode -x generator tests/muni/decode/multi.mbtiles 11 327 791 > tests/muni/decode/multi.mbtiles.onetile.json.check
|
||||
./tippecanoe-decode -x generator --stats tests/muni/decode/multi.mbtiles > tests/muni/decode/multi.mbtiles.stats.json.check
|
||||
cmp tests/muni/decode/multi.mbtiles.json.check tests/muni/decode/multi.mbtiles.json
|
||||
cmp tests/muni/decode/multi.mbtiles.pipeline.json.check tests/muni/decode/multi.mbtiles.pipeline.json
|
||||
cmp tests/muni/decode/multi.mbtiles.onetile.json.check tests/muni/decode/multi.mbtiles.onetile.json
|
||||
cmp tests/muni/decode/multi.mbtiles.stats.json.check tests/muni/decode/multi.mbtiles.stats.json
|
||||
rm -f tests/muni/decode/multi.mbtiles.json.check tests/muni/decode/multi.mbtiles tests/muni/decode/multi.mbtiles.pipeline.json.check tests/muni/decode/multi.mbtiles.stats.json.check tests/muni/decode/multi.mbtiles.onetile.json.check
|
||||
|
||||
pbf-test:
|
||||
./tippecanoe-decode -x generator tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.vector.pbf.out
|
||||
./tippecanoe-decode tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.vector.pbf.out
|
||||
cmp tests/pbf/11-328-791.json tests/pbf/11-328-791.vector.pbf.out
|
||||
rm tests/pbf/11-328-791.vector.pbf.out
|
||||
./tippecanoe-decode -x generator -s EPSG:3857 tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.3857.vector.pbf.out
|
||||
./tippecanoe-decode -t EPSG:3857 tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.3857.vector.pbf.out
|
||||
cmp tests/pbf/11-328-791.3857.json tests/pbf/11-328-791.3857.vector.pbf.out
|
||||
rm tests/pbf/11-328-791.3857.vector.pbf.out
|
||||
|
||||
enumerate-test:
|
||||
./tippecanoe -q -z5 -f -o tests/ne_110m_admin_0_countries/out/enum.mbtiles tests/ne_110m_admin_0_countries/in.json.gz
|
||||
./tippecanoe -z5 -f -o tests/ne_110m_admin_0_countries/out/enum.mbtiles tests/ne_110m_admin_0_countries/in.json
|
||||
./tippecanoe-enumerate tests/ne_110m_admin_0_countries/out/enum.mbtiles > tests/ne_110m_admin_0_countries/out/enum.check
|
||||
cmp tests/ne_110m_admin_0_countries/out/enum tests/ne_110m_admin_0_countries/out/enum.check
|
||||
rm tests/ne_110m_admin_0_countries/out/enum.mbtiles tests/ne_110m_admin_0_countries/out/enum.check
|
||||
|
||||
join-test: 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"}'
|
||||
./tippecanoe -q -f -Z5 -z10 -o tests/join-population/macarthur.mbtiles -l macarthur tests/join-population/macarthur.json
|
||||
./tile-join -q -f -Z6 -z9 -o tests/join-population/macarthur-6-9.mbtiles tests/join-population/macarthur.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/macarthur-6-9.mbtiles > tests/join-population/macarthur-6-9.mbtiles.json.check
|
||||
cmp tests/join-population/macarthur-6-9.mbtiles.json.check tests/join-population/macarthur-6-9.mbtiles.json
|
||||
./tile-join -q -f -Z6 -z9 -X -o tests/join-population/macarthur-6-9-exclude.mbtiles tests/join-population/macarthur.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/macarthur-6-9-exclude.mbtiles > tests/join-population/macarthur-6-9-exclude.mbtiles.json.check
|
||||
cmp tests/join-population/macarthur-6-9-exclude.mbtiles.json.check tests/join-population/macarthur-6-9-exclude.mbtiles.json
|
||||
rm -f tests/join-population/macarthur-6-9.mbtiles.json.check tests/join-population/macarthur-6-9.mbtiles tests/join-population/macarthur-6-9-exclude.mbtiles.json.check tests/join-population/macarthur-6-9-exclude.mbtiles
|
||||
./tippecanoe -q -f -d10 -D10 -Z9 -z11 -o tests/join-population/macarthur2.mbtiles -l macarthur tests/join-population/macarthur2.json
|
||||
./tile-join --quiet --force -o tests/join-population/joined.mbtiles -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join --quiet --force -o tests/join-population/joined-null.mbtiles --empty-csv-columns-are-null -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join --quiet --force --no-tile-stats -o tests/join-population/joined-no-tile-stats.mbtiles -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join -q -f -i -o tests/join-population/joined-i.mbtiles -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join -q -f -o tests/join-population/merged.mbtiles tests/join-population/tabblock_06001420.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
./tile-join -q -f -c tests/join-population/windows.csv -o tests/join-population/windows.mbtiles tests/join-population/macarthur.mbtiles
|
||||
./tippecanoe-decode -x generator --maximum-zoom=11 --minimum-zoom=4 tests/join-population/joined.mbtiles > tests/join-population/joined.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator --maximum-zoom=11 --minimum-zoom=4 tests/join-population/joined-null.mbtiles > tests/join-population/joined-null.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator --maximum-zoom=11 --minimum-zoom=4 tests/join-population/joined-no-tile-stats.mbtiles > tests/join-population/joined-no-tile-stats.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator tests/join-population/joined-i.mbtiles > tests/join-population/joined-i.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator tests/join-population/merged.mbtiles > tests/join-population/merged.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator tests/join-population/windows.mbtiles > tests/join-population/windows.mbtiles.json.check
|
||||
join-test:
|
||||
./tippecanoe -f -z12 -o tests/join-population/tabblock_06001420.mbtiles tests/join-population/tabblock_06001420.json
|
||||
./tippecanoe -f -z12 -o tests/join-population/tabblock_06001420.mbtiles tests/join-population/tabblock_06001420.json
|
||||
./tippecanoe -f -Z5 -z10 -o tests/join-population/macarthur.mbtiles -l macarthur tests/join-population/macarthur.json
|
||||
./tippecanoe -f -d10 -D10 -Z9 -z11 -o tests/join-population/macarthur2.mbtiles -l macarthur tests/join-population/macarthur2.json
|
||||
./tile-join -f -o tests/join-population/joined.mbtiles -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join -f -i -o tests/join-population/joined-i.mbtiles -x GEOID10 -c tests/join-population/population.csv tests/join-population/tabblock_06001420.mbtiles
|
||||
./tile-join -f -o tests/join-population/merged.mbtiles tests/join-population/tabblock_06001420.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
./tippecanoe-decode tests/join-population/joined.mbtiles > tests/join-population/joined.mbtiles.json.check
|
||||
./tippecanoe-decode tests/join-population/joined-i.mbtiles > tests/join-population/joined-i.mbtiles.json.check
|
||||
./tippecanoe-decode tests/join-population/merged.mbtiles > tests/join-population/merged.mbtiles.json.check
|
||||
cmp tests/join-population/joined.mbtiles.json.check tests/join-population/joined.mbtiles.json
|
||||
cmp tests/join-population/joined-null.mbtiles.json.check tests/join-population/joined-null.mbtiles.json
|
||||
cmp tests/join-population/joined-no-tile-stats.mbtiles.json.check tests/join-population/joined-no-tile-stats.mbtiles.json
|
||||
cmp tests/join-population/joined-i.mbtiles.json.check tests/join-population/joined-i.mbtiles.json
|
||||
cmp tests/join-population/merged.mbtiles.json.check tests/join-population/merged.mbtiles.json
|
||||
cmp tests/join-population/windows.mbtiles.json.check tests/join-population/windows.mbtiles.json
|
||||
rm -f tests/join-population/joined-null.mbtiles tests/join-population/joined-null.mbtiles.json.check
|
||||
./tile-join -q -f -l macarthur -n "macarthur name" -N "macarthur description" -A "macarthur's attribution" -o tests/join-population/just-macarthur.mbtiles tests/join-population/merged.mbtiles
|
||||
./tile-join -q -f -L macarthur -o tests/join-population/no-macarthur.mbtiles tests/join-population/merged.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/just-macarthur.mbtiles > tests/join-population/just-macarthur.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator tests/join-population/no-macarthur.mbtiles > tests/join-population/no-macarthur.mbtiles.json.check
|
||||
cmp tests/join-population/just-macarthur.mbtiles.json.check tests/join-population/just-macarthur.mbtiles.json
|
||||
cmp tests/join-population/no-macarthur.mbtiles.json.check tests/join-population/no-macarthur.mbtiles.json
|
||||
./tile-join -q --no-tile-compression -f -e tests/join-population/raw-merged-folder tests/join-population/tabblock_06001420.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/raw-merged-folder > tests/join-population/raw-merged-folder.json.check
|
||||
cmp tests/join-population/raw-merged-folder.json.check tests/join-population/raw-merged-folder.json
|
||||
rm -f tests/join-population/raw-merged-folder.json.check
|
||||
./tippecanoe -q -z12 -f -e tests/join-population/tabblock_06001420-folder -YALAND10:'Land area' -L'{"file": "tests/join-population/tabblock_06001420.json", "description": "population"}'
|
||||
./tippecanoe -q -Z5 -z10 -f -e tests/join-population/macarthur-folder -l macarthur tests/join-population/macarthur.json
|
||||
./tippecanoe -q -d10 -D10 -Z9 -z11 -f -e tests/join-population/macarthur2-folder -l macarthur tests/join-population/macarthur2.json
|
||||
./tile-join -q -f -o tests/join-population/merged-folder.mbtiles tests/join-population/tabblock_06001420-folder tests/join-population/macarthur-folder tests/join-population/macarthur2-folder
|
||||
./tippecanoe-decode -x generator tests/join-population/merged-folder.mbtiles > tests/join-population/merged-folder.mbtiles.json.check
|
||||
cmp tests/join-population/merged-folder.mbtiles.json.check tests/join-population/merged-folder.mbtiles.json
|
||||
./tile-join -q -n "merged name" -N "merged description" -f -e tests/join-population/merged-mbtiles-to-folder tests/join-population/tabblock_06001420.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
./tile-join -q -n "merged name" -N "merged description" -f -e tests/join-population/merged-folders-to-folder tests/join-population/tabblock_06001420-folder tests/join-population/macarthur-folder tests/join-population/macarthur2-folder
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/merged-mbtiles-to-folder > tests/join-population/merged-mbtiles-to-folder.json.check
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/merged-folders-to-folder > tests/join-population/merged-folders-to-folder.json.check
|
||||
cmp tests/join-population/merged-mbtiles-to-folder.json.check tests/join-population/merged-folders-to-folder.json.check
|
||||
rm -f tests/join-population/merged-mbtiles-to-folder.json.check tests/join-population/merged-folders-to-folder.json.check
|
||||
./tile-join -q -f -c tests/join-population/windows.csv -o tests/join-population/windows-merged.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2-folder
|
||||
./tile-join -q -c tests/join-population/windows.csv -f -e tests/join-population/windows-merged-folder tests/join-population/macarthur.mbtiles tests/join-population/macarthur2-folder
|
||||
./tile-join -q -f -o tests/join-population/windows-merged2.mbtiles tests/join-population/windows-merged-folder
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/windows-merged.mbtiles > tests/join-population/windows-merged.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/windows-merged2.mbtiles > tests/join-population/windows-merged2.mbtiles.json.check
|
||||
cmp tests/join-population/windows-merged.mbtiles.json.check tests/join-population/windows-merged2.mbtiles.json.check
|
||||
./tile-join -q -f -o tests/join-population/macarthur-and-macarthur2-merged.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2-folder
|
||||
./tile-join -q -f -e tests/join-population/macarthur-and-macarthur2-folder tests/join-population/macarthur.mbtiles tests/join-population/macarthur2-folder
|
||||
./tile-join -q -f -o tests/join-population/macarthur-and-macarthur2-merged2.mbtiles tests/join-population/macarthur-and-macarthur2-folder
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/macarthur-and-macarthur2-merged.mbtiles > tests/join-population/macarthur-and-macarthur2-merged.mbtiles.json.check
|
||||
./tippecanoe-decode -x generator -x generator_options tests/join-population/macarthur-and-macarthur2-merged2.mbtiles > tests/join-population/macarthur-and-macarthur2-merged2.mbtiles.json.check
|
||||
cmp tests/join-population/macarthur-and-macarthur2-merged.mbtiles.json.check tests/join-population/macarthur-and-macarthur2-merged2.mbtiles.json.check
|
||||
rm tests/join-population/tabblock_06001420.mbtiles tests/join-population/joined.mbtiles tests/join-population/joined-i.mbtiles tests/join-population/joined.mbtiles.json.check tests/join-population/joined-i.mbtiles.json.check tests/join-population/macarthur.mbtiles tests/join-population/merged.mbtiles tests/join-population/merged.mbtiles.json.check tests/join-population/merged-folder.mbtiles tests/join-population/macarthur2.mbtiles tests/join-population/windows.mbtiles tests/join-population/windows-merged.mbtiles tests/join-population/windows-merged2.mbtiles tests/join-population/windows.mbtiles.json.check tests/join-population/just-macarthur.mbtiles tests/join-population/no-macarthur.mbtiles tests/join-population/just-macarthur.mbtiles.json.check tests/join-population/no-macarthur.mbtiles.json.check tests/join-population/merged-folder.mbtiles.json.check tests/join-population/windows-merged.mbtiles.json.check tests/join-population/windows-merged2.mbtiles.json.check tests/join-population/macarthur-and-macarthur2-merged.mbtiles tests/join-population/macarthur-and-macarthur2-merged2.mbtiles tests/join-population/macarthur-and-macarthur2-merged.mbtiles.json.check tests/join-population/macarthur-and-macarthur2-merged2.mbtiles.json.check
|
||||
rm -rf tests/join-population/raw-merged-folder tests/join-population/tabblock_06001420-folder tests/join-population/macarthur-folder tests/join-population/macarthur2-folder tests/join-population/merged-mbtiles-to-folder tests/join-population/merged-folders-to-folder tests/join-population/windows-merged-folder tests/join-population/macarthur-and-macarthur2-folder
|
||||
# Test renaming of layers
|
||||
./tippecanoe -q -f -Z5 -z10 -o tests/join-population/macarthur.mbtiles -l macarthur1 tests/join-population/macarthur.json
|
||||
./tippecanoe -q -f -Z5 -z10 -o tests/join-population/macarthur2.mbtiles -l macarthur2 tests/join-population/macarthur2.json
|
||||
./tile-join -q -R macarthur1:one --rename-layer=macarthur2:two -f -o tests/join-population/renamed.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/renamed.mbtiles > tests/join-population/renamed.mbtiles.json.check
|
||||
cmp tests/join-population/renamed.mbtiles.json.check tests/join-population/renamed.mbtiles.json
|
||||
rm -f tests/join-population/renamed.mbtiles.json.check tests/join-population/renamed.mbtiles.json.check tests/join-population/macarthur.mbtiles tests/join-population/macarthur2.mbtiles
|
||||
# Make sure the concatenated name isn't too long
|
||||
./tippecanoe -q -f -z0 -n 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' -o tests/join-population/macarthur.mbtiles tests/join-population/macarthur.json
|
||||
./tile-join -f -o tests/join-population/concat.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur.mbtiles tests/join-population/macarthur.mbtiles
|
||||
./tippecanoe-decode -x generator tests/join-population/concat.mbtiles > tests/join-population/concat.mbtiles.json.check
|
||||
cmp tests/join-population/concat.mbtiles.json.check tests/join-population/concat.mbtiles.json
|
||||
rm tests/join-population/concat.mbtiles.json.check tests/join-population/concat.mbtiles tests/join-population/macarthur.mbtiles
|
||||
|
||||
join-filter-test:
|
||||
# Comes out different from the direct tippecanoe run because null attributes are lost
|
||||
./tippecanoe -q -z0 -f -o tests/feature-filter/out/all.mbtiles tests/feature-filter/in.json
|
||||
./tile-join -q -J tests/feature-filter/filter -f -o tests/feature-filter/out/filtered.mbtiles tests/feature-filter/out/all.mbtiles
|
||||
./tippecanoe-decode -x generator tests/feature-filter/out/filtered.mbtiles > tests/feature-filter/out/filtered.json.check
|
||||
cmp tests/feature-filter/out/filtered.json.check tests/feature-filter/out/filtered.json.standard
|
||||
rm -f tests/feature-filter/out/filtered.json.check tests/feature-filter/out/filtered.mbtiles tests/feature-filter/out/all.mbtiles
|
||||
# Test zoom level filtering
|
||||
./tippecanoe -q -r1 -z8 -f -o tests/feature-filter/out/places.mbtiles tests/ne_110m_populated_places/in.json
|
||||
./tile-join -q -J tests/feature-filter/places-filter -f -o tests/feature-filter/out/places-filter.mbtiles tests/feature-filter/out/places.mbtiles
|
||||
./tippecanoe-decode -x generator tests/feature-filter/out/places-filter.mbtiles > tests/feature-filter/out/places-filter.mbtiles.json.check
|
||||
cmp tests/feature-filter/out/places-filter.mbtiles.json.check tests/feature-filter/out/places-filter.mbtiles.json.standard
|
||||
rm -f tests/feature-filter/out/places.mbtiles tests/feature-filter/out/places-filter.mbtiles tests/feature-filter/out/places-filter.mbtiles.json.check
|
||||
|
||||
json-tool-test: tippecanoe-json-tool
|
||||
./tippecanoe-json-tool -e GEOID10 tests/join-population/tabblock_06001420.json | sort > tests/join-population/tabblock_06001420.json.sort
|
||||
./tippecanoe-json-tool -c tests/join-population/population.csv tests/join-population/tabblock_06001420.json.sort > tests/join-population/tabblock_06001420.json.sort.joined
|
||||
./tippecanoe-json-tool --empty-csv-columns-are-null -c tests/join-population/population.csv tests/join-population/tabblock_06001420.json.sort > tests/join-population/tabblock_06001420-null.json.sort.joined
|
||||
cmp tests/join-population/tabblock_06001420.json.sort.joined tests/join-population/tabblock_06001420.json.sort.joined.standard
|
||||
cmp tests/join-population/tabblock_06001420-null.json.sort.joined tests/join-population/tabblock_06001420-null.json.sort.joined.standard
|
||||
rm -f tests/join-population/tabblock_06001420.json.sort tests/join-population/tabblock_06001420.json.sort.joined
|
||||
rm -f tests/join-population/tabblock_06001420-null.json.sort.joined
|
||||
|
||||
allow-existing-test:
|
||||
# Make a tileset
|
||||
./tippecanoe -q -Z0 -z0 -f -o tests/allow-existing/both.mbtiles tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
# Writing to existing should fail
|
||||
if ./tippecanoe -q -Z1 -z1 -o tests/allow-existing/both.mbtiles tests/coalesce-tract/tl_2010_06001_tract10.json; then exit 1; else exit 0; fi
|
||||
# Replace existing
|
||||
./tippecanoe -q -Z8 -z9 -f -o tests/allow-existing/both.mbtiles tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
./tippecanoe -q -Z10 -z11 -F -o tests/allow-existing/both.mbtiles tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/allow-existing/both.mbtiles > tests/allow-existing/both.mbtiles.json.check
|
||||
cmp tests/allow-existing/both.mbtiles.json.check tests/allow-existing/both.mbtiles.json
|
||||
# Make a tileset
|
||||
./tippecanoe -q -Z0 -z0 -f -e tests/allow-existing/both.dir tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
# Writing to existing should fail
|
||||
if ./tippecanoe -q -Z1 -z1 -e tests/allow-existing/both.dir tests/coalesce-tract/tl_2010_06001_tract10.json; then exit 1; else exit 0; fi
|
||||
# Replace existing
|
||||
./tippecanoe -q -Z8 -z9 -f -e tests/allow-existing/both.dir tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
./tippecanoe -q -Z10 -z11 -F -e tests/allow-existing/both.dir tests/coalesce-tract/tl_2010_06001_tract10.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/allow-existing/both.dir | sed 's/both\.dir/both.mbtiles/g' > tests/allow-existing/both.dir.json.check
|
||||
cmp tests/allow-existing/both.dir.json.check tests/allow-existing/both.mbtiles.json
|
||||
rm -r tests/allow-existing/both.dir.json.check tests/allow-existing/both.dir tests/allow-existing/both.mbtiles.json.check tests/allow-existing/both.mbtiles
|
||||
|
||||
csv-test:
|
||||
# Reading from named CSV
|
||||
./tippecanoe -q -zg -f -o tests/csv/out.mbtiles tests/csv/ne_110m_populated_places_simple.csv
|
||||
./tippecanoe-decode -x generator -x generator_options tests/csv/out.mbtiles > tests/csv/out.mbtiles.json.check
|
||||
cmp tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles.json
|
||||
rm -f tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles
|
||||
# Reading from named CSV, with nulls
|
||||
./tippecanoe -q --empty-csv-columns-are-null -zg -f -o tests/csv/out-null.mbtiles tests/csv/ne_110m_populated_places_simple.csv
|
||||
./tippecanoe-decode -x generator tests/csv/out-null.mbtiles > tests/csv/out-null.mbtiles.json.check
|
||||
cmp tests/csv/out-null.mbtiles.json.check tests/csv/out-null.mbtiles.json
|
||||
rm -f tests/csv/out-null.mbtiles.json.check tests/csv/out-null.mbtiles
|
||||
# Same, but specifying csv with -L format
|
||||
./tippecanoe -q -zg -f -o tests/csv/out.mbtiles -L'{"file":"", "format":"csv", "layer":"ne_110m_populated_places_simple"}' < tests/csv/ne_110m_populated_places_simple.csv
|
||||
./tippecanoe-decode -x generator -x generator_options tests/csv/out.mbtiles > tests/csv/out.mbtiles.json.check
|
||||
cmp tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles.json
|
||||
rm -f tests/csv/out.mbtiles.json.check tests/csv/out.mbtiles
|
||||
|
||||
layer-json-test:
|
||||
# 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"}'
|
||||
./tippecanoe-decode -x generator -x generator_options tests/layer-json/out.mbtiles > tests/layer-json/out.mbtiles.json.check
|
||||
cmp tests/layer-json/out.mbtiles.json.check tests/layer-json/out.mbtiles.json
|
||||
rm -f tests/layer-json/out.mbtiles.json.check tests/layer-json/out.mbtiles
|
||||
# Same, but reading from the standard input
|
||||
./tippecanoe -q -z0 -r1 -yNAME -f -o tests/layer-json/out.mbtiles -L'{"file":"", "description":"World cities", "layer":"places"}' < tests/ne_110m_populated_places/in.json
|
||||
./tippecanoe-decode -x generator -x generator_options tests/layer-json/out.mbtiles > tests/layer-json/out.mbtiles.json.check
|
||||
cmp tests/layer-json/out.mbtiles.json.check tests/layer-json/out.mbtiles.json
|
||||
rm -f tests/layer-json/out.mbtiles.json.check tests/layer-json/out.mbtiles
|
||||
rm tests/join-population/tabblock_06001420.mbtiles tests/join-population/joined.mbtiles tests/join-population/joined-i.mbtiles tests/join-population/joined.mbtiles.json.check tests/join-population/joined-i.mbtiles.json.check tests/join-population/macarthur.mbtiles tests/join-population/merged.mbtiles tests/join-population/merged.mbtiles.json.check tests/join-population/macarthur2.mbtiles
|
||||
|
||||
# Use this target to regenerate the standards that the tests are compared against
|
||||
# after making a change that legitimately changes their output
|
||||
@ -342,7 +144,7 @@ layer-json-test:
|
||||
prep-test: $(TESTS)
|
||||
|
||||
tests/%.json: Makefile tippecanoe tippecanoe-decode
|
||||
./tippecanoe -q -a@ -f -o $@.check.mbtiles $(subst @,:,$(subst %,/,$(subst _, ,$(patsubst %.json,%,$(word 4,$(subst /, ,$@)))))) $(foreach suffix,$(suffixes),$(sort $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.$(suffix))))
|
||||
./tippecanoe-decode -x generator $@.check.mbtiles > $@
|
||||
./tippecanoe -f -o $@.check.mbtiles $(subst @,:,$(subst %,/,$(subst _, ,$(patsubst %.json,%,$(word 4,$(subst /, ,$@)))))) $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json)
|
||||
./tippecanoe-decode $@.check.mbtiles > $@
|
||||
cmp $(patsubst %.check,%,$@) $@
|
||||
rm $@.check.mbtiles
|
||||
|
802
README.md
802
README.md
@ -1,30 +1,11 @@
|
||||
tippecanoe
|
||||
==========
|
||||
|
||||
**Note**: there is an active fork of this project over at https://github.com/felt/tippecanoe
|
||||
|
||||
Builds [vector tilesets](https://www.mapbox.com/developers/vector-tiles/) from large (or small) collections of [GeoJSON](http://geojson.org/), [Geobuf](https://github.com/mapbox/geobuf), or [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) features,
|
||||
Builds [vector tilesets](https://www.mapbox.com/developers/vector-tiles/) from large (or small) collections of [GeoJSON](http://geojson.org/) features,
|
||||
[like these](MADE_WITH.md).
|
||||
|
||||

|
||||
|
||||
[](https://travis-ci.org/mapbox/tippecanoe)
|
||||
[](https://codecov.io/gh/mapbox/tippecanoe)
|
||||
|
||||
### :zap: Mapbox has a new service for creating vector tilesets! :zap:
|
||||
|
||||
[Mapbox Tiling Service (MTS)](https://docs.mapbox.com/mapbox-tiling-service/overview/) is a hosted, data processing service that allows you to integrate custom datasets of any scale into your maps faster, cheaper, and with more flexibility and control than previously possible.
|
||||
|
||||
MTS is the same service we use internally to create our global, daily updating basemap product Mapbox Streets, which serves over 650 million monthly active users and customers such as Facebook, Snap, the Weather Channel, Tableau, and Shopify.
|
||||
|
||||
MTS creates and updates data using distributed and parallelized processing, meaning data is processed much more quickly than is possible with a standard, single server setup with comparable tools. For example, a global basemap at 30cm precision (max zoom of 16) can be processed in under 2 hours with MTS, whereas a comparable workload would take multiple days to process on a single server.
|
||||
|
||||
Customers like AllTrails, Plume Labs, and Ookla have noted that MTS helps them:
|
||||
- build applications faster by focusing more on app development, not infrastructure
|
||||
- build more compelling user experiences that drive better user engagement
|
||||
- get updated data to their users faster—in some cases up to 90% faster than previous tools
|
||||
|
||||
Learn more about [MTS](https://blog.mapbox.com/introducing-mapbox-tiling-service-df1df636c7cf).
|
||||
[](https://coveralls.io/github/mapbox/tippecanoe?branch=master)
|
||||
|
||||
Intent
|
||||
------
|
||||
@ -52,28 +33,15 @@ Installation
|
||||
|
||||
The easiest way to install tippecanoe on OSX is with [Homebrew](http://brew.sh/):
|
||||
|
||||
```sh
|
||||
```js
|
||||
$ brew install tippecanoe
|
||||
```
|
||||
|
||||
On Ubuntu it will usually be easiest to build from the source repository:
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/mapbox/tippecanoe.git
|
||||
$ cd tippecanoe
|
||||
$ make -j
|
||||
$ make install
|
||||
```
|
||||
|
||||
See [Development](#development) below for how to upgrade your
|
||||
C++ compiler or install prerequisite packages if you get
|
||||
compiler errors.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
```sh
|
||||
$ tippecanoe -o file.mbtiles [options] [file.json file.json.gz file.geobuf ...]
|
||||
$ tippecanoe -o file.mbtiles [file.json ...]
|
||||
```
|
||||
|
||||
If no files are specified, it reads GeoJSON from the standard input.
|
||||
@ -84,525 +52,112 @@ You can concatenate multiple GeoJSON features or files together,
|
||||
and it will parse out the features and ignore whatever other objects
|
||||
it encounters.
|
||||
|
||||
Try this first
|
||||
--------------
|
||||
|
||||
If you aren't sure what options to use, try this:
|
||||
|
||||
```sh
|
||||
$ tippecanoe -zg -o out.mbtiles --drop-densest-as-needed in.geojson
|
||||
```
|
||||
|
||||
The `-zg` option will make Tippecanoe choose a maximum zoom level that should be
|
||||
high enough to reflect the precision of the original data. (If it turns out still
|
||||
not to be as detailed as you want, use `-z` manually with a higher number.)
|
||||
|
||||
If the tiles come out too big, the `--drop-densest-as-needed` option will make
|
||||
Tippecanoe try dropping what should be the least visible features at each zoom level.
|
||||
(If it drops too many features, use `-x` to leave out some feature attributes that
|
||||
you didn't really need.)
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
Create a tileset of TIGER roads for Alameda County, to zoom level 13, with a custom layer name and description:
|
||||
|
||||
```sh
|
||||
$ tippecanoe -o alameda.mbtiles -l alameda -n "Alameda County from TIGER" -z13 tl_2014_06001_roads.json
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
$ 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
|
||||
```
|
||||
|
||||
Cookbook
|
||||
--------
|
||||
|
||||
### Linear features (world railroads), visible at all zoom levels
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
tippecanoe -zg -o ne_10m_railroads.mbtiles --drop-densest-as-needed --extend-zooms-if-still-dropping ne_10m_railroads.geojson
|
||||
```
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--drop-densest-as-needed`: If the tiles are too big at low zoom levels, drop the least-visible features to allow tiles to be created with those features that remain
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Discontinuous polygon features (buildings of Rhode Island), visible at all zoom levels
|
||||
|
||||
```
|
||||
curl -L -O https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/RhodeIsland.zip
|
||||
unzip RhodeIsland.zip
|
||||
|
||||
tippecanoe -zg -o RhodeIsland.mbtiles --drop-densest-as-needed --extend-zooms-if-still-dropping RhodeIsland.geojson
|
||||
```
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--drop-densest-as-needed`: If the tiles are too big at low or medium zoom levels, drop the least-visible features to allow tiles to be created with those features that remain
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Continuous polygon features (states and provinces), visible at all zoom levels
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
tippecanoe -zg -o ne_10m_admin_1_states_provinces.mbtiles --coalesce-densest-as-needed --extend-zooms-if-still-dropping ne_10m_admin_1_states_provinces.geojson
|
||||
```
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--coalesce-densest-as-needed`: If the tiles are too big at low or medium zoom levels, merge as many features together as are necessary to allow tiles to be created with those features that are still distinguished
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Large point dataset (GPS bus locations), for visualization at all zoom levels
|
||||
|
||||
```
|
||||
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
|
||||
```
|
||||
|
||||
(The `sed` line is to clean the corrupt CSV header, which contains the wrong number of fields.)
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--drop-densest-as-needed`: If the tiles are too big at low or medium zoom levels, drop the least-visible features to allow tiles to be created with those features that remain
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Clustered points (world cities), summing the clustered population, visible at all zoom levels
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
tippecanoe -zg -o ne_10m_populated_places.mbtiles -r1 --cluster-distance=10 --accumulate-attribute=POP_MAX:sum ne_10m_populated_places.geojson
|
||||
```
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `-r1`: Do not automatically drop a fraction of points at low zoom levels, since clustering will be used instead
|
||||
* `--cluster-distance=10`: Cluster together features that are closer than about 10 pixels from each other
|
||||
* `--accumulate-attribute=POP_MAX:sum`: Sum the `POP_MAX` (population) attribute in features that are clustered together. Other attributes will be arbitrarily taken from the first feature in the cluster.
|
||||
|
||||
### Show countries at low zoom levels but states at higher zoom levels
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
tippecanoe -z3 -o countries-z3.mbtiles --coalesce-densest-as-needed ne_10m_admin_0_countries.geojson
|
||||
tippecanoe -zg -Z4 -o states-Z4.mbtiles --coalesce-densest-as-needed --extend-zooms-if-still-dropping ne_10m_admin_1_states_provinces.geojson
|
||||
tile-join -o states-countries.mbtiles countries-z3.mbtiles states-Z4.mbtiles
|
||||
```
|
||||
|
||||
Countries:
|
||||
|
||||
* `-z3`: Only generate zoom levels 0 through 3
|
||||
* `--coalesce-densest-as-needed`: If the tiles are too big at low or medium zoom levels, merge as many features together as are necessary to allow tiles to be created with those features that are still distinguished
|
||||
|
||||
States and Provinces:
|
||||
|
||||
* `-Z4`: Only generate zoom levels 4 and beyond
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--coalesce-densest-as-needed`: If the tiles are too big at low or medium zoom levels, merge as many features together as are necessary to allow tiles to be created with those features that are still distinguished
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Represent multiple sources (Illinois and Indiana counties) as separate layers
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/COUNTY/2010/tl_2010_18_county10.zip
|
||||
unzip tl_2010_18_county10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_18_county10.geojson tl_2010_18_county10.shp
|
||||
|
||||
tippecanoe -zg -o counties-separate.mbtiles --coalesce-densest-as-needed --extend-zooms-if-still-dropping tl_2010_17_county10.geojson tl_2010_18_county10.geojson
|
||||
```
|
||||
|
||||
* `-zg`: Automatically choose a maxzoom that should be sufficient to clearly distinguish the features and the detail within each feature
|
||||
* `--coalesce-densest-as-needed`: If the tiles are too big at low or medium zoom levels, merge as many features together as are necessary to allow tiles to be created with those features that are still distinguished
|
||||
* `--extend-zooms-if-still-dropping`: If even the tiles at high zoom levels are too big, keep adding zoom levels until one is reached that can represent all the features
|
||||
|
||||
### Merge multiple sources (Illinois and Indiana counties) into the same layer
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/COUNTY/2010/tl_2010_18_county10.zip
|
||||
unzip tl_2010_18_county10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_18_county10.geojson tl_2010_18_county10.shp
|
||||
|
||||
tippecanoe -zg -o counties-merged.mbtiles -l counties --coalesce-densest-as-needed --extend-zooms-if-still-dropping tl_2010_17_county10.geojson tl_2010_18_county10.geojson
|
||||
```
|
||||
|
||||
As above, but
|
||||
|
||||
* `-l counties`: Specify the layer name instead of letting it be derived from the source file names
|
||||
|
||||
### Selectively remove and replace features (Census tracts) to update a tileset
|
||||
|
||||
```
|
||||
# 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
|
||||
ogr2ogr -f GeoJSON tl_2010_06_tract00.shp.json tl_2010_06_tract00.shp
|
||||
tippecanoe -z11 -o tracts.mbtiles -l tracts tl_2010_06_tract00.shp.json
|
||||
|
||||
# Create a copy of the tileset, minus Alameda County (FIPS code 001)
|
||||
tile-join -j '{"*":["none",["==","COUNTYFP00","001"]]}' -f -o tracts-filtered.mbtiles tracts.mbtiles
|
||||
|
||||
# Retrieve and tile Alameda County Census tracts for 2010
|
||||
curl -L -O https://www2.census.gov/geo/tiger/TIGER2010/TRACT/2010/tl_2010_06001_tract10.zip
|
||||
unzip tl_2010_06001_tract10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_06001_tract10.shp.json tl_2010_06001_tract10.shp
|
||||
tippecanoe -z11 -o tracts-added.mbtiles -l tracts tl_2010_06001_tract10.shp.json
|
||||
|
||||
# Merge the filtered tileset and the tileset of new tracts into a final tileset
|
||||
tile-join -o tracts-final.mbtiles tracts-filtered.mbtiles tracts-added.mbtiles
|
||||
```
|
||||
|
||||
The `-z11` option explicitly specifies the maxzoom, to make sure both the old and new tilesets have the same zoom range.
|
||||
|
||||
The `-j` option to `tile-join` specifies a filter, so that only the desired features will be copied to the new tileset.
|
||||
This filter excludes (using `none`) any features whose FIPS code (`COUNTYFP00`) is the code for Alameda County (`001`).
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
There are a lot of options. A lot of the time you won't want to use any of them
|
||||
other than `-o` _output_`.mbtiles` to name the output file, and probably `-f` to
|
||||
delete the file that already exists with that name.
|
||||
### Naming
|
||||
|
||||
If you aren't sure what the right maxzoom is for your data, `-zg` will guess one for you
|
||||
based on the density of features.
|
||||
* -l _name_ or --layer=_name_: Layer name (default "file" if source is file.json or output is file.mbtiles). If there are multiple input files
|
||||
specified, the files are all merged into the single named layer, even if they try to specify individual names with -L.
|
||||
* -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.
|
||||
* -n _name_ or --name=_name_: Human-readable name for the tileset (default file.json)
|
||||
* -A _text_ or --attribution=_text_: Attribution (HTML) to be shown with maps that use data from this tileset.
|
||||
|
||||
Tippecanoe will normally drop a fraction of point features at zooms below the maxzoom,
|
||||
to keep the low-zoom tiles from getting too big. If you have a smaller data set where
|
||||
all the points would fit without dropping any of them, use `-r1` to keep them all.
|
||||
If you do want point dropping, but you still want the tiles to be denser than `-zg`
|
||||
thinks they should be, use `-B` to set a basezoom lower than the maxzoom.
|
||||
### File control
|
||||
|
||||
If some of your tiles are coming out too big in spite of the settings above, you will
|
||||
often want to use `--drop-densest-as-needed` to drop whatever fraction of the features
|
||||
is necessary at each zoom level to make that zoom level's tiles work.
|
||||
|
||||
If your features have a lot of attributes, use `-y` to keep only the ones you really need.
|
||||
|
||||
If your input is formatted as newline-delimited GeoJSON, use `-P` to make input parsing a lot faster.
|
||||
|
||||
### Output tileset
|
||||
|
||||
* `-o` _file_`.mbtiles` or `--output=`_file_`.mbtiles`: Name the output file.
|
||||
* `-e` _directory_ or `--output-to-directory`=_directory_: Write tiles to the specified *directory* instead of to an mbtiles file.
|
||||
* `-f` or `--force`: Delete the mbtiles file if it already exists instead of giving an error
|
||||
* `-F` or `--allow-existing`: Proceed (without deleting existing data) if the metadata or tiles table already exists
|
||||
or if metadata fields can't be set. You probably don't want to use this.
|
||||
|
||||
### Tileset description and attribution
|
||||
|
||||
* `-n` _name_ or `--name=`_name_: Human-readable name for the tileset (default file.json)
|
||||
* `-A` _text_ or `--attribution=`_text_: Attribution (HTML) to be shown with maps that use data from this tileset.
|
||||
* `-N` _description_ or `--description=`_description_: Description for the tileset (default file.mbtiles)
|
||||
|
||||
### Input files and layer names
|
||||
|
||||
* _name_`.json` or _name_`.geojson`: Read the named GeoJSON input file into a layer called _name_.
|
||||
* _name_`.json.gz` or _name_`.geojson.gz`: Read the named gzipped GeoJSON input file into a layer called _name_.
|
||||
* _name_`.geobuf`: Read the named Geobuf input file into a layer called _name_.
|
||||
* _name_`.csv`: Read the named CSV input file into a layer called _name_.
|
||||
* `-l` _name_ or `--layer=`_name_: Use the specified layer name instead of deriving a name from the input filename or output tileset. If there are multiple input files
|
||||
specified, the files are all merged into the single named layer, even if they try to specify individual names with `-L`.
|
||||
* `-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 `geobuf` file format if it is not obvious from the `name`. Example:
|
||||
|
||||
```
|
||||
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`.
|
||||
|
||||
### Parallel processing of input
|
||||
|
||||
* `-P` or `--read-parallel`: Use multiple threads to read different parts of each GeoJSON input file at once.
|
||||
* -o _file_.mbtiles or --output=_file_.mbtiles: Name the output file.
|
||||
* -f or --force: Delete the mbtiles file if it already exists instead of giving an error
|
||||
* -F or --allow-existing: Proceed (without deleting existing data) if the metadata or tiles table already exists
|
||||
or if metadata fields can't be set
|
||||
* -t _directory_ or --temporary-directory=_directory_: Put the temporary files in _directory_.
|
||||
If you don't specify, it will use `/tmp`.
|
||||
* -P or --read-parallel: Use multiple threads to read different parts of each input file at once.
|
||||
This will only work if the input is line-delimited JSON with each Feature on its
|
||||
own line, because it knows nothing of the top-level structure around the Features. Spurious "EOF" error
|
||||
messages may result otherwise.
|
||||
Performance will be better if the input is a named file that can be mapped into memory
|
||||
rather than a stream that can only be read sequentially.
|
||||
|
||||
If the input file begins with the [RFC 8142](https://tools.ietf.org/html/rfc8142) record separator,
|
||||
parallel processing of input will be invoked automatically, splitting at record separators rather
|
||||
than at all newlines.
|
||||
### Zoom levels and resolution
|
||||
|
||||
Parallel processing will also be automatic if the input file is in Geobuf format.
|
||||
|
||||
### Projection of input
|
||||
|
||||
* `-s` _projection_ or `--projection=`_projection_: Specify the projection of the input data. Currently supported are `EPSG:4326` (WGS84, the default) and `EPSG:3857` (Web Mercator). In general you should use WGS84 for your input files if at all possible.
|
||||
|
||||
### Zoom levels
|
||||
|
||||
* `-z` _zoom_ or `--maximum-zoom=`_zoom_: Maxzoom: the highest zoom level for which tiles are generated (default 14)
|
||||
* `-zg` or `--maximum-zoom=g`: Guess what is probably a reasonable maxzoom based on the spacing of features.
|
||||
* `-Z` _zoom_ or `--minimum-zoom=`_zoom_: Minzoom: the lowest zoom level for which tiles are generated (default 0)
|
||||
* `-ae` or `--extend-zooms-if-still-dropping`: Increase the maxzoom if features are still being dropped at that zoom level.
|
||||
The detail and simplification options that ordinarily apply only to the maximum zoom level will apply both to the originally
|
||||
specified maximum zoom and to any levels added beyond that.
|
||||
* `-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.
|
||||
|
||||
If you know the precision to which you want your data to be represented,
|
||||
or the map scale of a corresponding printed map,
|
||||
this table shows the approximate precision and scale corresponding to various
|
||||
`-z` options if you use the default `-d` detail of 12:
|
||||
|
||||
zoom level | precision (ft) | precision (m) | map scale
|
||||
---------- | -------------- | ------------- | ---------
|
||||
`-z0` | 32000 ft | 10000 m | 1:320,000,000
|
||||
`-z1` | 16000 ft | 5000 m | 1:160,000,000
|
||||
`-z2` | 8000 ft | 2500 m | 1:80,000,000
|
||||
`-z3` | 4000 ft | 1250 m | 1:40,000,000
|
||||
`-z4` | 2000 ft | 600 m | 1:20,000,000
|
||||
`-z5` | 1000 ft | 300 m | 1:10,000,000
|
||||
`-z6` | 500 ft | 150 m | 1:5,000,000
|
||||
`-z7` | 250 ft | 80 m | 1:2,500,000
|
||||
`-z8` | 125 ft | 40 m | 1:1,250,000
|
||||
`-z9` | 64 ft | 20 m | 1:640,000
|
||||
`-z10` | 32 ft | 10 m | 1:320,000
|
||||
`-z11` | 16 ft | 5 m | 1:160,000
|
||||
`-z12` | 8 ft | 2 m | 1:80,000
|
||||
`-z13` | 4 ft | 1 m | 1:40,000
|
||||
`-z14` | 2 ft | 0.5 m | 1:20,000
|
||||
`-z15` | 1 ft | 0.25 m | 1:10,000
|
||||
`-z16` | 6 in | 15 cm | 1:5000
|
||||
`-z17` | 3 in | 8 cm | 1:2500
|
||||
`-z18` | 1.5 in | 4 cm | 1:1250
|
||||
`-z19` | 0.8 in | 2 cm | 1:600
|
||||
`-z20` | 0.4 in | 1 cm | 1:300
|
||||
`-z21` | 0.2 in | 0.5 cm | 1:150
|
||||
`-z22` | 0.1 in | 0.25 cm | 1:75
|
||||
|
||||
### Tile resolution
|
||||
|
||||
* `-d` _detail_ or `--full-detail=`_detail_: Detail at max zoom level (default 12, for tile resolution of 2^12=4096)
|
||||
* `-D` _detail_ or `--low-detail=`_detail_: Detail at lower zoom levels (default 12, for tile resolution of 2^12=4096)
|
||||
* `-m` _detail_ or `--minimum-detail=`_detail_: Minimum detail that it will try if tiles are too big at regular detail (default 7)
|
||||
* -z _zoom_ or --maximum-zoom=_zoom_: Maxzoom: the highest zoom level for which tiles are generated (default 14)
|
||||
* -Z _zoom_ or --minimum-zoom=_zoom_: Minzoom: the lowest zoom level for which tiles are generated (default 0)
|
||||
* -B _zoom_ or --base-zoom=_zoom_: Base zoom, the level at and above which all points are included in the tiles (default maxzoom).
|
||||
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.
|
||||
* -d _detail_ or --full-detail=_detail_: Detail at max zoom level (default 12, for tile resolution of 4096)
|
||||
* -D _detail_ or --low-detail=_detail_: Detail at lower zoom levels (default 12, for tile resolution of 4096)
|
||||
* -m _detail_ or --minimum-detail=_detail_: Minimum detail that it will try if tiles are too big at regular detail (default 7)
|
||||
* -b _pixels_ or --buffer=_pixels_: Buffer size where features are duplicated from adjacent tiles. Units are "screen pixels"--1/256th of the tile width or height. (default 5)
|
||||
* -s _projection_ or --projection=_projection_: Specify the projection of the input data. Currently supported are EPSG:4326 (WGS84, the default) and EPSG:3857 (Web Mercator).
|
||||
* -M _bytes_ or --maximum-tile-bytes=_bytes_: Use the specified number of _bytes_ as the maximum compressed tile size instead of 500K.
|
||||
|
||||
All internal math is done in terms of a 32-bit tile coordinate system, so 1/(2^32) of the size of Earth,
|
||||
or about 1cm, is the smallest distinguishable distance. If _maxzoom_ + _detail_ > 32, no additional
|
||||
resolution is obtained than by using a smaller _maxzoom_ or _detail_.
|
||||
|
||||
### Filtering feature attributes
|
||||
### Properties
|
||||
|
||||
* `-x` _name_ or `--exclude=`_name_: Exclude the named attributes from all features. You can specify multiple `-x` options to exclude several attributes. (Don't comma-separate names within a single `-x`.)
|
||||
* `-y` _name_ or `--include=`_name_: Include the named attributes in all features, excluding all those not explicitly named. You can specify multiple `-y` options to explicitly include several attributes. (Don't comma-separate names within a single `-y`.)
|
||||
* `-X` or `--exclude-all`: Exclude all attributes and encode only geometries
|
||||
* -x _name_ or --exclude=_name_: Exclude the named properties from all features
|
||||
* -y _name_ or --include=_name_: Include the named properties in all features, excluding all those not explicitly named
|
||||
* -X or --exclude-all: Exclude all properties and encode only geometries
|
||||
|
||||
### Modifying feature attributes
|
||||
### Point simplification
|
||||
|
||||
* `-T`_attribute_`:`_type_ or `--attribute-type=`_attribute_`:`_type_: Coerce the named feature _attribute_ to be of the specified _type_.
|
||||
The _type_ may be `string`, `float`, `int`, or `bool`.
|
||||
If the type is `bool`, then original attributes of `0` (or, if numeric, `0.0`, etc.), `false`, `null`, or the empty string become `false`, and otherwise become `true`.
|
||||
If the type is `float` or `int` and the original attribute was non-numeric, it becomes `0`.
|
||||
If the type is `int` and the original attribute was floating-point, it is rounded to the nearest integer.
|
||||
* `-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`
|
||||
to specify how the named _attribute_ is accumulated onto the attribute of the same name in a feature that does survive.
|
||||
* `-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.)
|
||||
|
||||
### Filtering features by attributes
|
||||
|
||||
* `-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. The special variable `$zoom` refers to the current zoom level.
|
||||
* `-J` *filter-file* or `--feature-filter-file`=*filter-file*: Like `-j`, but read the filter from a file.
|
||||
|
||||
Example: to find the Natural Earth countries with low `scalerank` but high `LABELRANK`:
|
||||
|
||||
```
|
||||
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:
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
```
|
||||
tippecanoe -o roads.mbtiles -j '{ "*": [ "attribute-filter", "FULLNAME", [ ">=", "$zoom", 9 ] ] }' tl_2015_06001_roads.json
|
||||
```
|
||||
|
||||
An `attribute-filter` expression itself is always considered to evaluate to `true` (in other words, to retain the feature instead
|
||||
of dropping it). If you want to use multiple `attribute-filter` expressions, or to use other expressions to remove features from
|
||||
the same layer, enclose them in an `all` expression so they will all be evaluated.
|
||||
|
||||
### Dropping a fixed fraction of features by zoom level
|
||||
|
||||
* `-r` _rate_ or `--drop-rate=`_rate_: Rate at which dots are dropped at zoom levels below basezoom (default 2.5).
|
||||
If you use `-rg`, it will guess a drop rate that will keep at most 50,000 features in the densest tile.
|
||||
You can also specify a marker-width with `-rg`*width* to allow fewer features in the densest tile to
|
||||
compensate for the larger marker, or `-rf`*number* to allow at most *number* features in the densest tile.
|
||||
* `-B` _zoom_ or `--base-zoom=`_zoom_: Base zoom, the level at and above which all points are included in the tiles (default maxzoom).
|
||||
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.
|
||||
* `-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.
|
||||
|
||||
### 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. This option will not work for point features.
|
||||
* `-aN` or `--coalesce-smallest-as-needed`: Dynamically combine the smallest features (physically smallest: the shortest lines or the smallest polygons) from each zoom level into other nearby features to keep large tiles under the 500K size limit. This option will not work for point features, and will probably not help very much with LineStrings. It is mostly intended for polygons, to maintain the full original area covered by polygons while still reducing the feature count somehow. The attributes of the small polygons are *not* preserved into the combined features (except through `--accumulate-attribute`), only their geometry. Furthermore, the polygons to which nested polygons are coalesced may not necessarily be the immediately enclosing features.
|
||||
* `-aD` or `--coalesce-densest-as-needed`: Dynamically combine the densest features from each zoom level into other nearby features to keep large tiles under the 500K size limit. (Again, mostly useful for polygons.)
|
||||
* `-aS` or `--coalesce-fraction-as-needed`: Dynamically combine a fraction of features from each zoom level into other nearby features to keep large tiles under the 500K size limit. (Again, mostly useful for polygons.)
|
||||
* `-pd` or `--force-feature-limit`: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. (This is like `-ad` but applies to each tile individually, not to the entire zoom level.) You probably don't want to use this.
|
||||
* `-aC` or `--cluster-densest-as-needed`: If a tile is too large, try to reduce its size by increasing the minimum spacing between features, and leaving one placeholder feature from each group. The remaining feature will be given a `"clustered": true` attribute to indicate that it represents a cluster, a `"point_count"` attribute to indicate the number of features that were clustered into it, and a `"sqrt_point_count"` attribute to indicate the relative width of a feature to represent the cluster. If the features being clustered are points, the representative feature will be located at the average of the original points' locations; otherwise, one of the original features will be left as the representative.
|
||||
|
||||
### Dropping tightly overlapping features
|
||||
|
||||
* `-g` _gamma_ or `--gamma=_gamma`_: Rate at which especially dense dots are dropped (default 0, for no effect). A gamma of 2 reduces the number of dots less than a pixel apart to the square root of their original number.
|
||||
* `-aG` or `--increase-gamma-as-needed`: If a tile is too large, try to reduce it to under 500K by increasing the `-g` gamma. The discovered gamma applies to the entire zoom level. You probably want to use `--drop-densest-as-needed` instead.
|
||||
* -r _rate_ or --drop-rate=_rate_: Rate at which dots are dropped at zoom levels below basezoom (default 2.5).
|
||||
If you use -rg, it will guess a drop rate that will keep at most 50,000 features in the densest tile.
|
||||
You can also specify a marker-width with -rg*width* to allow fewer features in the densest tile to
|
||||
compensate for the larger marker, or -rf*number* to allow at most *number* features in the densest tile.
|
||||
* -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.
|
||||
|
||||
### Line and polygon simplification
|
||||
|
||||
* `-S` _scale_ or `--simplification=`_scale_: Multiply the tolerance for line and polygon simplification by _scale_. The standard tolerance tries to keep
|
||||
* -S _scale_ or --simplification=_scale_: Multiply the tolerance for line and polygon simplification by _scale_. The standard tolerance tries to keep
|
||||
the line or polygon within one tile unit of its proper location. You can probably go up to about 10 without too much visible difference.
|
||||
* `-ps` or `--no-line-simplification`: Don't simplify lines and polygons
|
||||
* `-pS` or `--simplify-only-low-zooms`: Don't simplify lines and polygons at maxzoom (but do simplify at lower zooms)
|
||||
* `-pn` or `--no-simplification-of-shared-nodes`: Don't simplify away nodes that appear in more than one feature or are used multiple times within the same feature, so that the intersection node will not be lost from intersecting roads. (This will not be effective if you also use `--coalesce` or `--detect-shared-borders`.)
|
||||
* `-pt` or `--no-tiny-polygon-reduction`: Don't combine the area of very small polygons into small squares that represent their combined area.
|
||||
|
||||
### Attempts to improve shared polygon boundaries
|
||||
### Doing more
|
||||
|
||||
* `-ab` or `--detect-shared-borders`: 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.
|
||||
* `-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.
|
||||
* -ac or --coalesce: Coalesce adjacent line and polygon features that have the same properties.
|
||||
Note that when overlapping polygons are coalesced, the overlapping region is treated as a hole,
|
||||
which may not be what you want.
|
||||
* -ar or --reverse: Try reversing the directions of lines to make them coalesce and compress better
|
||||
* -ao or --reorder: Reorder features to put ones with the same properties in sequence, to try to get them to coalesce
|
||||
* -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
|
||||
* -ag or --calculate-feature-density: Add a new attribute, `tippecanoe_feature_density`, to each feature, to record how densely features are spaced in that area of the tile. You can use this attribute in the style to produce a glowing effect where points are densely packed. It can range from 0 in the sparsest areas to 255 in the densest.
|
||||
* -ab or --detect-shared-borders: 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.
|
||||
* -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.
|
||||
* -am or --merge-polygons-as-needed: If a tile is too large, try to reduce it to under 500K by merging adjacent polygons together
|
||||
* -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. This option will not work for point features.
|
||||
|
||||
### Controlling clipping to tile boundaries
|
||||
### Doing less
|
||||
|
||||
* `-b` _pixels_ or `--buffer=`_pixels_: Buffer size where features are duplicated from adjacent tiles. Units are "screen pixels"—1/256th of the tile width or height. (default 5)
|
||||
* `-pc` or `--no-clipping`: Don't clip features to the size of the tile. If a feature overlaps the tile's bounds or buffer at all, it is included completely. Be careful: this can produce very large tilesets, especially with large polygons.
|
||||
* `-pD` or `--no-duplication`: As with `--no-clipping`, each feature is included intact instead of cut to tile boundaries. In addition, it is included only in a single tile per zoom level rather than potentially in multiple copies. Clients of the tileset must check adjacent tiles (possibly some distance away) to ensure they have all features.
|
||||
* -ps or --no-line-simplification: Don't simplify lines
|
||||
* -pS or --simplify-only-low-zooms: Don't simplify lines at maxzoom (but do simplify at lower zooms)
|
||||
* -pf or --no-feature-limit: Don't limit tiles to 200,000 features
|
||||
* -pk or --no-tile-size-limit: Don't limit tiles to 500K bytes
|
||||
* -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.)
|
||||
* -pi or --preserve-input-order: Preserve the original input order of features as the drawing order instead of ordering geographically. (This is implemented as a restoration of the original order at the end, so that dot-dropping is still geographic, which means it also undoes -ao).
|
||||
* -pp or --no-polygon-splitting: Don't split complex polygons (over 700 vertices after simplification) into multiple features.
|
||||
* -pc or --no-clipping: Don't clip features to the size of the tile. If a feature overlaps the tile's bounds or buffer at all, it is included completely. Be careful: this can produce very large tilesets, especially with large polygons.
|
||||
* -pD or --no-duplication: As with --no-clipping, each feature is included intact instead of cut to tile boundaries. In addition, it is included only in a single tile per zoom level rather than potentially in multiple copies. Clients of the tileset must check adjacent tiles (possibly some distance away) to ensure they have all features.
|
||||
* -pt or --no-tiny-polygon-reduction: Don't combine the area of very small polygons into small squares that represent their combined area.
|
||||
* -q or --quiet: Work quietly instead of reporting progress
|
||||
|
||||
### Reordering features within each tile
|
||||
Example
|
||||
-------
|
||||
|
||||
* `-pi` or `--preserve-input-order`: Preserve the original input order of features as the drawing order instead of ordering geographically. (This is implemented as a restoration of the original order at the end, so that dot-dropping is still geographic, which means it also undoes `-ao`).
|
||||
* `-ac` or `--coalesce`: Coalesce consecutive features that have the same attributes. This can be useful if you have lots of small polygons with identical attributes and you would like to merge them together.
|
||||
* `-ao` or `--reorder`: Reorder features to put ones with the same attributes in sequence (instead of ones that are approximately spatially adjacent), to try to get them to coalesce. You probably want to use this if you use `--coalesce`.
|
||||
* `-ar` or `--reverse`: Try reversing the directions of lines to make them coalesce and compress better. You probably don't want to use this.
|
||||
* `-ah` or `--hilbert`: Put features in Hilbert Curve order instead of the usual Z-Order. This improves the odds that spatially adjacent features will be sequentially adjacent, and should improve density calculations and spatial coalescing. It should be the default eventually.
|
||||
|
||||
### Adding calculated attributes
|
||||
|
||||
* `-ag` or `--calculate-feature-density`: Add a new attribute, `tippecanoe_feature_density`, to each feature, to record how densely features are spaced in that area of the tile. You can use this attribute in the style to produce a glowing effect where points are densely packed. It can range from 0 in the sparsest areas to 255 in the densest.
|
||||
* `-ai` or `--generate-ids`: Add an `id` (a feature ID, not an attribute named `id`) to each feature that does not already have one. There is currently no guarantee that the `id` added will be stable between runs or that it will not conflict with manually-assigned feature IDs. Future versions of Tippecanoe may change the mechanism for allocating IDs.
|
||||
|
||||
### Trying to correct bad source geometry
|
||||
|
||||
* `-aw` or `--detect-longitude-wraparound`: Detect when consecutive points within a feature jump to the other side of the world, and try to fix the geometry.
|
||||
* `-pw` or `--use-source-polygon-winding`: Instead of respecting GeoJSON polygon ring order, use the original polygon winding in the source data to distinguish inner (clockwise) and outer (counterclockwise) polygon rings.
|
||||
* `-pW` or `--reverse-source-polygon-winding`: Instead of respecting GeoJSON polygon ring order, use the opposite of the original polygon winding in the source data to distinguish inner (counterclockwise) and outer (clockwise) polygon rings.
|
||||
* `--clip-bounding-box=`*minlon*`,`*minlat*`,`*maxlon*`,`*maxlat*: Clip all features to the specified bounding box.
|
||||
|
||||
### Setting or disabling tile size limits
|
||||
|
||||
* `-M` _bytes_ or `--maximum-tile-bytes=`_bytes_: Use the specified number of _bytes_ as the maximum compressed tile size instead of 500K.
|
||||
* `-O` _features_ or `--maximum-tile-features=`_features_: Use the specified number of _features_ as the maximum in a tile instead of 200,000.
|
||||
* `-pf` or `--no-feature-limit`: Don't limit tiles to 200,000 features
|
||||
* `-pk` or `--no-tile-size-limit`: Don't limit tiles to 500K bytes
|
||||
* `-pC` or `--no-tile-compression`: Don't compress the PBF vector tile data. If you are getting "Unimplemented type 3" error messages from a renderer, it is probably because it expects uncompressed tiles using this option rather than the normal gzip-compressed tiles.
|
||||
* `-pg` or `--no-tile-stats`: Don't generate the `tilestats` row in the tileset metadata. Uploads without [tilestats](https://github.com/mapbox/mapbox-geostats) will take longer to process.
|
||||
* `--tile-stats-attributes-limit=`*count*: Include `tilestats` information about at most *count* attributes instead of the default 1000.
|
||||
* `--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.
|
||||
|
||||
### Temporary storage
|
||||
|
||||
* `-t` _directory_ or `--temporary-directory=`_directory_: Put the temporary files in _directory_.
|
||||
If you don't specify, it will use `/tmp`.
|
||||
|
||||
### Progress indicator
|
||||
|
||||
* `-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_.
|
||||
* `-v` or `--version`: Report Tippecanoe's version number
|
||||
|
||||
### Filters
|
||||
|
||||
* `-C` _command_ or `--prefilter=`_command_: Specify a shell filter command to be run at the start of assembling each tile
|
||||
* `-c` _command_ or `--postfilter=`_command_: Specify a shell filter command to be run at the end of assembling each tile
|
||||
|
||||
The pre- and post-filter commands allow you to do optional filtering or transformation on the features of each tile
|
||||
as it is created. They are shell commands, run with the zoom level, X, and Y as the `$1`, `$2`, and `$3` arguments.
|
||||
Future versions of Tippecanoe may add additional arguments for more context.
|
||||
|
||||
The features are provided to the filter
|
||||
as a series of newline-delimited GeoJSON objects on the standard input, and `tippecanoe` expects to read another
|
||||
set of GeoJSON features from the filter's standard output.
|
||||
|
||||
The prefilter receives the features at the highest available resolution, before line simplification,
|
||||
polygon topology repair, gamma calculation, dynamic feature dropping, or other internal processing.
|
||||
The postfilter receives the features at tile resolution, after simplification, cleaning, and dropping.
|
||||
|
||||
The layer name is provided as part of the `tippecanoe` element of the feature and must be passed through
|
||||
to keep the feature in its correct layer. In the case of the prefilter, the `tippecanoe` element may also
|
||||
contain `index`, `sequence`, `extent`, and `dropped`, elements, which must be passed through for internal operations like
|
||||
`--drop-densest-as-needed`, `--drop-smallest-as-needed`, and `--preserve-input-order` to work.
|
||||
|
||||
#### Examples:
|
||||
|
||||
* 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.
|
||||
|
||||
```
|
||||
tippecanoe -o countries.mbtiles -z5 -C 'mkdir -p tiles/$1/$2; tee tiles/$1/$2/$3.geojson' ne_10m_admin_0_countries.json
|
||||
```sh
|
||||
$ tippecanoe -o alameda.mbtiles -l alameda -n "Alameda County from TIGER" -z13 tl_2014_06001_roads.json
|
||||
```
|
||||
|
||||
* Make a tileset of the Natural Earth countries to zoom level 5, but including only those tiles that
|
||||
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).)
|
||||
|
||||
```
|
||||
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
|
||||
$ 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
|
||||
```
|
||||
|
||||
* 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.
|
||||
|
||||
```
|
||||
tippecanoe -o roads.mbtiles -c 'if [ $1 -lt 11 ]; then grep "\"MTFCC\": \"S1[12]00\""; else cat; fi' tl_2016_18157_roads.json
|
||||
```
|
||||
|
||||
Environment
|
||||
-----------
|
||||
|
||||
Tippecanoe ordinarily uses as many parallel threads as the operating system claims that CPUs are available.
|
||||
You can override this number by setting the `TIPPECANOE_MAX_THREADS` environmental variable.
|
||||
|
||||
GeoJSON extension
|
||||
-----------------
|
||||
|
||||
@ -624,9 +179,7 @@ If you have a feature like this:
|
||||
|
||||
with a `tippecanoe` object specifiying 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
|
||||
dropped it.
|
||||
object belongs to the Feature, not to its `properties`.
|
||||
|
||||
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:
|
||||
@ -643,11 +196,32 @@ the filename or name specified using `--layer`, like this:
|
||||
}
|
||||
```
|
||||
|
||||
If your source GeoJSON only has `minzoom`, `maxzoom` and/or `layer` within `properties` you can use [ndjson-cli](https://github.com/mbostock/ndjson-cli/blob/master/README.md) to move them into the required `tippecanoe` object by piping the GeoJSON like this:
|
||||
Point styling
|
||||
-------------
|
||||
|
||||
```sh
|
||||
ndjson-map 'd.tippecanoe = { minzoom: d.properties.minzoom, maxzoom: d.properties.maxzoom, layer: d.properties.layer }, delete d.properties.minzoom, delete d.properties.maxzoom, delete d.properties.layer, d'
|
||||
```
|
||||
To provide a consistent density gradient as you zoom, the Mapbox Studio style needs to be
|
||||
coordinated with the base zoom level and dot-dropping rate. You can use this shell script to
|
||||
calculate the appropriate marker-width at high zoom levels to match the fraction of dots
|
||||
that were dropped at low zoom levels.
|
||||
|
||||
If you used `-B` or `-z` to change the base zoom level or `-r` to change the
|
||||
dot-dropping rate, replace them in the `basezoom` and `rate` below.
|
||||
|
||||
awk 'BEGIN {
|
||||
dotsize = 2; # up to you to decide
|
||||
basezoom = 14; # tippecanoe -z 14
|
||||
rate = 2.5; # tippecanoe -r 2.5
|
||||
|
||||
print " marker-line-width: 0;";
|
||||
print " marker-ignore-placement: true;";
|
||||
print " marker-allow-overlap: true;";
|
||||
print " marker-width: " dotsize ";";
|
||||
for (i = basezoom + 1; i <= 22; i++) {
|
||||
print " [zoom >= " i "] { marker-width: " (dotsize * exp(log(sqrt(rate)) * (i - basezoom))) "; }";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}'
|
||||
|
||||
Geometric simplifications
|
||||
-------------------------
|
||||
@ -675,9 +249,12 @@ have their probability diffused, so that some of them will be drawn as a square
|
||||
this minimum size and others will not be drawn at all, preserving the total area that
|
||||
all of them should have had together.
|
||||
|
||||
Any polygons that have over 700 vertices after line simplification will be split into
|
||||
multiple features so they can be rendered efficiently, unless you use -pp to prevent this.
|
||||
|
||||
Features in the same tile that share the same type and attributes are coalesced
|
||||
together into a single geometry if you use `--coalesce`. You are strongly encouraged to use -x to exclude
|
||||
any unnecessary attributes to reduce wasted file size.
|
||||
any unnecessary properties to reduce wasted file size.
|
||||
|
||||
If a tile is larger than 500K, it will try encoding that tile at progressively
|
||||
lower resolutions before failing if it still doesn't fit.
|
||||
@ -690,7 +267,7 @@ uses md2man (`gem install md2man`).
|
||||
|
||||
Linux:
|
||||
|
||||
sudo apt-get install build-essential libsqlite3-dev zlib1g-dev
|
||||
sudo apt-get install libsqlite3-dev zlib1g-dev
|
||||
|
||||
Then build:
|
||||
|
||||
@ -700,35 +277,6 @@ 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
|
||||
|
||||
```
|
||||
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
|
||||
```
|
||||
|
||||
Docker Image
|
||||
------------
|
||||
|
||||
A tippecanoe Docker image can be built from source and executed as a task to
|
||||
automatically install dependencies and allow tippecanoe to run on any system
|
||||
supported by Docker.
|
||||
|
||||
```docker
|
||||
$ docker build -t tippecanoe:latest .
|
||||
$ docker run -it --rm \
|
||||
-v /tiledata:/data \
|
||||
tippecanoe:latest \
|
||||
tippecanoe --output=/data/output.mbtiles /data/example.geojson
|
||||
```
|
||||
|
||||
The commands above will build a Docker image from the source and compile the
|
||||
latest version. The image supports all tippecanoe flags and options.
|
||||
|
||||
Examples
|
||||
------
|
||||
|
||||
@ -742,61 +290,22 @@ The name is [a joking reference](http://en.wikipedia.org/wiki/Tippecanoe_and_Tyl
|
||||
tile-join
|
||||
=========
|
||||
|
||||
Tile-join is a tool for copying and merging vector mbtiles files and for
|
||||
joining new attributes from a CSV file to existing features in them.
|
||||
Tile-join is a tool for joining new attributes from a CSV file to features that
|
||||
have already been tiled with tippecanoe. It reads the tiles from an existing .mbtiles
|
||||
file, matches them against the records of the CSV, and writes out a new tileset.
|
||||
|
||||
It reads the tiles from an
|
||||
existing .mbtiles file or a directory of tiles, matches them against the
|
||||
records of the CSV (if one is specified), and writes out a new tileset.
|
||||
|
||||
If you specify multiple source mbtiles files or source directories of tiles,
|
||||
all the sources are read and their combined contents are written to the new
|
||||
mbtiles output. If they define the same layers or the same tiles, the layers
|
||||
or tiles are merged.
|
||||
If you specify multiple source mbtiles files, they are all read and their combined
|
||||
contents are written to the new mbtiles output. If they define the same layers or
|
||||
the same tiles, the layers or tiles are merged.
|
||||
|
||||
The options are:
|
||||
|
||||
### Output tileset
|
||||
|
||||
* `-o` *out.mbtiles* 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.
|
||||
|
||||
### Tileset description and attribution
|
||||
|
||||
* `-A` *attribution* or `--attribution=`*attribution*: Set the attribution string.
|
||||
* `-n` *name* or `--name=`*name*: Set the tileset name.
|
||||
* `-N` *description* or `--description=`*description*: Set the tileset description.
|
||||
|
||||
### Layer filtering and naming
|
||||
|
||||
* `-l` *layer* or `--layer=`*layer*: Include the named layer in the output. You can specify multiple `-l` options to keep multiple layers. If you don't specify, they will all be retained.
|
||||
* `-L` *layer* or `--exclude-layer=`*layer*: Remove the named layer from the output. You can specify multiple `-L` options to remove multiple layers.
|
||||
* `-R`*old*`:`*new* or `--rename-layer=`*old*`:`*new*: Rename the layer named *old* to be named *new* instead. You can specify multiple `-R` options to rename multiple layers. Renaming happens before filtering.
|
||||
|
||||
### Zoom levels
|
||||
|
||||
* `-z` _zoom_ or `--maximum-zoom=`_zoom_: Don't copy tiles from higher zoom levels than the specified zoom
|
||||
* `-Z` _zoom_ or `--minimum-zoom=`_zoom_: Don't copy tiles from lower zoom levels than the specified zoom
|
||||
|
||||
### Merging attributes from a CSV file
|
||||
|
||||
* `-c` *match*`.csv` or `--csv=`*match*`.csv`: Use *match*`.csv` as the source for new attributes to join to the features. The first line of the file should be the key names; the other lines are values. The first column is the one to match against the existing features; the other columns are the new data to add.
|
||||
|
||||
### Filtering features and feature attributes
|
||||
|
||||
* `-x` *key* or `--exclude=`*key*: Remove attributes of type *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.
|
||||
* `-X` or `--exclude-all`: Remove all attributes from the output.
|
||||
* `-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.
|
||||
* `-pe` or `--empty-csv-columns-are-null`: Treat empty CSV columns as nulls rather than as empty strings.
|
||||
|
||||
### Setting or disabling tile size limits
|
||||
|
||||
* `-pk` or `--no-tile-size-limit`: Don't skip tiles larger than 500K.
|
||||
* `-pC` or `--no-tile-compression`: Don't compress the PBF vector tile data.
|
||||
* `-pg` or `--no-tile-stats`: Don't generate the `tilestats` row in the tileset metadata. Uploads without [tilestats](https://github.com/mapbox/mapbox-geostats) will take longer to process.
|
||||
* -o *out.mbtiles*: Write the new tiles to the specified .mbtiles file
|
||||
* -f: Remove *out.mbtiles* if it already exists
|
||||
* -c *match.csv*: Use *match.csv* as the source for new attributes to join to the features. The first line of the file should be the key names; the other lines are values. The first column is the one to match against the existing features; the other columns are the new data to add.
|
||||
* -x *key*: Remove attributes of type *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.
|
||||
* -i: Only include features that matched the CSV.
|
||||
* -pk: Don't skip tiles larger than 500K.
|
||||
|
||||
Because tile-join just copies the geometries to the new .mbtiles without processing them
|
||||
(except to rescale the extents if necessary),
|
||||
@ -809,7 +318,7 @@ Example
|
||||
Imagine you have a tileset of census blocks:
|
||||
|
||||
```sh
|
||||
curl -L -O http://www2.census.gov/geo/tiger/TIGER2010/TABBLOCK/2010/tl_2010_06001_tabblock10.zip
|
||||
curl -O http://www2.census.gov/geo/tiger/TIGER2010/TABBLOCK/2010/tl_2010_06001_tabblock10.zip
|
||||
unzip tl_2010_06001_tabblock10.zip
|
||||
ogr2ogr -f GeoJSON tl_2010_06001_tabblock10.json tl_2010_06001_tabblock10.shp
|
||||
./tippecanoe -o tl_2010_06001_tabblock10.mbtiles tl_2010_06001_tabblock10.json
|
||||
@ -818,7 +327,7 @@ ogr2ogr -f GeoJSON tl_2010_06001_tabblock10.json tl_2010_06001_tabblock10.shp
|
||||
and a CSV of their populations:
|
||||
|
||||
```sh
|
||||
curl -L -O http://www2.census.gov/census_2010/01-Redistricting_File--PL_94-171/California/ca2010.pl.zip
|
||||
curl -O http://www2.census.gov/census_2010/01-Redistricting_File--PL_94-171/California/ca2010.pl.zip
|
||||
unzip -p ca2010.pl.zip cageo2010.pl |
|
||||
awk 'BEGIN {
|
||||
print "GEOID10,population"
|
||||
@ -873,80 +382,11 @@ or on an individual tile:
|
||||
tippecanoe-decode file.mbtiles zoom x y
|
||||
tippecanoe-decode file.vector.pbf zoom x y
|
||||
|
||||
Unless you use `-c`, the output is a set of nested FeatureCollections identifying each
|
||||
If you decode an entire file, you get a nested `FeatureCollection` identifying each
|
||||
tile and layer separately. Note that the same features generally appear at all zooms,
|
||||
so the output for the file will have many copies of the same features at different
|
||||
resolutions.
|
||||
|
||||
### Options
|
||||
|
||||
* `-s` _projection_ or `--projection=`*projection*: Specify the projection of the output data. Currently supported are EPSG:4326 (WGS84, the default) and EPSG:3857 (Web Mercator).
|
||||
* `-z` _maxzoom_ or `--maximum-zoom=`*maxzoom*: Specify the highest zoom level to decode from the tileset
|
||||
* `-Z` _minzoom_ or `--minimum-zoom=`*minzoom*: Specify the lowest zoom level to decode from the tileset
|
||||
* `-l` _layer_ or `--layer=`*layer*: Decode only layers with the specified names. (Multiple `-l` options can be specified.)
|
||||
* `-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
|
||||
|
||||
tippecanoe-json-tool
|
||||
====================
|
||||
|
||||
Extracts GeoJSON features or standalone geometries as line-delimited JSON objects from a larger JSON file,
|
||||
following the same extraction rules that Tippecanoe uses when parsing JSON.
|
||||
|
||||
tippecanoe-json-tool file.json [... file.json]
|
||||
|
||||
Optionally also wraps them in a FeatureCollection or GeometryCollection as appropriate.
|
||||
|
||||
Optionally extracts an attribute from the GeoJSON `properties` for sorting.
|
||||
|
||||
Optionally joins a sorted CSV of new attributes to a sorted GeoJSON file.
|
||||
|
||||
The reason for requiring sorting is so that it is possible to work on CSV and GeoJSON files that are larger
|
||||
than can comfortably fit in memory by streaming through them in parallel, in the same way that the Unix
|
||||
`join` command does. The Unix `sort` command can be used to sort large files to prepare them for joining.
|
||||
|
||||
The sorting interface is weird, and future version of `tippecanoe-json-tool` will replace it with
|
||||
something better.
|
||||
|
||||
### Options
|
||||
|
||||
* `-w` or `--wrap`: Add the FeatureCollection or GeometryCollection wrapper.
|
||||
* `-e` *attribute* or `--extract=`*attribute*: Extract the named attribute as a prefix to each feature.
|
||||
The formatting makes excessive use of `\u` quoting so that it follows JSON string rules but will still
|
||||
be sorted correctly by tools that just do ASCII comparisons.
|
||||
* `-c` *file.csv* or `--csv=`*file.csv*: Join attributes from the named sorted CSV file, using its first column as the join key. Geometries will be passed through even if they do not match the CSV; CSV lines that do not match a geometry will be discarded.
|
||||
* `-pe` or `--empty-csv-columns-are-null`: Treat empty CSV columns as nulls rather than as empty strings.
|
||||
|
||||
### Example
|
||||
|
||||
Join Census LEHD ([Longitudinal Employer-Household Dynamics](https://lehd.ces.census.gov/)) employment data to a file of Census block geography
|
||||
for Tippecanoe County, Indiana.
|
||||
|
||||
Download Census block geometry, and convert to GeoJSON:
|
||||
|
||||
```
|
||||
$ 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
|
||||
```
|
||||
|
||||
Download Indiana employment data, and fix name of join key in header
|
||||
|
||||
```
|
||||
$ 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
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```
|
||||
$ 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:
|
||||
|
||||
```
|
||||
$ tippecanoe-json-tool -c in_wac_S000_JT00_2015.csv tl_2010_18157_tabblock10.sort.json > blocks-wac.json
|
||||
```
|
||||
* -t _projection_: Specify the projection of the output data. Currently supported are EPSG:4326 (WGS84, the default) and EPSG:3857 (Web Mercator).
|
||||
|
@ -1,7 +0,0 @@
|
||||
ignore:
|
||||
- "test"
|
||||
- "mapbox"
|
||||
|
||||
coverage:
|
||||
status:
|
||||
patch: off
|
174
csv.cpp
174
csv.cpp
@ -1,174 +0,0 @@
|
||||
#include "csv.hpp"
|
||||
#include "text.hpp"
|
||||
|
||||
std::vector<std::string> csv_split(const char *s) {
|
||||
std::vector<std::string> ret;
|
||||
|
||||
while (*s && *s != '\n' && *s != '\r') {
|
||||
const char *start = s;
|
||||
int within = 0;
|
||||
|
||||
for (; *s && *s != '\n' && *s != '\r'; s++) {
|
||||
if (*s == '"') {
|
||||
within = !within;
|
||||
}
|
||||
|
||||
if (*s == ',' && !within) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string v = std::string(start, s - start);
|
||||
ret.push_back(v);
|
||||
|
||||
if (*s == ',') {
|
||||
s++;
|
||||
|
||||
while (*s && isspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
|
||||
if (*s == '\0' || *s == '\r' || *s == '\n') {
|
||||
ret.push_back(std::string(""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string csv_dequote(std::string s) {
|
||||
std::string out;
|
||||
for (size_t i = 0; i < s.size(); i++) {
|
||||
if (s[i] == '"') {
|
||||
if (i + 1 < s.size() && s[i + 1] == '"') {
|
||||
out.push_back('"');
|
||||
}
|
||||
} else {
|
||||
out.push_back(s[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string csv_getline(FILE *f) {
|
||||
std::string out;
|
||||
int c;
|
||||
while ((c = getc(f)) != EOF) {
|
||||
out.push_back(c);
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping) {
|
||||
FILE *f = fopen(fn, "r");
|
||||
if (f == NULL) {
|
||||
perror(fn);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string s;
|
||||
if ((s = csv_getline(f)).size() > 0) {
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s: %s\n", fn, err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
header = csv_split(s.c_str());
|
||||
|
||||
for (size_t i = 0; i < header.size(); i++) {
|
||||
header[i] = csv_dequote(header[i]);
|
||||
}
|
||||
}
|
||||
while ((s = csv_getline(f)).size() > 0) {
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s: %s\n", fn, err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::vector<std::string> line = csv_split(s.c_str());
|
||||
if (line.size() > 0) {
|
||||
line[0] = csv_dequote(line[0]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < line.size() && i < header.size(); i++) {
|
||||
// printf("putting %s\n", line[0].c_str());
|
||||
mapping.insert(std::pair<std::string, std::vector<std::string>>(line[0], line));
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(f) != 0) {
|
||||
perror("fclose");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Follow JSON rules for what looks like a number
|
||||
bool is_number(std::string const &s) {
|
||||
const char *cp = s.c_str();
|
||||
char c = *(cp++);
|
||||
|
||||
if (c == '-' || (c >= '0' && c <= '9')) {
|
||||
if (c == '-') {
|
||||
c = *(cp++);
|
||||
}
|
||||
|
||||
if (c == '0') {
|
||||
;
|
||||
} else if (c >= '1' && c <= '9') {
|
||||
c = *cp;
|
||||
|
||||
while (c >= '0' && c <= '9') {
|
||||
cp++;
|
||||
c = *cp;
|
||||
}
|
||||
}
|
||||
|
||||
if (*cp == '.') {
|
||||
cp++;
|
||||
|
||||
c = *cp;
|
||||
if (c < '0' || c > '9') {
|
||||
return false;
|
||||
}
|
||||
while (c >= '0' && c <= '9') {
|
||||
cp++;
|
||||
c = *cp;
|
||||
}
|
||||
}
|
||||
|
||||
c = *cp;
|
||||
if (c == 'e' || c == 'E') {
|
||||
cp++;
|
||||
|
||||
c = *cp;
|
||||
if (c == '+' || c == '-') {
|
||||
cp++;
|
||||
}
|
||||
|
||||
c = *cp;
|
||||
if (c < '0' || c > '9') {
|
||||
return false;
|
||||
}
|
||||
while (c >= '0' && c <= '9') {
|
||||
cp++;
|
||||
c = *cp;
|
||||
}
|
||||
}
|
||||
|
||||
if (*cp == '\0') {
|
||||
return true;
|
||||
} else {
|
||||
// Something non-numeric at the end
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
16
csv.hpp
16
csv.hpp
@ -1,16 +0,0 @@
|
||||
#ifndef CSV_HPP
|
||||
#define CSV_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
std::vector<std::string> csv_split(const char *s);
|
||||
std::string csv_dequote(std::string s);
|
||||
void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping);
|
||||
std::string csv_getline(FILE *f);
|
||||
bool is_number(std::string const &s);
|
||||
|
||||
#endif
|
742
decode.cpp
742
decode.cpp
@ -3,234 +3,339 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sqlite3.h>
|
||||
#include <getopt.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <zlib.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <protozero/pbf_reader.hpp>
|
||||
#include <sys/stat.h>
|
||||
#include "mvt.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "write_json.hpp"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "dirtiles.hpp"
|
||||
|
||||
int minzoom = 0;
|
||||
int maxzoom = 32;
|
||||
bool force = false;
|
||||
|
||||
void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, unsigned y, json_writer &state) {
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("zoom");
|
||||
state.json_write_signed(z);
|
||||
|
||||
state.json_write_string("x");
|
||||
state.json_write_unsigned(x);
|
||||
|
||||
state.json_write_string("y");
|
||||
state.json_write_unsigned(y);
|
||||
|
||||
state.json_write_string("bytes");
|
||||
state.json_write_unsigned(size);
|
||||
|
||||
state.json_write_string("compressed");
|
||||
state.json_write_bool(compressed);
|
||||
|
||||
state.json_write_string("layers");
|
||||
state.json_write_hash();
|
||||
|
||||
for (size_t i = 0; i < tile.layers.size(); i++) {
|
||||
state.json_write_string(tile.layers[i].name);
|
||||
|
||||
size_t points = 0, lines = 0, polygons = 0;
|
||||
for (size_t j = 0; j < tile.layers[i].features.size(); j++) {
|
||||
if (tile.layers[i].features[j].type == mvt_point) {
|
||||
points++;
|
||||
} else if (tile.layers[i].features[j].type == mvt_linestring) {
|
||||
lines++;
|
||||
} else if (tile.layers[i].features[j].type == mvt_polygon) {
|
||||
polygons++;
|
||||
}
|
||||
void printq(const char *s) {
|
||||
putchar('"');
|
||||
for (; *s; s++) {
|
||||
if (*s == '\\' || *s == '"') {
|
||||
printf("\\%c", *s);
|
||||
} else if (*s >= 0 && *s < ' ') {
|
||||
printf("\\u%04x", *s);
|
||||
} else {
|
||||
putchar(*s);
|
||||
}
|
||||
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("points");
|
||||
state.json_write_unsigned(points);
|
||||
|
||||
state.json_write_string("lines");
|
||||
state.json_write_unsigned(lines);
|
||||
|
||||
state.json_write_string("polygons");
|
||||
state.json_write_unsigned(polygons);
|
||||
|
||||
state.json_write_string("extent");
|
||||
state.json_write_signed(tile.layers[i].extent);
|
||||
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
state.json_end_hash();
|
||||
state.json_end_hash();
|
||||
|
||||
state.json_write_newline();
|
||||
putchar('"');
|
||||
}
|
||||
|
||||
void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats, json_writer &state) {
|
||||
struct lonlat {
|
||||
int op;
|
||||
double lon;
|
||||
double lat;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
lonlat(int nop, double nlon, double nlat, int nx, int ny) {
|
||||
this->op = nop;
|
||||
this->lon = nlon;
|
||||
this->lat = nlat;
|
||||
this->x = nx;
|
||||
this->y = ny;
|
||||
}
|
||||
};
|
||||
|
||||
void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
||||
int within = 0;
|
||||
mvt_tile tile;
|
||||
bool was_compressed;
|
||||
|
||||
try {
|
||||
if (!tile.decode(message, was_compressed)) {
|
||||
if (!tile.decode(message)) {
|
||||
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", z, x, y);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} catch (std::exception const &e) {
|
||||
} catch (protozero::unknown_pbf_wire_type_exception e) {
|
||||
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", z, x, y);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (stats) {
|
||||
do_stats(tile, message.size(), was_compressed, z, x, y, state);
|
||||
return;
|
||||
}
|
||||
printf("{ \"type\": \"FeatureCollection\"");
|
||||
|
||||
if (!pipeline) {
|
||||
state.json_write_hash();
|
||||
if (describe) {
|
||||
printf(", \"properties\": { \"zoom\": %d, \"x\": %d, \"y\": %d }", z, x, y);
|
||||
|
||||
state.json_write_string("type");
|
||||
state.json_write_string("FeatureCollection");
|
||||
|
||||
if (true) {
|
||||
state.json_write_string("properties");
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("zoom");
|
||||
state.json_write_signed(z);
|
||||
|
||||
state.json_write_string("x");
|
||||
state.json_write_signed(x);
|
||||
|
||||
state.json_write_string("y");
|
||||
state.json_write_signed(y);
|
||||
|
||||
if (!was_compressed) {
|
||||
state.json_write_string("compressed");
|
||||
state.json_write_bool(false);
|
||||
}
|
||||
|
||||
state.json_end_hash();
|
||||
|
||||
if (projection != projections) {
|
||||
state.json_write_string("crs");
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("type");
|
||||
state.json_write_string("name");
|
||||
|
||||
state.json_write_string("properties");
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("name");
|
||||
state.json_write_string(projection->alias);
|
||||
|
||||
state.json_end_hash();
|
||||
state.json_end_hash();
|
||||
}
|
||||
if (projection != projections) {
|
||||
printf(", \"crs\": { \"type\": \"name\", \"properties\": { \"name\": ");
|
||||
printq(projection->alias);
|
||||
printf(" } }");
|
||||
}
|
||||
|
||||
state.json_write_string("features");
|
||||
state.json_write_array();
|
||||
state.json_write_newline();
|
||||
}
|
||||
|
||||
bool first_layer = true;
|
||||
printf(", \"features\": [\n");
|
||||
|
||||
for (size_t l = 0; l < tile.layers.size(); l++) {
|
||||
mvt_layer &layer = tile.layers[l];
|
||||
int extent = layer.extent;
|
||||
|
||||
if (layer.extent <= 0) {
|
||||
fprintf(stderr, "Impossible layer extent %lld in mbtiles\n", layer.extent);
|
||||
exit(EXIT_FAILURE);
|
||||
if (describe) {
|
||||
if (l != 0) {
|
||||
printf(",\n");
|
||||
}
|
||||
|
||||
printf("{ \"type\": \"FeatureCollection\"");
|
||||
printf(", \"properties\": { \"layer\": ");
|
||||
printq(layer.name.c_str());
|
||||
printf(", \"version\": %d, \"extent\": %d", layer.version, layer.extent);
|
||||
printf(" }");
|
||||
printf(", \"features\": [\n");
|
||||
|
||||
within = 0;
|
||||
}
|
||||
|
||||
if (to_decode.size() != 0 && !to_decode.count(layer.name)) {
|
||||
continue;
|
||||
}
|
||||
for (size_t f = 0; f < layer.features.size(); f++) {
|
||||
mvt_feature &feat = layer.features[f];
|
||||
|
||||
if (!pipeline) {
|
||||
if (true) {
|
||||
if (!first_layer) {
|
||||
state.json_comma_newline();
|
||||
if (within) {
|
||||
printf(",\n");
|
||||
}
|
||||
within = 1;
|
||||
|
||||
printf("{ \"type\": \"Feature\"");
|
||||
|
||||
if (feat.has_id) {
|
||||
printf(", \"id\": %llu", feat.id);
|
||||
}
|
||||
|
||||
printf(", \"properties\": { ");
|
||||
|
||||
for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) {
|
||||
if (t != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
state.json_write_hash();
|
||||
if (feat.tags[t] >= layer.keys.size()) {
|
||||
fprintf(stderr, "Error: out of bounds feature key\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (feat.tags[t + 1] >= layer.values.size()) {
|
||||
fprintf(stderr, "Error: out of bounds feature value\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
state.json_write_string("type");
|
||||
state.json_write_string("FeatureCollection");
|
||||
const char *key = layer.keys[feat.tags[t]].c_str();
|
||||
mvt_value const &val = layer.values[feat.tags[t + 1]];
|
||||
|
||||
state.json_write_string("properties");
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("layer");
|
||||
state.json_write_string(layer.name);
|
||||
|
||||
state.json_write_string("version");
|
||||
state.json_write_signed(layer.version);
|
||||
|
||||
state.json_write_string("extent");
|
||||
state.json_write_signed(layer.extent);
|
||||
|
||||
state.json_end_hash();
|
||||
|
||||
state.json_write_string("features");
|
||||
state.json_write_array();
|
||||
|
||||
state.json_write_newline();
|
||||
first_layer = false;
|
||||
if (val.type == mvt_string) {
|
||||
printq(key);
|
||||
printf(": ");
|
||||
printq(val.string_value.c_str());
|
||||
} else if (val.type == mvt_int) {
|
||||
printq(key);
|
||||
printf(": %lld", (long long) val.numeric_value.int_value);
|
||||
} else if (val.type == mvt_double) {
|
||||
printq(key);
|
||||
double v = val.numeric_value.double_value;
|
||||
if (v == (long long) v) {
|
||||
printf(": %lld", (long long) v);
|
||||
} else {
|
||||
printf(": %g", v);
|
||||
}
|
||||
} else if (val.type == mvt_float) {
|
||||
printq(key);
|
||||
double v = val.numeric_value.float_value;
|
||||
if (v == (long long) v) {
|
||||
printf(": %lld", (long long) v);
|
||||
} else {
|
||||
printf(": %g", v);
|
||||
}
|
||||
} else if (val.type == mvt_sint) {
|
||||
printq(key);
|
||||
printf(": %lld", (long long) val.numeric_value.sint_value);
|
||||
} else if (val.type == mvt_uint) {
|
||||
printq(key);
|
||||
printf(": %lld", (long long) val.numeric_value.uint_value);
|
||||
} else if (val.type == mvt_bool) {
|
||||
printq(key);
|
||||
printf(": %s", val.numeric_value.bool_value ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
printf(" }, \"geometry\": { ");
|
||||
|
||||
std::vector<lonlat> ops;
|
||||
|
||||
for (size_t g = 0; g < feat.geometry.size(); g++) {
|
||||
int op = feat.geometry[g].op;
|
||||
long long px = feat.geometry[g].x;
|
||||
long long py = feat.geometry[g].y;
|
||||
|
||||
if (op == VT_MOVETO || op == VT_LINETO) {
|
||||
long long scale = 1LL << (32 - z);
|
||||
long long wx = scale * x + (scale / extent) * px;
|
||||
long long wy = scale * y + (scale / extent) * py;
|
||||
|
||||
double lat, lon;
|
||||
projection->unproject(wx, wy, 32, &lon, &lat);
|
||||
|
||||
ops.push_back(lonlat(op, lon, lat, px, py));
|
||||
} else {
|
||||
ops.push_back(lonlat(op, 0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (feat.type == VT_POINT) {
|
||||
if (ops.size() == 1) {
|
||||
printf("\"type\": \"Point\", \"coordinates\": [ %f, %f ]", ops[0].lon, ops[0].lat);
|
||||
} else {
|
||||
printf("\"type\": \"MultiPoint\", \"coordinates\": [ ");
|
||||
for (size_t i = 0; i < ops.size(); i++) {
|
||||
if (i != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
printf("[ %f, %f ]", ops[i].lon, ops[i].lat);
|
||||
}
|
||||
printf(" ]");
|
||||
}
|
||||
} else if (feat.type == VT_LINE) {
|
||||
int movetos = 0;
|
||||
for (size_t i = 0; i < ops.size(); i++) {
|
||||
if (ops[i].op == VT_MOVETO) {
|
||||
movetos++;
|
||||
}
|
||||
}
|
||||
|
||||
if (movetos < 2) {
|
||||
printf("\"type\": \"LineString\", \"coordinates\": [ ");
|
||||
for (size_t i = 0; i < ops.size(); i++) {
|
||||
if (i != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
printf("[ %f, %f ]", ops[i].lon, ops[i].lat);
|
||||
}
|
||||
printf(" ]");
|
||||
} else {
|
||||
printf("\"type\": \"MultiLineString\", \"coordinates\": [ [ ");
|
||||
int state = 0;
|
||||
for (size_t i = 0; i < ops.size(); i++) {
|
||||
if (ops[i].op == VT_MOVETO) {
|
||||
if (state == 0) {
|
||||
printf("[ %f, %f ]", ops[i].lon, ops[i].lat);
|
||||
state = 1;
|
||||
} else {
|
||||
printf(" ], [ ");
|
||||
printf("[ %f, %f ]", ops[i].lon, ops[i].lat);
|
||||
state = 1;
|
||||
}
|
||||
} else {
|
||||
printf(", [ %f, %f ]", ops[i].lon, ops[i].lat);
|
||||
}
|
||||
}
|
||||
printf(" ] ]");
|
||||
}
|
||||
} else if (feat.type == VT_POLYGON) {
|
||||
std::vector<std::vector<lonlat> > rings;
|
||||
std::vector<double> areas;
|
||||
|
||||
for (size_t i = 0; i < ops.size(); i++) {
|
||||
if (ops[i].op == VT_MOVETO) {
|
||||
rings.push_back(std::vector<lonlat>());
|
||||
areas.push_back(0);
|
||||
}
|
||||
|
||||
int n = rings.size() - 1;
|
||||
if (n >= 0) {
|
||||
if (ops[i].op == VT_CLOSEPATH) {
|
||||
rings[n].push_back(rings[n][0]);
|
||||
} else {
|
||||
rings[n].push_back(ops[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int outer = 0;
|
||||
|
||||
for (size_t i = 0; i < rings.size(); i++) {
|
||||
long double area = 0;
|
||||
for (size_t k = 0; k < rings[i].size(); k++) {
|
||||
if (rings[i][k].op != VT_CLOSEPATH) {
|
||||
area += rings[i][k].x * rings[i][(k + 1) % rings[i].size()].y;
|
||||
area -= rings[i][k].y * rings[i][(k + 1) % rings[i].size()].x;
|
||||
}
|
||||
}
|
||||
|
||||
areas[i] = area;
|
||||
if (areas[i] >= 0 || i == 0) {
|
||||
outer++;
|
||||
}
|
||||
|
||||
// printf("area %f\n", area / .00000274 / .00000274);
|
||||
}
|
||||
|
||||
if (outer > 1) {
|
||||
printf("\"type\": \"MultiPolygon\", \"coordinates\": [ [ [ ");
|
||||
} else {
|
||||
printf("\"type\": \"Polygon\", \"coordinates\": [ [ ");
|
||||
}
|
||||
|
||||
int state = 0;
|
||||
for (size_t i = 0; i < rings.size(); i++) {
|
||||
if (areas[i] >= 0) {
|
||||
if (state != 0) {
|
||||
// new multipolygon
|
||||
printf(" ] ], [ [ ");
|
||||
}
|
||||
state = 1;
|
||||
}
|
||||
|
||||
if (state == 2) {
|
||||
// new ring in the same polygon
|
||||
printf(" ], [ ");
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < rings[i].size(); j++) {
|
||||
if (rings[i][j].op != VT_CLOSEPATH) {
|
||||
if (j != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
printf("[ %f, %f ]", rings[i][j].lon, rings[i][j].lat);
|
||||
} else {
|
||||
if (j != 0) {
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
printf("[ %f, %f ]", rings[i][0].lon, rings[i][0].lat);
|
||||
}
|
||||
}
|
||||
|
||||
state = 2;
|
||||
}
|
||||
|
||||
if (outer > 1) {
|
||||
printf(" ] ] ]");
|
||||
} else {
|
||||
printf(" ] ]");
|
||||
}
|
||||
}
|
||||
|
||||
printf(" } }\n");
|
||||
}
|
||||
|
||||
// X and Y are unsigned, so no need to check <0
|
||||
if (x > (1ULL << z) || y > (1ULL << z)) {
|
||||
fprintf(stderr, "Impossible tile %d/%u/%u\n", z, x, y);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state);
|
||||
|
||||
if (!pipeline) {
|
||||
if (true) {
|
||||
state.json_end_array();
|
||||
state.json_end_hash();
|
||||
state.json_write_newline();
|
||||
}
|
||||
if (describe) {
|
||||
printf("] }\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!pipeline) {
|
||||
state.json_end_array();
|
||||
state.json_end_hash();
|
||||
state.json_write_newline();
|
||||
}
|
||||
printf("] }\n");
|
||||
}
|
||||
|
||||
void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats, std::set<std::string> const &exclude_meta) {
|
||||
sqlite3 *db = NULL;
|
||||
bool isdir = false;
|
||||
void decode(char *fname, int z, unsigned x, unsigned y) {
|
||||
sqlite3 *db;
|
||||
int oz = z;
|
||||
unsigned ox = x, oy = y;
|
||||
json_writer state(stdout);
|
||||
|
||||
int fd = open(fname, O_RDONLY | O_CLOEXEC);
|
||||
int fd = open(fname, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == 0) {
|
||||
@ -240,7 +345,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
|
||||
if (strcmp(map, "SQLite format 3") != 0) {
|
||||
if (z >= 0) {
|
||||
std::string s = std::string(map, st.st_size);
|
||||
handle(s, z, x, y, to_decode, pipeline, stats, state);
|
||||
handle(s, z, x, y, 1);
|
||||
munmap(map, st.st_size);
|
||||
return;
|
||||
} else {
|
||||
@ -254,188 +359,72 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
|
||||
} else {
|
||||
perror("fstat");
|
||||
}
|
||||
if (close(fd) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
perror(fname);
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
std::vector<zxy> tiles;
|
||||
if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) {
|
||||
isdir = true;
|
||||
|
||||
db = dirmeta2tmp(fname);
|
||||
tiles = enumerate_dirtiles(fname, minzoom, maxzoom);
|
||||
} else {
|
||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (z < 0) {
|
||||
printf("{ \"type\": \"FeatureCollection\", \"properties\": {\n");
|
||||
|
||||
const char *sql2 = "SELECT name, value from metadata order by name;";
|
||||
sqlite3_stmt *stmt2;
|
||||
if (sqlite3_prepare_v2(db, sql2, -1, &stmt2, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int within = 0;
|
||||
|
||||
if (!pipeline && !stats) {
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("type");
|
||||
state.json_write_string("FeatureCollection");
|
||||
|
||||
state.json_write_string("properties");
|
||||
state.json_write_hash();
|
||||
state.json_write_newline();
|
||||
|
||||
const char *sql2 = "SELECT name, value from metadata order by name;";
|
||||
sqlite3_stmt *stmt2;
|
||||
if (sqlite3_prepare_v2(db, sql2, -1, &stmt2, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
while (sqlite3_step(stmt2) == SQLITE_ROW) {
|
||||
if (within) {
|
||||
printf(",\n");
|
||||
}
|
||||
within = 1;
|
||||
|
||||
while (sqlite3_step(stmt2) == SQLITE_ROW) {
|
||||
const unsigned char *name = sqlite3_column_text(stmt2, 0);
|
||||
const unsigned char *value = sqlite3_column_text(stmt2, 1);
|
||||
const unsigned char *name = sqlite3_column_text(stmt2, 0);
|
||||
const unsigned char *value = sqlite3_column_text(stmt2, 1);
|
||||
|
||||
if (name == NULL || value == NULL) {
|
||||
fprintf(stderr, "Corrupt mbtiles file: null metadata\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printq((char *) name);
|
||||
printf(": ");
|
||||
printq((char *) value);
|
||||
}
|
||||
|
||||
if (exclude_meta.count((char *) name) == 0) {
|
||||
if (within) {
|
||||
state.json_comma_newline();
|
||||
}
|
||||
within = 1;
|
||||
sqlite3_finalize(stmt2);
|
||||
|
||||
state.json_write_string((char *) name);
|
||||
state.json_write_string((char *) value);
|
||||
}
|
||||
const char *sql = "SELECT tile_data, zoom_level, tile_column, tile_row from tiles order by zoom_level, tile_column, tile_row;";
|
||||
sqlite3_stmt *stmt;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("\n}, \"features\": [\n");
|
||||
|
||||
within = 0;
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if (within) {
|
||||
printf(",\n");
|
||||
}
|
||||
within = 1;
|
||||
|
||||
state.json_write_newline();
|
||||
state.wantnl = false; // XXX
|
||||
int len = sqlite3_column_bytes(stmt, 0);
|
||||
int tz = sqlite3_column_int(stmt, 1);
|
||||
int tx = sqlite3_column_int(stmt, 2);
|
||||
int ty = sqlite3_column_int(stmt, 3);
|
||||
ty = (1LL << tz) - 1 - ty;
|
||||
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
||||
|
||||
sqlite3_finalize(stmt2);
|
||||
handle(std::string(s, len), tz, tx, ty, 1);
|
||||
}
|
||||
|
||||
if (stats) {
|
||||
state.json_write_array();
|
||||
state.json_write_newline();
|
||||
}
|
||||
printf("] }\n");
|
||||
|
||||
if (!pipeline && !stats) {
|
||||
state.json_end_hash();
|
||||
|
||||
state.json_write_string("features");
|
||||
state.json_write_array();
|
||||
state.json_write_newline();
|
||||
}
|
||||
|
||||
if (isdir) {
|
||||
within = 0;
|
||||
for (size_t i = 0; i < tiles.size(); i++) {
|
||||
if (!pipeline && !stats) {
|
||||
if (within) {
|
||||
state.json_comma_newline();
|
||||
}
|
||||
within = 1;
|
||||
}
|
||||
if (stats) {
|
||||
if (within) {
|
||||
state.json_comma_newline();
|
||||
}
|
||||
within = 1;
|
||||
}
|
||||
|
||||
std::string fn = std::string(fname) + "/" + tiles[i].path();
|
||||
FILE *f = fopen(fn.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
perror(fn.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string s;
|
||||
char buf[2000];
|
||||
ssize_t n;
|
||||
while ((n = fread(buf, 1, 2000, f)) > 0) {
|
||||
s.append(std::string(buf, n));
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
handle(s, tiles[i].z, tiles[i].x, tiles[i].y, to_decode, pipeline, stats, state);
|
||||
}
|
||||
} else {
|
||||
const char *sql = "SELECT tile_data, zoom_level, tile_column, tile_row from tiles where zoom_level between ? and ? order by zoom_level, tile_column, tile_row;";
|
||||
sqlite3_stmt *stmt;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sqlite3_bind_int(stmt, 1, minzoom);
|
||||
sqlite3_bind_int(stmt, 2, maxzoom);
|
||||
|
||||
within = 0;
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if (!pipeline && !stats) {
|
||||
if (within) {
|
||||
state.json_comma_newline();
|
||||
}
|
||||
within = 1;
|
||||
}
|
||||
if (stats) {
|
||||
if (within) {
|
||||
state.json_comma_newline();
|
||||
}
|
||||
within = 1;
|
||||
}
|
||||
|
||||
int len = sqlite3_column_bytes(stmt, 0);
|
||||
int tz = sqlite3_column_int(stmt, 1);
|
||||
int tx = sqlite3_column_int(stmt, 2);
|
||||
int ty = sqlite3_column_int(stmt, 3);
|
||||
|
||||
if (tz < 0 || tz >= 32) {
|
||||
fprintf(stderr, "Impossible zoom level %d in mbtiles\n", tz);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ty = (1LL << tz) - 1 - ty;
|
||||
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
||||
|
||||
if (s == NULL) {
|
||||
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
if (!pipeline && !stats) {
|
||||
state.json_end_array();
|
||||
state.json_end_hash();
|
||||
state.json_write_newline();
|
||||
}
|
||||
if (stats) {
|
||||
state.json_end_array();
|
||||
state.json_write_newline();
|
||||
}
|
||||
if (pipeline) {
|
||||
state.json_write_newline();
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
} else {
|
||||
int handled = 0;
|
||||
while (z >= 0 && !handled) {
|
||||
@ -454,16 +443,11 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
|
||||
int len = sqlite3_column_bytes(stmt, 0);
|
||||
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
||||
|
||||
if (s == NULL) {
|
||||
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (z != oz) {
|
||||
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
|
||||
}
|
||||
|
||||
handle(std::string(s, len), z, x, y, to_decode, pipeline, stats, state);
|
||||
handle(std::string(s, len), z, x, y, 0);
|
||||
handled = 1;
|
||||
}
|
||||
|
||||
@ -482,7 +466,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
|
||||
}
|
||||
|
||||
void usage(char **argv) {
|
||||
fprintf(stderr, "Usage: %s [-s projection] [-Z minzoom] [-z maxzoom] [-l layer ...] file.mbtiles [zoom x y]\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s [-t projection] file.mbtiles zoom x y\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -490,80 +474,22 @@ int main(int argc, char **argv) {
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
int i;
|
||||
std::set<std::string> to_decode;
|
||||
bool pipeline = false;
|
||||
bool stats = false;
|
||||
std::set<std::string> exclude_meta;
|
||||
|
||||
struct option long_options[] = {
|
||||
{"projection", required_argument, 0, 's'},
|
||||
{"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},
|
||||
};
|
||||
|
||||
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(argc, argv, "t:")) != -1) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 's':
|
||||
case 't':
|
||||
set_projection_or_exit(optarg);
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
maxzoom = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
minzoom = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
to_decode.insert(optarg);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
pipeline = true;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
stats = true;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
force = true;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
exclude_meta.insert(optarg);
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(argv);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == optind + 4) {
|
||||
decode(argv[optind], atoi(argv[optind + 1]), atoi(argv[optind + 2]), atoi(argv[optind + 3]), to_decode, pipeline, stats, exclude_meta);
|
||||
decode(argv[optind], atoi(argv[optind + 1]), atoi(argv[optind + 2]), atoi(argv[optind + 3]));
|
||||
} else if (argc == optind + 1) {
|
||||
decode(argv[optind], -1, -1, -1, to_decode, pipeline, stats, exclude_meta);
|
||||
decode(argv[optind], -1, -1, -1);
|
||||
} else {
|
||||
usage(argv);
|
||||
}
|
||||
|
211
dirtiles.cpp
211
dirtiles.cpp
@ -1,211 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sqlite3.h>
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "dirtiles.hpp"
|
||||
|
||||
std::string dir_read_tile(std::string base, struct zxy tile) {
|
||||
std::ifstream pbfFile(base + "/" + tile.path(), std::ios::in | std::ios::binary);
|
||||
std::ostringstream contents;
|
||||
contents << pbfFile.rdbuf();
|
||||
pbfFile.close();
|
||||
|
||||
return (contents.str());
|
||||
}
|
||||
|
||||
void dir_write_tile(const char *outdir, int z, int tx, int ty, std::string const &pbf) {
|
||||
mkdir(outdir, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
std::string curdir(outdir);
|
||||
std::string slash("/");
|
||||
std::string newdir = curdir + slash + std::to_string(z);
|
||||
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
newdir = newdir + "/" + std::to_string(tx);
|
||||
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
newdir = newdir + "/" + std::to_string(ty) + ".pbf";
|
||||
|
||||
struct stat st;
|
||||
if (stat(newdir.c_str(), &st) == 0) {
|
||||
fprintf(stderr, "Can't write tile to already existing %s\n", newdir.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::ofstream pbfFile(newdir, std::ios::out | std::ios::binary);
|
||||
pbfFile.write(pbf.data(), pbf.size());
|
||||
pbfFile.close();
|
||||
}
|
||||
|
||||
static bool numeric(const char *s) {
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
}
|
||||
for (; *s != 0; s++) {
|
||||
if (*s < '0' || *s > '9') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool pbfname(const char *s) {
|
||||
while (*s >= '0' && *s <= '9') {
|
||||
s++;
|
||||
}
|
||||
|
||||
return strcmp(s, ".pbf") == 0 || strcmp(s, ".mvt") == 0;
|
||||
}
|
||||
|
||||
void check_dir(const char *dir, char **argv, bool force, bool forcetable) {
|
||||
struct stat st;
|
||||
|
||||
mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
std::string meta = std::string(dir) + "/" + "metadata.json";
|
||||
if (force) {
|
||||
unlink(meta.c_str()); // error OK since it may not exist;
|
||||
} else {
|
||||
if (stat(meta.c_str(), &st) == 0) {
|
||||
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", argv[0], dir);
|
||||
fprintf(stderr, "%s: %s: file exists\n", argv[0], meta.c_str());
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forcetable) {
|
||||
// Don't clear existing tiles
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<zxy> tiles = enumerate_dirtiles(dir, INT_MIN, INT_MAX);
|
||||
|
||||
for (size_t i = 0; i < tiles.size(); i++) {
|
||||
std::string fn = std::string(dir) + "/" + tiles[i].path();
|
||||
|
||||
if (force) {
|
||||
if (unlink(fn.c_str()) != 0) {
|
||||
perror(fn.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%s: file exists\n", fn.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom) {
|
||||
std::vector<zxy> tiles;
|
||||
|
||||
DIR *d1 = opendir(fname);
|
||||
if (d1 != NULL) {
|
||||
struct dirent *dp;
|
||||
while ((dp = readdir(d1)) != NULL) {
|
||||
if (numeric(dp->d_name) && atoi(dp->d_name) >= minzoom && atoi(dp->d_name) <= maxzoom) {
|
||||
std::string z = std::string(fname) + "/" + dp->d_name;
|
||||
int tz = atoi(dp->d_name);
|
||||
|
||||
DIR *d2 = opendir(z.c_str());
|
||||
if (d2 == NULL) {
|
||||
perror(z.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct dirent *dp2;
|
||||
while ((dp2 = readdir(d2)) != NULL) {
|
||||
if (numeric(dp2->d_name)) {
|
||||
std::string x = z + "/" + dp2->d_name;
|
||||
int tx = atoi(dp2->d_name);
|
||||
|
||||
DIR *d3 = opendir(x.c_str());
|
||||
if (d3 == NULL) {
|
||||
perror(x.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct dirent *dp3;
|
||||
while ((dp3 = readdir(d3)) != NULL) {
|
||||
if (pbfname(dp3->d_name)) {
|
||||
int ty = atoi(dp3->d_name);
|
||||
zxy tile(tz, tx, ty);
|
||||
if (strstr(dp3->d_name, ".mvt") != NULL) {
|
||||
tile.extension = ".mvt";
|
||||
}
|
||||
|
||||
tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d3);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d2);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d1);
|
||||
}
|
||||
|
||||
std::sort(tiles.begin(), tiles.end());
|
||||
return tiles;
|
||||
}
|
||||
|
||||
sqlite3 *dirmeta2tmp(const char *fname) {
|
||||
sqlite3 *db;
|
||||
char *err = NULL;
|
||||
|
||||
if (sqlite3_open("", &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "Temporary db: %s\n", sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(db, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "Create metadata table: %s\n", err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string name = fname;
|
||||
name += "/metadata.json";
|
||||
|
||||
FILE *f = fopen(name.c_str(), "r");
|
||||
if (f == NULL) {
|
||||
perror(name.c_str());
|
||||
} else {
|
||||
json_pull *jp = json_begin_file(f);
|
||||
json_object *o = json_read_tree(jp);
|
||||
if (o == NULL) {
|
||||
fprintf(stderr, "%s: metadata parsing error: %s\n", name.c_str(), jp->error);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (o->type != JSON_HASH) {
|
||||
fprintf(stderr, "%s: bad metadata format\n", name.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < o->length; i++) {
|
||||
if (o->keys[i]->type != JSON_STRING || o->values[i]->type != JSON_STRING) {
|
||||
fprintf(stderr, "%s: non-string in metadata\n", name.c_str());
|
||||
}
|
||||
|
||||
char *sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES (%Q, %Q);", o->keys[i]->string, o->values[i]->string);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set %s in metadata: %s\n", o->keys[i]->string, err);
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
}
|
||||
|
||||
json_end(jp);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
49
dirtiles.hpp
49
dirtiles.hpp
@ -1,49 +0,0 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef DIRTILES_HPP
|
||||
#define DIRTILES_HPP
|
||||
|
||||
void dir_write_tile(const char *outdir, int z, int tx, int ty, std::string const &pbf);
|
||||
|
||||
void check_dir(const char *d, char **argv, bool force, bool forcetable);
|
||||
|
||||
struct zxy {
|
||||
long long z;
|
||||
long long x;
|
||||
long long y;
|
||||
std::string extension = ".pbf";
|
||||
|
||||
zxy(int _z, int _x, int _y)
|
||||
: z(_z), x(_x), y(_y) {
|
||||
}
|
||||
|
||||
bool operator<(const zxy &other) const {
|
||||
if (z < other.z) {
|
||||
return true;
|
||||
}
|
||||
if (z == other.z) {
|
||||
if (x < other.x) {
|
||||
return true;
|
||||
}
|
||||
if (x == other.x) {
|
||||
if (y > other.y) {
|
||||
return true; // reversed for TMS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string path() {
|
||||
return std::to_string(z) + "/" + std::to_string(x) + "/" + std::to_string(y) + extension;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom);
|
||||
sqlite3 *dirmeta2tmp(const char *fname);
|
||||
std::string dir_read_tile(std::string pbfPath, struct zxy tile);
|
||||
|
||||
#endif
|
@ -11,12 +11,6 @@ void enumerate(char *fname) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *sql = "SELECT zoom_level, tile_column, tile_row from tiles order by zoom_level, tile_column, tile_row;";
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
@ -30,11 +24,6 @@ void enumerate(char *fname) {
|
||||
long long x = sqlite3_column_int(stmt, 1);
|
||||
long long y = sqlite3_column_int(stmt, 2);
|
||||
|
||||
if (zoom < 0 || zoom > 31) {
|
||||
fprintf(stderr, "Corrupt mbtiles file: impossible zoom level %lld\n", zoom);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
y = (1LL << zoom) - 1 - y;
|
||||
printf("%s %lld %lld %lld\n", fname, zoom, x, y);
|
||||
}
|
||||
|
347
evaluator.cpp
347
evaluator.cpp
@ -1,347 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <map>
|
||||
#include "mvt.hpp"
|
||||
#include "evaluator.hpp"
|
||||
|
||||
int compare(mvt_value one, json_object *two, bool &fail) {
|
||||
if (one.type == mvt_string) {
|
||||
if (two->type != JSON_STRING) {
|
||||
fail = true;
|
||||
return false; // string vs non-string
|
||||
}
|
||||
|
||||
return strcmp(one.string_value.c_str(), two->string);
|
||||
}
|
||||
|
||||
if (one.type == mvt_double || one.type == mvt_float || one.type == mvt_int || one.type == mvt_uint || one.type == mvt_sint) {
|
||||
if (two->type != JSON_NUMBER) {
|
||||
fail = true;
|
||||
return false; // number vs non-number
|
||||
}
|
||||
|
||||
double v;
|
||||
if (one.type == mvt_double) {
|
||||
v = one.numeric_value.double_value;
|
||||
} else if (one.type == mvt_float) {
|
||||
v = one.numeric_value.float_value;
|
||||
} else if (one.type == mvt_int) {
|
||||
v = one.numeric_value.int_value;
|
||||
} else if (one.type == mvt_uint) {
|
||||
v = one.numeric_value.uint_value;
|
||||
} else if (one.type == mvt_sint) {
|
||||
v = one.numeric_value.sint_value;
|
||||
} else {
|
||||
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (v < two->number) {
|
||||
return -1;
|
||||
} else if (v > two->number) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (one.type == mvt_bool) {
|
||||
if (two->type != JSON_TRUE && two->type != JSON_FALSE) {
|
||||
fail = true;
|
||||
return false; // bool vs non-bool
|
||||
}
|
||||
|
||||
bool b = two->type != JSON_FALSE;
|
||||
return one.numeric_value.bool_value > b;
|
||||
}
|
||||
|
||||
if (one.type == mvt_null) {
|
||||
if (two->type != JSON_NULL) {
|
||||
fail = true;
|
||||
return false; // null vs non-null
|
||||
}
|
||||
|
||||
return 0; // null equals null
|
||||
}
|
||||
|
||||
fprintf(stderr, "Internal error: bad mvt type %d\n", one.type);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
bool eval(std::map<std::string, mvt_value> const &feature, json_object *f, std::set<std::string> &exclude_attributes) {
|
||||
if (f == NULL || f->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "Filter is not an array: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (f->length < 1) {
|
||||
fprintf(stderr, "Array too small in filter: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (f->array[0]->type != JSON_STRING) {
|
||||
fprintf(stderr, "Filter operation is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "has") == 0 ||
|
||||
strcmp(f->array[0]->string, "!has") == 0) {
|
||||
if (f->length != 2) {
|
||||
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "has") == 0) {
|
||||
if (f->array[1]->type != JSON_STRING) {
|
||||
fprintf(stderr, "\"has\" key is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return feature.count(std::string(f->array[1]->string)) != 0;
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "!has") == 0) {
|
||||
if (f->array[1]->type != JSON_STRING) {
|
||||
fprintf(stderr, "\"!has\" key is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return feature.count(std::string(f->array[1]->string)) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "==") == 0 ||
|
||||
strcmp(f->array[0]->string, "!=") == 0 ||
|
||||
strcmp(f->array[0]->string, ">") == 0 ||
|
||||
strcmp(f->array[0]->string, ">=") == 0 ||
|
||||
strcmp(f->array[0]->string, "<") == 0 ||
|
||||
strcmp(f->array[0]->string, "<=") == 0) {
|
||||
if (f->length != 3) {
|
||||
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (f->array[1]->type != JSON_STRING) {
|
||||
fprintf(stderr, "\"!has\" key is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
auto ff = feature.find(std::string(f->array[1]->string));
|
||||
if (ff == feature.end()) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
const char *s = json_stringify(f);
|
||||
fprintf(stderr, "Warning: attribute not found for comparison: %s\n", s);
|
||||
free((void *) s);
|
||||
warned = true;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "!=") == 0) {
|
||||
return true; // attributes that aren't found are not equal
|
||||
}
|
||||
return false; // not found: comparison is false
|
||||
}
|
||||
|
||||
bool fail = false;
|
||||
int cmp = compare(ff->second, f->array[2], fail);
|
||||
|
||||
if (fail) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
const char *s = json_stringify(f);
|
||||
fprintf(stderr, "Warning: mismatched type in comparison: %s\n", s);
|
||||
free((void *) s);
|
||||
warned = true;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "!=") == 0) {
|
||||
return true; // mismatched types are not equal
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "==") == 0) {
|
||||
return cmp == 0;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "!=") == 0) {
|
||||
return cmp != 0;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, ">") == 0) {
|
||||
return cmp > 0;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, ">=") == 0) {
|
||||
return cmp >= 0;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "<") == 0) {
|
||||
return cmp < 0;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "<=") == 0) {
|
||||
return cmp <= 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Internal error: can't happen: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "all") == 0 ||
|
||||
strcmp(f->array[0]->string, "any") == 0 ||
|
||||
strcmp(f->array[0]->string, "none") == 0) {
|
||||
bool v;
|
||||
|
||||
if (strcmp(f->array[0]->string, "all") == 0) {
|
||||
v = true;
|
||||
} else {
|
||||
v = false;
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < f->length; i++) {
|
||||
bool out = eval(feature, f->array[i], exclude_attributes);
|
||||
|
||||
if (strcmp(f->array[0]->string, "all") == 0) {
|
||||
v = v && out;
|
||||
if (!v) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
v = v || out;
|
||||
if (v) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "none") == 0) {
|
||||
return !v;
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "in") == 0 ||
|
||||
strcmp(f->array[0]->string, "!in") == 0) {
|
||||
if (f->length < 2) {
|
||||
fprintf(stderr, "Array too small in filter: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (f->array[1]->type != JSON_STRING) {
|
||||
fprintf(stderr, "\"!has\" key is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
auto ff = feature.find(std::string(f->array[1]->string));
|
||||
if (ff == feature.end()) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
const char *s = json_stringify(f);
|
||||
fprintf(stderr, "Warning: attribute not found for comparison: %s\n", s);
|
||||
free((void *) s);
|
||||
warned = true;
|
||||
}
|
||||
if (strcmp(f->array[0]->string, "!in") == 0) {
|
||||
return true; // attributes that aren't found are not in
|
||||
}
|
||||
return false; // not found: comparison is false
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for (size_t i = 2; i < f->length; i++) {
|
||||
bool fail = false;
|
||||
int cmp = compare(ff->second, f->array[i], fail);
|
||||
|
||||
if (fail) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
const char *s = json_stringify(f);
|
||||
fprintf(stderr, "Warning: mismatched type in comparison: %s\n", s);
|
||||
free((void *) s);
|
||||
warned = true;
|
||||
}
|
||||
cmp = 1;
|
||||
}
|
||||
|
||||
if (cmp == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "in") == 0) {
|
||||
return found;
|
||||
} else {
|
||||
return !found;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(f->array[0]->string, "attribute-filter") == 0) {
|
||||
if (f->length != 3) {
|
||||
fprintf(stderr, "Wrong number of array elements in filter: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (f->array[1]->type != JSON_STRING) {
|
||||
fprintf(stderr, "\"attribute-filter\" key is not a string: %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
bool ok = eval(feature, f->array[2], exclude_attributes);
|
||||
if (!ok) {
|
||||
exclude_attributes.insert(f->array[1]->string);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Unknown filter %s\n", json_stringify(f));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
bool evaluate(std::map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes) {
|
||||
if (filter == NULL || filter->type != JSON_HASH) {
|
||||
fprintf(stderr, "Error: filter is not a hash: %s\n", json_stringify(filter));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
json_object *f;
|
||||
|
||||
f = json_hash_get(filter, layer.c_str());
|
||||
if (ok && f != NULL) {
|
||||
ok = eval(feature, f, exclude_attributes);
|
||||
}
|
||||
|
||||
f = json_hash_get(filter, "*");
|
||||
if (ok && f != NULL) {
|
||||
ok = eval(feature, f, exclude_attributes);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
json_object *read_filter(const char *fname) {
|
||||
FILE *fp = fopen(fname, "r");
|
||||
if (fp == NULL) {
|
||||
perror(fname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_pull *jp = json_begin_file(fp);
|
||||
json_object *filter = json_read_tree(jp);
|
||||
if (filter == NULL) {
|
||||
fprintf(stderr, "%s: %s\n", fname, jp->error);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
json_disconnect(filter);
|
||||
json_end(jp);
|
||||
fclose(fp);
|
||||
return filter;
|
||||
}
|
||||
|
||||
json_object *parse_filter(const char *s) {
|
||||
json_pull *jp = json_begin_string(s);
|
||||
json_object *filter = json_read_tree(jp);
|
||||
if (filter == NULL) {
|
||||
fprintf(stderr, "Could not parse filter %s\n", s);
|
||||
fprintf(stderr, "%s\n", jp->error);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
json_disconnect(filter);
|
||||
json_end(jp);
|
||||
return filter;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#ifndef EVALUATOR_HPP
|
||||
#define EVALUATOR HPP
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "mvt.hpp"
|
||||
|
||||
bool evaluate(std::map<std::string, mvt_value> const &feature, std::string const &layer, json_object *filter, std::set<std::string> &exclude_attributes);
|
||||
json_object *parse_filter(const char *s);
|
||||
json_object *read_filter(const char *fname);
|
||||
|
||||
#endif
|
@ -1,27 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use Math::Trig;
|
||||
use strict;
|
||||
|
||||
# http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
||||
sub getTileNumber {
|
||||
my ($lat, $lon, $zoom) = @_;
|
||||
my $xtile = int(($lon + 180) / 360 * 2 ** $zoom);
|
||||
my $ytile = int((1 - log(tan(deg2rad($lat)) + sec(deg2rad($lat))) / pi) / 2 * 2 ** $zoom);
|
||||
return ($xtile, $ytile);
|
||||
}
|
||||
|
||||
my ($minlon, $minlat, $maxlon, $maxlat, $z, $x, $y) = @ARGV;
|
||||
|
||||
my ($x1, $y1) = getTileNumber($maxlat, $minlon, $z);
|
||||
my ($x2, $y2) = getTileNumber($minlat, $maxlon, $z);
|
||||
|
||||
if ($x >= $x1 && $x <= $x2 && $y >= $y1 && $y <= $y2) {
|
||||
while (<STDIN>) {
|
||||
print;
|
||||
}
|
||||
} else {
|
||||
while (<STDIN>) {
|
||||
|
||||
}
|
||||
}
|
585
geobuf.cpp
585
geobuf.cpp
@ -1,585 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include "mvt.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "geobuf.hpp"
|
||||
#include "geojson.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "main.hpp"
|
||||
#include "protozero/varint.hpp"
|
||||
#include "protozero/pbf_reader.hpp"
|
||||
#include "protozero/pbf_writer.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "text.hpp"
|
||||
|
||||
#define POINT 0
|
||||
#define MULTIPOINT 1
|
||||
#define LINESTRING 2
|
||||
#define MULTILINESTRING 3
|
||||
#define POLYGON 4
|
||||
#define MULTIPOLYGON 5
|
||||
|
||||
struct queued_feature {
|
||||
protozero::pbf_reader pbf{};
|
||||
size_t dim = 0;
|
||||
double e = 0;
|
||||
std::vector<std::string> *keys = NULL;
|
||||
std::vector<struct serialization_state> *sst = NULL;
|
||||
int layer = 0;
|
||||
std::string layername = "";
|
||||
};
|
||||
|
||||
static std::vector<queued_feature> feature_queue;
|
||||
|
||||
void ensureDim(size_t dim) {
|
||||
if (dim < 2) {
|
||||
fprintf(stderr, "Geometry has fewer than 2 dimensions: %zu\n", dim);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
serial_val readValue(protozero::pbf_reader &pbf) {
|
||||
serial_val sv;
|
||||
sv.type = mvt_null;
|
||||
sv.s = "null";
|
||||
|
||||
while (pbf.next()) {
|
||||
switch (pbf.tag()) {
|
||||
case 1:
|
||||
sv.type = mvt_string;
|
||||
sv.s = pbf.get_string();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
sv.type = mvt_double;
|
||||
sv.s = milo::dtoa_milo(pbf.get_double());
|
||||
break;
|
||||
|
||||
case 3:
|
||||
sv.type = mvt_double;
|
||||
sv.s = std::to_string(pbf.get_uint64());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
sv.type = mvt_double;
|
||||
sv.s = std::to_string(-(long long) pbf.get_uint64());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
sv.type = mvt_bool;
|
||||
if (pbf.get_bool()) {
|
||||
sv.s = "true";
|
||||
} else {
|
||||
sv.s = "false";
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
sv.type = mvt_string; // stringified JSON
|
||||
sv.s = pbf.get_string();
|
||||
|
||||
if (sv.s == "null") {
|
||||
sv.type = mvt_null;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
pbf.skip();
|
||||
}
|
||||
}
|
||||
|
||||
return sv;
|
||||
}
|
||||
|
||||
drawvec readPoint(std::vector<long long> &coords, size_t dim, double e) {
|
||||
ensureDim(dim);
|
||||
|
||||
long long x, y;
|
||||
projection->project(coords[0] / e, coords[1] / e, 32, &x, &y);
|
||||
drawvec dv;
|
||||
dv.push_back(draw(VT_MOVETO, x, y));
|
||||
return dv;
|
||||
}
|
||||
|
||||
drawvec readLinePart(std::vector<long long> &coords, size_t dim, double e, size_t start, size_t end, bool closed) {
|
||||
ensureDim(dim);
|
||||
|
||||
drawvec dv;
|
||||
std::vector<long long> prev;
|
||||
std::vector<double> p;
|
||||
prev.resize(dim);
|
||||
p.resize(dim);
|
||||
|
||||
for (size_t i = start; i + dim - 1 < end; i += dim) {
|
||||
if (i + dim - 1 >= coords.size()) {
|
||||
fprintf(stderr, "Internal error: line segment %zu vs %zu\n", i + dim - 1, coords.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (size_t d = 0; d < dim; d++) {
|
||||
prev[d] += coords[i + d];
|
||||
p[d] = prev[d] / e;
|
||||
}
|
||||
|
||||
long long x, y;
|
||||
projection->project(p[0], p[1], 32, &x, &y);
|
||||
|
||||
if (i == start) {
|
||||
dv.push_back(draw(VT_MOVETO, x, y));
|
||||
} else {
|
||||
dv.push_back(draw(VT_LINETO, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
if (closed && dv.size() > 0) {
|
||||
dv.push_back(draw(VT_LINETO, dv[0].x, dv[0].y));
|
||||
}
|
||||
|
||||
return dv;
|
||||
}
|
||||
|
||||
drawvec readLine(std::vector<long long> &coords, size_t dim, double e, bool closed) {
|
||||
return readLinePart(coords, dim, e, 0, coords.size(), closed);
|
||||
}
|
||||
|
||||
drawvec readMultiLine(std::vector<long long> &coords, std::vector<int> &lengths, size_t dim, double e, bool closed) {
|
||||
if (lengths.size() == 0) {
|
||||
return readLinePart(coords, dim, e, 0, coords.size(), closed);
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
size_t here = 0;
|
||||
for (size_t i = 0; i < lengths.size(); i++) {
|
||||
drawvec dv2 = readLinePart(coords, dim, e, here, here + lengths[i] * dim, closed);
|
||||
here += lengths[i] * dim;
|
||||
|
||||
for (size_t j = 0; j < dv2.size(); j++) {
|
||||
dv.push_back(dv2[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return dv;
|
||||
}
|
||||
|
||||
drawvec readMultiPolygon(std::vector<long long> &coords, std::vector<int> &lengths, size_t dim, double e) {
|
||||
ensureDim(dim);
|
||||
|
||||
if (lengths.size() == 0) {
|
||||
return readLinePart(coords, dim, e, 0, coords.size(), true);
|
||||
}
|
||||
|
||||
size_t polys = lengths[0];
|
||||
size_t n = 1;
|
||||
size_t here = 0;
|
||||
drawvec dv;
|
||||
|
||||
for (size_t i = 0; i < polys; i++) {
|
||||
size_t rings = lengths[n++];
|
||||
|
||||
for (size_t j = 0; j < rings; j++) {
|
||||
drawvec dv2 = readLinePart(coords, dim, e, here, here + lengths[n] * dim, true);
|
||||
here += lengths[n] * dim;
|
||||
n++;
|
||||
|
||||
for (size_t k = 0; k < dv2.size(); k++) {
|
||||
dv.push_back(dv2[k]);
|
||||
}
|
||||
}
|
||||
|
||||
dv.push_back(draw(VT_CLOSEPATH, 0, 0)); // mark that the next ring is outer
|
||||
}
|
||||
|
||||
return dv;
|
||||
}
|
||||
|
||||
struct drawvec_type {
|
||||
drawvec dv{};
|
||||
int type = 0;
|
||||
};
|
||||
|
||||
std::vector<drawvec_type> readGeometry(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<std::string> &keys) {
|
||||
std::vector<drawvec_type> ret;
|
||||
std::vector<long long> coords;
|
||||
std::vector<int> lengths;
|
||||
int type = -1;
|
||||
|
||||
while (pbf.next()) {
|
||||
switch (pbf.tag()) {
|
||||
case 1:
|
||||
type = pbf.get_enum();
|
||||
break;
|
||||
|
||||
case 2: {
|
||||
auto pi = pbf.get_packed_uint32();
|
||||
for (auto it = pi.first; it != pi.second; ++it) {
|
||||
lengths.push_back(*it);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: {
|
||||
auto pi = pbf.get_packed_sint64();
|
||||
for (auto it = pi.first; it != pi.second; ++it) {
|
||||
coords.push_back(*it);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: {
|
||||
protozero::pbf_reader geometry_reader(pbf.get_message());
|
||||
std::vector<drawvec_type> dv2 = readGeometry(geometry_reader, dim, e, keys);
|
||||
|
||||
for (size_t i = 0; i < dv2.size(); i++) {
|
||||
ret.push_back(dv2[i]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
pbf.skip();
|
||||
}
|
||||
}
|
||||
|
||||
drawvec_type dv;
|
||||
if (type == POINT) {
|
||||
dv.dv = readPoint(coords, dim, e);
|
||||
} else if (type == MULTIPOINT) {
|
||||
dv.dv = readLine(coords, dim, e, false);
|
||||
} else if (type == LINESTRING) {
|
||||
dv.dv = readLine(coords, dim, e, false);
|
||||
} else if (type == POLYGON) {
|
||||
dv.dv = readMultiLine(coords, lengths, dim, e, true);
|
||||
} else if (type == MULTILINESTRING) {
|
||||
dv.dv = readMultiLine(coords, lengths, dim, e, false);
|
||||
} else if (type == MULTIPOLYGON) {
|
||||
dv.dv = readMultiPolygon(coords, lengths, dim, e);
|
||||
} else {
|
||||
// GeometryCollection
|
||||
return ret;
|
||||
}
|
||||
|
||||
dv.type = type / 2 + 1;
|
||||
ret.push_back(dv);
|
||||
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) {
|
||||
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<serial_val> full_values;
|
||||
|
||||
while (pbf.next()) {
|
||||
switch (pbf.tag()) {
|
||||
case 1: {
|
||||
protozero::pbf_reader geometry_reader(pbf.get_message());
|
||||
std::vector<drawvec_type> dv2 = readGeometry(geometry_reader, dim, e, keys);
|
||||
for (size_t i = 0; i < dv2.size(); i++) {
|
||||
dv.push_back(dv2[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 11: {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Non-numeric feature IDs not supported\n");
|
||||
warned = true;
|
||||
}
|
||||
pbf.skip();
|
||||
break;
|
||||
}
|
||||
|
||||
case 12:
|
||||
has_id = true;
|
||||
id = pbf.get_sint64();
|
||||
if (id < 0) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Out of range feature id %lld\n", id);
|
||||
warned = true;
|
||||
}
|
||||
has_id = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 13: {
|
||||
protozero::pbf_reader value_reader(pbf.get_message());
|
||||
values.push_back(readValue(value_reader));
|
||||
break;
|
||||
}
|
||||
|
||||
case 14: {
|
||||
std::vector<size_t> properties;
|
||||
auto pi = pbf.get_packed_uint32();
|
||||
for (auto it = pi.first; it != pi.second; ++it) {
|
||||
properties.push_back(*it);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i + 1 < properties.size(); i += 2) {
|
||||
if (properties[i] >= keys.size()) {
|
||||
fprintf(stderr, "Out of bounds key: %zu in %zu\n", properties[i], keys.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (properties[i + 1] >= values.size()) {
|
||||
fprintf(stderr, "Out of bounds value: %zu in %zu\n", properties[i + 1], values.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
full_keys.push_back(keys[properties[i]]);
|
||||
full_values.push_back(values[properties[i + 1]]);
|
||||
}
|
||||
|
||||
values.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
case 15: {
|
||||
std::vector<size_t> misc;
|
||||
auto pi = pbf.get_packed_uint32();
|
||||
for (auto it = pi.first; it != pi.second; ++it) {
|
||||
misc.push_back(*it);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i + 1 < misc.size(); i += 2) {
|
||||
if (misc[i] >= keys.size()) {
|
||||
fprintf(stderr, "Out of bounds key: %zu in %zu\n", misc[i], keys.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (misc[i + 1] >= values.size()) {
|
||||
fprintf(stderr, "Out of bounds value: %zu in %zu\n", misc[i + 1], values.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
other.insert(std::pair<std::string, serial_val>(keys[misc[i]], values[misc[i + 1]]));
|
||||
}
|
||||
|
||||
values.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
pbf.skip();
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
serial_feature sf;
|
||||
|
||||
sf.layer = layer;
|
||||
sf.layername = layername;
|
||||
sf.segment = sst->segment;
|
||||
sf.has_id = has_id;
|
||||
sf.id = id;
|
||||
sf.has_tippecanoe_minzoom = false;
|
||||
sf.has_tippecanoe_maxzoom = false;
|
||||
sf.feature_minzoom = false;
|
||||
sf.seq = *(sst->layer_seq);
|
||||
sf.geometry = dv[i].dv;
|
||||
sf.t = dv[i].type;
|
||||
sf.full_keys = full_keys;
|
||||
sf.full_values = full_values;
|
||||
|
||||
auto tip = other.find("tippecanoe");
|
||||
if (tip != other.end()) {
|
||||
json_pull *jp = json_begin_string(tip->second.s.c_str());
|
||||
json_object *o = json_read_tree(jp);
|
||||
|
||||
if (o != NULL) {
|
||||
json_object *min = json_hash_get(o, "minzoom");
|
||||
if (min != NULL && (min->type == JSON_STRING || min->type == JSON_NUMBER)) {
|
||||
sf.has_tippecanoe_minzoom = true;
|
||||
sf.tippecanoe_minzoom = integer_zoom(sst->fname, min->string);
|
||||
}
|
||||
|
||||
json_object *max = json_hash_get(o, "maxzoom");
|
||||
if (max != NULL && (max->type == JSON_STRING || max->type == JSON_NUMBER)) {
|
||||
sf.has_tippecanoe_maxzoom = true;
|
||||
sf.tippecanoe_maxzoom = integer_zoom(sst->fname, max->string);
|
||||
}
|
||||
|
||||
json_object *tlayer = json_hash_get(o, "layer");
|
||||
if (tlayer != NULL && (tlayer->type == JSON_STRING || tlayer->type == JSON_NUMBER)) {
|
||||
sf.layername = tlayer->string;
|
||||
}
|
||||
}
|
||||
|
||||
json_free(o);
|
||||
json_end(jp);
|
||||
}
|
||||
|
||||
serialize_feature(sst, sf);
|
||||
}
|
||||
}
|
||||
|
||||
struct queue_run_arg {
|
||||
size_t start;
|
||||
size_t end;
|
||||
size_t segment;
|
||||
|
||||
queue_run_arg(size_t start1, size_t end1, size_t segment1)
|
||||
: start(start1), end(end1), segment(segment1) {
|
||||
}
|
||||
};
|
||||
|
||||
void *run_parse_feature(void *v) {
|
||||
struct queue_run_arg *qra = (struct queue_run_arg *) v;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void runQueue() {
|
||||
if (feature_queue.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<struct queue_run_arg> qra;
|
||||
|
||||
std::vector<pthread_t> pthreads;
|
||||
pthreads.resize(CPUS);
|
||||
|
||||
for (size_t i = 0; i < CPUS; i++) {
|
||||
*((*(feature_queue[0].sst))[i].layer_seq) = *((*(feature_queue[0].sst))[0].layer_seq) + feature_queue.size() * i / CPUS;
|
||||
|
||||
qra.push_back(queue_run_arg(
|
||||
feature_queue.size() * i / CPUS,
|
||||
feature_queue.size() * (i + 1) / CPUS,
|
||||
i));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < CPUS; i++) {
|
||||
if (pthread_create(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) {
|
||||
perror("pthread_create");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < CPUS; i++) {
|
||||
void *retval;
|
||||
|
||||
if (pthread_join(pthreads[i], &retval) != 0) {
|
||||
perror("pthread_join");
|
||||
}
|
||||
}
|
||||
|
||||
// Lack of atomicity is OK, since we are single-threaded again here
|
||||
long long was = *((*(feature_queue[0].sst))[CPUS - 1].layer_seq);
|
||||
*((*(feature_queue[0].sst))[0].layer_seq) = was;
|
||||
feature_queue.clear();
|
||||
}
|
||||
|
||||
void queueFeature(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<std::string> &keys, std::vector<struct serialization_state> *sst, int layer, std::string layername) {
|
||||
struct queued_feature qf;
|
||||
qf.pbf = pbf;
|
||||
qf.dim = dim;
|
||||
qf.e = e;
|
||||
qf.keys = &keys;
|
||||
qf.sst = sst;
|
||||
qf.layer = layer;
|
||||
qf.layername = layername;
|
||||
|
||||
feature_queue.push_back(qf);
|
||||
|
||||
if (feature_queue.size() > CPUS * 500) {
|
||||
runQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void outBareGeometry(drawvec const &dv, int type, struct serialization_state *sst, int layer, std::string layername) {
|
||||
serial_feature sf;
|
||||
|
||||
sf.layer = layer;
|
||||
sf.layername = layername;
|
||||
sf.segment = sst->segment;
|
||||
sf.has_id = false;
|
||||
sf.has_tippecanoe_minzoom = false;
|
||||
sf.has_tippecanoe_maxzoom = false;
|
||||
sf.feature_minzoom = false;
|
||||
sf.seq = (*sst->layer_seq);
|
||||
sf.geometry = dv;
|
||||
sf.t = type;
|
||||
|
||||
serialize_feature(sst, sf);
|
||||
}
|
||||
|
||||
void readFeatureCollection(protozero::pbf_reader &pbf, size_t dim, double e, std::vector<std::string> &keys, std::vector<struct serialization_state> *sst, int layer, std::string layername) {
|
||||
while (pbf.next()) {
|
||||
switch (pbf.tag()) {
|
||||
case 1: {
|
||||
protozero::pbf_reader feature_reader(pbf.get_message());
|
||||
queueFeature(feature_reader, dim, e, keys, sst, layer, layername);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
pbf.skip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse_geobuf(std::vector<struct serialization_state> *sst, const char *src, size_t len, int layer, std::string layername) {
|
||||
protozero::pbf_reader pbf(src, len);
|
||||
|
||||
size_t dim = 2;
|
||||
double e = 1e6;
|
||||
std::vector<std::string> keys;
|
||||
|
||||
while (pbf.next()) {
|
||||
switch (pbf.tag()) {
|
||||
case 1:
|
||||
keys.push_back(pbf.get_string());
|
||||
break;
|
||||
|
||||
case 2:
|
||||
dim = pbf.get_int64();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
e = pow(10, pbf.get_int64());
|
||||
break;
|
||||
|
||||
case 4: {
|
||||
protozero::pbf_reader feature_collection_reader(pbf.get_message());
|
||||
readFeatureCollection(feature_collection_reader, dim, e, keys, sst, layer, layername);
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: {
|
||||
protozero::pbf_reader feature_reader(pbf.get_message());
|
||||
queueFeature(feature_reader, dim, e, keys, sst, layer, layername);
|
||||
break;
|
||||
}
|
||||
|
||||
case 6: {
|
||||
protozero::pbf_reader geometry_reader(pbf.get_message());
|
||||
std::vector<drawvec_type> dv = readGeometry(geometry_reader, dim, e, keys);
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
// Always on thread 0
|
||||
outBareGeometry(dv[i].dv, dv[i].type, &(*sst)[0], layer, layername);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
pbf.skip();
|
||||
}
|
||||
}
|
||||
|
||||
runQueue();
|
||||
}
|
13
geobuf.hpp
13
geobuf.hpp
@ -1,13 +0,0 @@
|
||||
#ifndef GEOBUF_HPP
|
||||
#define GEOBUF_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "mbtiles.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
void parse_geobuf(std::vector<struct serialization_state> *sst, const char *s, size_t len, int layer, std::string layername);
|
||||
|
||||
#endif
|
139
geocsv.cpp
139
geocsv.cpp
@ -1,139 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include "geocsv.hpp"
|
||||
#include "mvt.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "main.hpp"
|
||||
#include "text.hpp"
|
||||
#include "csv.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "options.hpp"
|
||||
|
||||
void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fname, int layer, std::string layername) {
|
||||
FILE *f;
|
||||
|
||||
if (fname.size() == 0) {
|
||||
f = stdin;
|
||||
} else {
|
||||
f = fopen(fname.c_str(), "r");
|
||||
if (f == NULL) {
|
||||
perror(fname.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
std::string s;
|
||||
std::vector<std::string> header;
|
||||
ssize_t latcol = -1, loncol = -1;
|
||||
|
||||
if ((s = csv_getline(f)).size() > 0) {
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s: %s\n", fname.c_str(), err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
header = csv_split(s.c_str());
|
||||
|
||||
for (size_t i = 0; i < header.size(); i++) {
|
||||
header[i] = csv_dequote(header[i]);
|
||||
|
||||
std::string lower(header[i]);
|
||||
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
||||
|
||||
if (lower == "y" || lower == "lat" || (lower.find("latitude") != std::string::npos)) {
|
||||
latcol = i;
|
||||
}
|
||||
if (lower == "x" || lower == "lon" || lower == "lng" || lower == "long" || (lower.find("longitude") != std::string::npos)) {
|
||||
loncol = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (latcol < 0 || loncol < 0) {
|
||||
fprintf(stderr, "%s: Can't find \"lat\" and \"lon\" columns\n", fname.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
size_t seq = 0;
|
||||
while ((s = csv_getline(f)).size() > 0) {
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s: %s\n", fname.c_str(), err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
seq++;
|
||||
std::vector<std::string> line = csv_split(s.c_str());
|
||||
|
||||
if (line.size() != header.size()) {
|
||||
fprintf(stderr, "%s:%zu: Mismatched column count: %zu in line, %zu in header\n", fname.c_str(), seq + 1, line.size(), header.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (line[loncol].empty() || line[latcol].empty()) {
|
||||
static int warned = 0;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "%s:%zu: null geometry (additional not reported)\n", fname.c_str(), seq + 1);
|
||||
warned = 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
double lon = atof(line[loncol].c_str());
|
||||
double lat = atof(line[latcol].c_str());
|
||||
|
||||
long long x, y;
|
||||
projection->project(lon, lat, 32, &x, &y);
|
||||
drawvec dv;
|
||||
dv.push_back(draw(VT_MOVETO, x, y));
|
||||
|
||||
std::vector<std::string> full_keys;
|
||||
std::vector<serial_val> full_values;
|
||||
|
||||
for (size_t i = 0; i < line.size(); i++) {
|
||||
if (i != (size_t) latcol && i != (size_t) loncol) {
|
||||
line[i] = csv_dequote(line[i]);
|
||||
|
||||
serial_val sv;
|
||||
if (is_number(line[i])) {
|
||||
sv.type = mvt_double;
|
||||
} else if (line[i].size() == 0 && prevent[P_EMPTY_CSV_COLUMNS]) {
|
||||
sv.type = mvt_null;
|
||||
line[i] = "null";
|
||||
} else {
|
||||
sv.type = mvt_string;
|
||||
}
|
||||
sv.s = line[i];
|
||||
|
||||
full_keys.push_back(header[i]);
|
||||
full_values.push_back(sv);
|
||||
}
|
||||
}
|
||||
|
||||
serial_feature sf;
|
||||
|
||||
sf.layer = layer;
|
||||
sf.layername = layername;
|
||||
sf.segment = sst[0].segment;
|
||||
sf.has_id = false;
|
||||
sf.id = 0;
|
||||
sf.has_tippecanoe_minzoom = false;
|
||||
sf.has_tippecanoe_maxzoom = false;
|
||||
sf.feature_minzoom = false;
|
||||
sf.seq = *(sst[0].layer_seq);
|
||||
sf.geometry = dv;
|
||||
sf.t = 1; // POINT
|
||||
sf.full_keys = full_keys;
|
||||
sf.full_values = full_values;
|
||||
|
||||
serialize_feature(&sst[0], sf);
|
||||
}
|
||||
|
||||
if (fname.size() != 0) {
|
||||
if (fclose(f) != 0) {
|
||||
perror("fclose");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
13
geocsv.hpp
13
geocsv.hpp
@ -1,13 +0,0 @@
|
||||
#ifndef GEOCSV_HPP
|
||||
#define GEOCSV_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "mbtiles.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fname, int layer, std::string layername);
|
||||
|
||||
#endif
|
184
geojson-loop.cpp
184
geojson-loop.cpp
@ -1,184 +0,0 @@
|
||||
#ifdef MTRACE
|
||||
#include <mcheck.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include "geojson-loop.hpp"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
|
||||
// XXX duplicated
|
||||
#define GEOM_TYPES 6
|
||||
static const char *geometry_names[GEOM_TYPES] = {
|
||||
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
||||
};
|
||||
|
||||
// XXX duplicated
|
||||
static void json_context(json_object *j) {
|
||||
char *s = json_stringify(j);
|
||||
|
||||
if (strlen(s) >= 500) {
|
||||
sprintf(s + 497, "...");
|
||||
}
|
||||
|
||||
fprintf(stderr, "In JSON object %s\n", s);
|
||||
free(s); // stringify
|
||||
}
|
||||
|
||||
void parse_json(json_feature_action *jfa, json_pull *jp) {
|
||||
long long found_hashes = 0;
|
||||
long long found_features = 0;
|
||||
long long found_geometries = 0;
|
||||
|
||||
while (1) {
|
||||
json_object *j = json_read(jp);
|
||||
if (j == NULL) {
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "%s:%d: %s\n", jfa->fname.c_str(), jp->line, jp->error);
|
||||
if (jp->root != NULL) {
|
||||
json_context(jp->root);
|
||||
}
|
||||
}
|
||||
|
||||
json_free(jp->root);
|
||||
break;
|
||||
}
|
||||
|
||||
if (j->type == JSON_HASH) {
|
||||
found_hashes++;
|
||||
|
||||
if (found_hashes == 50 && found_features == 0 && found_geometries == 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: not finding any GeoJSON features or geometries in input yet after 50 objects.\n", jfa->fname.c_str(), jp->line);
|
||||
}
|
||||
}
|
||||
|
||||
json_object *type = json_hash_get(j, "type");
|
||||
if (type == NULL || type->type != JSON_STRING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (found_features == 0) {
|
||||
int i;
|
||||
int is_geometry = 0;
|
||||
for (i = 0; i < GEOM_TYPES; i++) {
|
||||
if (strcmp(type->string, geometry_names[i]) == 0) {
|
||||
is_geometry = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_geometry) {
|
||||
if (j->parent != NULL) {
|
||||
if (j->parent->type == JSON_ARRAY && j->parent->parent != NULL) {
|
||||
if (j->parent->parent->type == JSON_HASH) {
|
||||
json_object *geometries = json_hash_get(j->parent->parent, "geometries");
|
||||
if (geometries != NULL) {
|
||||
// Parent of Parent must be a GeometryCollection
|
||||
is_geometry = 0;
|
||||
}
|
||||
}
|
||||
} else if (j->parent->type == JSON_HASH) {
|
||||
json_object *geometry = json_hash_get(j->parent, "geometry");
|
||||
if (geometry != NULL) {
|
||||
// Parent must be a Feature
|
||||
is_geometry = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_geometry) {
|
||||
json_object *jo = j;
|
||||
while (jo != NULL) {
|
||||
if (jo->parent != NULL && jo->parent->type == JSON_HASH) {
|
||||
if (json_hash_get(jo->parent, "properties") == jo) {
|
||||
// Ancestor is the value corresponding to a properties key
|
||||
is_geometry = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
jo = jo->parent;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_geometry) {
|
||||
if (found_features != 0 && found_geometries == 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: found a mixture of features and bare geometries\n", jfa->fname.c_str(), jp->line);
|
||||
}
|
||||
found_geometries++;
|
||||
|
||||
jfa->add_feature(j, false, NULL, NULL, NULL, j);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(type->string, "Feature") != 0) {
|
||||
if (strcmp(type->string, "FeatureCollection") == 0) {
|
||||
jfa->check_crs(j);
|
||||
json_free(j);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (found_features == 0 && found_geometries != 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: found a mixture of features and bare geometries\n", jfa->fname.c_str(), jp->line);
|
||||
}
|
||||
found_features++;
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "%s:%d: feature with no geometry\n", jfa->fname.c_str(), jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
if (properties == NULL || (properties->type != JSON_HASH && properties->type != JSON_NULL)) {
|
||||
fprintf(stderr, "%s:%d: feature without properties hash\n", jfa->fname.c_str(), jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_feature = true;
|
||||
{
|
||||
json_object *jo = j;
|
||||
while (jo != NULL) {
|
||||
if (jo->parent != NULL && jo->parent->type == JSON_HASH) {
|
||||
if (json_hash_get(jo->parent, "properties") == jo) {
|
||||
// Ancestor is the value corresponding to a properties key
|
||||
is_feature = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
jo = jo->parent;
|
||||
}
|
||||
}
|
||||
if (!is_feature) {
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *tippecanoe = json_hash_get(j, "tippecanoe");
|
||||
json_object *id = json_hash_get(j, "id");
|
||||
|
||||
json_object *geometries = json_hash_get(geometry, "geometries");
|
||||
if (geometries != NULL && geometries->type == JSON_ARRAY) {
|
||||
jfa->add_feature(geometries, true, properties, id, tippecanoe, j);
|
||||
} else {
|
||||
jfa->add_feature(geometry, false, properties, id, tippecanoe, j);
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
|
||||
/* XXX check for any non-features in the outer object */
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#include <string>
|
||||
#include "jsonpull/jsonpull.h"
|
||||
|
||||
struct json_feature_action {
|
||||
std::string fname;
|
||||
|
||||
virtual int add_feature(json_object *geometry, bool geometrycollection, json_object *properties, json_object *id, json_object *tippecanoe, json_object *feature) = 0;
|
||||
virtual void check_crs(json_object *j) = 0;
|
||||
};
|
||||
|
||||
void parse_json(json_feature_action *action, json_pull *jp);
|
580
geojson.cpp
580
geojson.cpp
@ -20,11 +20,14 @@
|
||||
#include <sys/resource.h>
|
||||
#include <pthread.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "jsonpull/jsonpull.h"
|
||||
}
|
||||
|
||||
#include "pool.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "memfile.hpp"
|
||||
@ -35,16 +38,141 @@
|
||||
#include "options.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "text.hpp"
|
||||
#include "read_json.hpp"
|
||||
#include "mvt.hpp"
|
||||
#include "geojson-loop.hpp"
|
||||
|
||||
int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string layername) {
|
||||
#define GEOM_POINT 0 /* array of positions */
|
||||
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
||||
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
||||
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
||||
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
||||
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
||||
#define GEOM_TYPES 6
|
||||
|
||||
static const char *geometry_names[GEOM_TYPES] = {
|
||||
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
||||
};
|
||||
|
||||
static int geometry_within[GEOM_TYPES] = {
|
||||
-1, /* point */
|
||||
GEOM_POINT, /* multipoint */
|
||||
GEOM_POINT, /* linestring */
|
||||
GEOM_LINESTRING, /* multilinestring */
|
||||
GEOM_LINESTRING, /* polygon */
|
||||
GEOM_POLYGON, /* multipolygon */
|
||||
};
|
||||
|
||||
static int mb_geometry[GEOM_TYPES] = {
|
||||
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
|
||||
};
|
||||
|
||||
void json_context(json_object *j) {
|
||||
char *s = json_stringify(j);
|
||||
|
||||
if (strlen(s) >= 500) {
|
||||
sprintf(s + 497, "...");
|
||||
}
|
||||
|
||||
fprintf(stderr, "In JSON object %s\n", s);
|
||||
free(s); // stringify
|
||||
}
|
||||
|
||||
long long parse_geometry(int t, json_object *j, long long *bbox, drawvec &out, int op, const char *fname, int line, int *initialized, unsigned *initial_x, unsigned *initial_y, json_object *feature) {
|
||||
long long g = 0;
|
||||
|
||||
if (j == NULL || j->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "%s:%d: expected array for type %d\n", fname, line, t);
|
||||
json_context(feature);
|
||||
return g;
|
||||
}
|
||||
|
||||
int within = geometry_within[t];
|
||||
if (within >= 0) {
|
||||
size_t i;
|
||||
for (i = 0; i < j->length; i++) {
|
||||
if (within == GEOM_POINT) {
|
||||
if (i == 0 || mb_geometry[t] == GEOM_MULTIPOINT) {
|
||||
op = VT_MOVETO;
|
||||
} else {
|
||||
op = VT_LINETO;
|
||||
}
|
||||
}
|
||||
|
||||
g += parse_geometry(within, j->array[i], bbox, out, op, fname, line, initialized, initial_x, initial_y, feature);
|
||||
}
|
||||
} else {
|
||||
if (j->length >= 2 && j->array[0]->type == JSON_NUMBER && j->array[1]->type == JSON_NUMBER) {
|
||||
long long x, y;
|
||||
double lon = j->array[0]->number;
|
||||
double lat = j->array[1]->number;
|
||||
projection->project(lon, lat, 32, &x, &y);
|
||||
|
||||
if (j->length > 2) {
|
||||
static int warned = 0;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "%s:%d: ignoring dimensions beyond two\n", fname, line);
|
||||
json_context(j);
|
||||
json_context(feature);
|
||||
warned = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (x < bbox[0]) {
|
||||
bbox[0] = x;
|
||||
}
|
||||
if (y < bbox[1]) {
|
||||
bbox[1] = y;
|
||||
}
|
||||
if (x > bbox[2]) {
|
||||
bbox[2] = x;
|
||||
}
|
||||
if (y > bbox[3]) {
|
||||
bbox[3] = y;
|
||||
}
|
||||
|
||||
if (!*initialized) {
|
||||
if (x < 0 || x >= (1LL << 32) || y < 0 || y >= (1LL < 32)) {
|
||||
*initial_x = 1LL << 31;
|
||||
*initial_y = 1LL << 31;
|
||||
} else {
|
||||
*initial_x = (x >> geometry_scale) << geometry_scale;
|
||||
*initial_y = (y >> geometry_scale) << geometry_scale;
|
||||
}
|
||||
|
||||
*initialized = 1;
|
||||
}
|
||||
|
||||
draw d(op, (x >> geometry_scale), (y >> geometry_scale));
|
||||
out.push_back(d);
|
||||
g++;
|
||||
} else {
|
||||
fprintf(stderr, "%s:%d: malformed point\n", fname, line);
|
||||
json_context(j);
|
||||
json_context(feature);
|
||||
}
|
||||
}
|
||||
|
||||
if (t == GEOM_POLYGON) {
|
||||
// Note that this is not using the correct meaning of closepath.
|
||||
//
|
||||
// We are using it here to close an entire Polygon, to distinguish
|
||||
// the Polygons within a MultiPolygon from each other.
|
||||
//
|
||||
// This will be undone in fix_polygon(), which needs to know which
|
||||
// rings come from which Polygons so that it can make the winding order
|
||||
// of the outer ring be the opposite of the order of the inner rings.
|
||||
|
||||
out.push_back(draw(VT_CLOSEPATH, 0, 0));
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int serialize_geometry(json_object *geometry, json_object *properties, json_object *id, const char *reading, int line, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, const char *fname, int basezoom, int layer, double droprate, long long *file_bbox, json_object *tippecanoe, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, int maxzoom, json_object *feature, std::map<std::string, layermap_entry> *layermap, std::string const &layername, bool uses_gamma) {
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
static int warned = 0;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "%s:%d: null geometry (additional not reported)\n", sst->fname, sst->line);
|
||||
fprintf(stderr, "%s:%d: null geometry (additional not reported)\n", reading, line);
|
||||
json_context(feature);
|
||||
warned = 1;
|
||||
}
|
||||
@ -53,14 +181,14 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
}
|
||||
|
||||
if (geometry_type->type != JSON_STRING) {
|
||||
fprintf(stderr, "%s:%d: geometry type is not a string\n", sst->fname, sst->line);
|
||||
fprintf(stderr, "%s:%d: geometry type is not a string\n", reading, line);
|
||||
json_context(feature);
|
||||
return 0;
|
||||
}
|
||||
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "%s:%d: feature without coordinates array\n", sst->fname, sst->line);
|
||||
fprintf(stderr, "%s:%d: feature without coordinates array\n", reading, line);
|
||||
json_context(feature);
|
||||
return 0;
|
||||
}
|
||||
@ -72,7 +200,7 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
}
|
||||
}
|
||||
if (t >= GEOM_TYPES) {
|
||||
fprintf(stderr, "%s:%d: Can't handle geometry type %s\n", sst->fname, sst->line, geometry_type->string);
|
||||
fprintf(stderr, "%s:%d: Can't handle geometry type %s\n", reading, line, geometry_type->string);
|
||||
json_context(feature);
|
||||
return 0;
|
||||
}
|
||||
@ -83,13 +211,19 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
|
||||
if (tippecanoe != NULL) {
|
||||
json_object *min = json_hash_get(tippecanoe, "minzoom");
|
||||
if (min != NULL && (min->type == JSON_STRING || min->type == JSON_NUMBER)) {
|
||||
tippecanoe_minzoom = integer_zoom(sst->fname, min->string);
|
||||
if (min != NULL && min->type == JSON_NUMBER) {
|
||||
tippecanoe_minzoom = min->number;
|
||||
}
|
||||
if (min != NULL && min->type == JSON_STRING) {
|
||||
tippecanoe_minzoom = atoi(min->string);
|
||||
}
|
||||
|
||||
json_object *max = json_hash_get(tippecanoe, "maxzoom");
|
||||
if (max != NULL && (max->type == JSON_STRING || max->type == JSON_NUMBER)) {
|
||||
tippecanoe_maxzoom = integer_zoom(sst->fname, max->string);
|
||||
if (max != NULL && max->type == JSON_NUMBER) {
|
||||
tippecanoe_maxzoom = max->number;
|
||||
}
|
||||
if (max != NULL && max->type == JSON_STRING) {
|
||||
tippecanoe_maxzoom = atoi(max->string);
|
||||
}
|
||||
|
||||
json_object *ln = json_hash_get(tippecanoe, "layer");
|
||||
@ -107,114 +241,162 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
id_value = strtoull(id->string, &err, 10);
|
||||
|
||||
if (err != NULL && *err != '\0') {
|
||||
static bool warned_frac = false;
|
||||
|
||||
if (!warned_frac) {
|
||||
fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", id->string);
|
||||
warned_frac = true;
|
||||
}
|
||||
} else if (std::to_string(id_value) != id->string) {
|
||||
static bool warned = false;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: Can't represent too-large feature ID %s\n", id->string);
|
||||
warned = true;
|
||||
}
|
||||
fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", id->string);
|
||||
} else {
|
||||
has_id = true;
|
||||
}
|
||||
} else {
|
||||
static bool warned_neg = false;
|
||||
|
||||
if (!warned_neg) {
|
||||
fprintf(stderr, "Warning: Can't represent negative feature ID %s\n", id->string);
|
||||
warned_neg = true;
|
||||
}
|
||||
fprintf(stderr, "Warning: Can't represent negative feature ID %s\n", id->string);
|
||||
}
|
||||
} else {
|
||||
bool converted = false;
|
||||
|
||||
if (additional[A_CONVERT_NUMERIC_IDS] && id->type == JSON_STRING) {
|
||||
char *err = NULL;
|
||||
id_value = strtoull(id->string, &err, 10);
|
||||
|
||||
if (err != NULL && *err != '\0') {
|
||||
static bool warned_frac = false;
|
||||
|
||||
if (!warned_frac) {
|
||||
fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", id->string);
|
||||
warned_frac = true;
|
||||
}
|
||||
} else if (std::to_string(id_value) != id->string) {
|
||||
static bool warned = false;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: Can't represent too-large feature ID %s\n", id->string);
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
has_id = true;
|
||||
converted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!converted) {
|
||||
static bool warned_nan = false;
|
||||
|
||||
if (!warned_nan) {
|
||||
char *s = json_stringify(id);
|
||||
fprintf(stderr, "Warning: Can't represent non-numeric feature ID %s\n", s);
|
||||
free(s); // stringify
|
||||
warned_nan = true;
|
||||
}
|
||||
}
|
||||
char *s = json_stringify(id);
|
||||
fprintf(stderr, "Warning: Can't represent non-numeric feature ID %s\n", s);
|
||||
free(s); // stringify
|
||||
}
|
||||
}
|
||||
|
||||
long long bbox[] = {LLONG_MAX, LLONG_MAX, LLONG_MIN, LLONG_MIN};
|
||||
|
||||
size_t nprop = 0;
|
||||
if (properties != NULL && properties->type == JSON_HASH) {
|
||||
nprop = properties->length;
|
||||
}
|
||||
|
||||
std::vector<char *> metakey;
|
||||
metakey.resize(nprop);
|
||||
|
||||
char *metakey[nprop];
|
||||
std::vector<std::string> metaval;
|
||||
metaval.resize(nprop);
|
||||
|
||||
std::vector<int> metatype;
|
||||
metatype.resize(nprop);
|
||||
|
||||
int metatype[nprop];
|
||||
size_t m = 0;
|
||||
|
||||
for (size_t i = 0; i < nprop; i++) {
|
||||
if (properties->keys[i]->type == JSON_STRING) {
|
||||
std::string s(properties->keys[i]->string);
|
||||
|
||||
int type = -1;
|
||||
std::string val;
|
||||
stringify_value(properties->values[i], type, val, sst->fname, sst->line, feature);
|
||||
if (exclude_all) {
|
||||
if (include->count(s) == 0) {
|
||||
continue;
|
||||
}
|
||||
} else if (exclude->count(s) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type >= 0) {
|
||||
metakey[m] = properties->keys[i]->string;
|
||||
metatype[m] = type;
|
||||
metaval[m] = val;
|
||||
type_and_string tas;
|
||||
tas.string = s;
|
||||
tas.type = -1;
|
||||
|
||||
metakey[m] = properties->keys[i]->string;
|
||||
|
||||
if (properties->values[i] != NULL && properties->values[i]->type == JSON_STRING) {
|
||||
tas.type = metatype[m] = VT_STRING;
|
||||
metaval[m] = std::string(properties->values[i]->string);
|
||||
std::string err = check_utf8(metaval[m]);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s:%d: %s\n", reading, line, err.c_str());
|
||||
json_context(feature);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
m++;
|
||||
} else if (properties->values[i] != NULL && properties->values[i]->type == JSON_NUMBER) {
|
||||
tas.type = metatype[m] = VT_NUMBER;
|
||||
metaval[m] = std::string(properties->values[i]->string);
|
||||
m++;
|
||||
} else if (properties->values[i] != NULL && (properties->values[i]->type == JSON_TRUE || properties->values[i]->type == JSON_FALSE)) {
|
||||
tas.type = metatype[m] = VT_BOOLEAN;
|
||||
metaval[m] = std::string(properties->values[i]->type == JSON_TRUE ? "true" : "false");
|
||||
m++;
|
||||
} else if (properties->values[i] != NULL && (properties->values[i]->type == JSON_NULL)) {
|
||||
;
|
||||
} else {
|
||||
metakey[m] = properties->keys[i]->string;
|
||||
metatype[m] = mvt_null;
|
||||
metaval[m] = "null";
|
||||
tas.type = metatype[m] = VT_STRING;
|
||||
const char *v = json_stringify(properties->values[i]);
|
||||
metaval[m] = std::string(v);
|
||||
free((void *) v); // stringify
|
||||
m++;
|
||||
}
|
||||
|
||||
if (tas.type >= 0) {
|
||||
auto fk = layermap->find(layername);
|
||||
fk->second.file_keys.insert(tas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, sst->fname, sst->line, feature);
|
||||
long long g = parse_geometry(t, coordinates, bbox, dv, VT_MOVETO, fname, line, initialized, initial_x, initial_y, feature);
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv);
|
||||
}
|
||||
|
||||
bool inline_meta = true;
|
||||
// Don't inline metadata for features that will span several tiles at maxzoom
|
||||
if (g > 0 && (bbox[2] < bbox[0] || bbox[3] < bbox[1])) {
|
||||
fprintf(stderr, "Internal error: impossible feature bounding box %llx,%llx,%llx,%llx\n", bbox[0], bbox[1], bbox[2], bbox[3]);
|
||||
}
|
||||
if (bbox[2] - bbox[0] > (2LL << (32 - maxzoom)) || bbox[3] - bbox[1] > (2LL << (32 - maxzoom))) {
|
||||
inline_meta = false;
|
||||
|
||||
if (prevent[P_CLIPPING]) {
|
||||
static volatile long long warned = 0;
|
||||
long long extent = ((bbox[2] - bbox[0]) / ((1LL << (32 - maxzoom)) + 1)) * ((bbox[3] - bbox[1]) / ((1LL << (32 - maxzoom)) + 1));
|
||||
if (extent > warned) {
|
||||
fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", fname, line, extent);
|
||||
warned = extent;
|
||||
|
||||
if (extent > 10000) {
|
||||
fprintf(stderr, "Exiting because this can't be right.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double extent = 0;
|
||||
if (additional[A_DROP_SMALLEST_AS_NEEDED]) {
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
if (dv[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
for (j = i + 1; j < dv.size(); j++) {
|
||||
if (dv[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
extent += get_area(dv, i, j);
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
} else if (mb_geometry[t] == VT_LINE) {
|
||||
for (size_t i = 1; i < dv.size(); i++) {
|
||||
if (dv[i].op == VT_LINETO) {
|
||||
double xd = dv[i].x - dv[i - 1].x;
|
||||
double yd = dv[i].y - dv[i - 1].y;
|
||||
extent += sqrt(xd * xd + yd * yd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tippecanoe_layername.size() != 0) {
|
||||
if (layermap->count(tippecanoe_layername) == 0) {
|
||||
layermap->insert(std::pair<std::string, layermap_entry>(tippecanoe_layername, layermap_entry(layermap->size())));
|
||||
}
|
||||
|
||||
auto ai = layermap->find(tippecanoe_layername);
|
||||
if (ai != layermap->end()) {
|
||||
layer = ai->second.id;
|
||||
} else {
|
||||
fprintf(stderr, "Internal error: can't find layer name %s\n", tippecanoe_layername.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
long long geomstart = *geompos;
|
||||
long long bbox_index;
|
||||
|
||||
serial_feature sf;
|
||||
sf.layer = layer;
|
||||
sf.segment = sst->segment;
|
||||
sf.segment = segment;
|
||||
sf.t = mb_geometry[t];
|
||||
sf.has_id = has_id;
|
||||
sf.id = id_value;
|
||||
@ -223,26 +405,74 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
sf.has_tippecanoe_maxzoom = (tippecanoe_maxzoom != -1);
|
||||
sf.tippecanoe_maxzoom = tippecanoe_maxzoom;
|
||||
sf.geometry = dv;
|
||||
sf.m = m;
|
||||
sf.feature_minzoom = 0; // Will be filled in during index merging
|
||||
sf.seq = *(sst->layer_seq);
|
||||
sf.extent = (long long) extent;
|
||||
|
||||
if (tippecanoe_layername.size() != 0) {
|
||||
sf.layername = tippecanoe_layername;
|
||||
if (prevent[P_INPUT_ORDER]) {
|
||||
sf.seq = *layer_seq;
|
||||
} else {
|
||||
sf.layername = layername;
|
||||
sf.seq = 0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m; i++) {
|
||||
sf.full_keys.push_back(metakey[i]);
|
||||
// Calculate the center even if off the edge of the plane,
|
||||
// and then mask to bring it back into the addressable area
|
||||
long long midx = (bbox[0] / 2 + bbox[2] / 2) & ((1LL << 32) - 1);
|
||||
long long midy = (bbox[1] / 2 + bbox[3] / 2) & ((1LL << 32) - 1);
|
||||
bbox_index = encode(midx, midy);
|
||||
|
||||
serial_val sv;
|
||||
sv.type = metatype[i];
|
||||
sv.s = metaval[i];
|
||||
|
||||
sf.full_values.push_back(sv);
|
||||
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_INCREASE_GAMMA_AS_NEEDED] || additional[A_MERGE_POLYGONS_AS_NEEDED] || uses_gamma) {
|
||||
sf.index = bbox_index;
|
||||
}
|
||||
|
||||
return serialize_feature(sst, sf);
|
||||
if (inline_meta) {
|
||||
sf.metapos = -1;
|
||||
for (size_t i = 0; i < m; i++) {
|
||||
sf.keys.push_back(addpool(poolfile, treefile, metakey[i], VT_STRING));
|
||||
sf.values.push_back(addpool(poolfile, treefile, metaval[i].c_str(), metatype[i]));
|
||||
}
|
||||
} else {
|
||||
sf.metapos = *metapos;
|
||||
for (size_t i = 0; i < m; i++) {
|
||||
serialize_long_long(metafile, addpool(poolfile, treefile, metakey[i], VT_STRING), metapos, fname);
|
||||
serialize_long_long(metafile, addpool(poolfile, treefile, metaval[i].c_str(), metatype[i]), metapos, fname);
|
||||
}
|
||||
}
|
||||
|
||||
serialize_feature(geomfile, &sf, geompos, fname, *initial_x >> geometry_scale, *initial_y >> geometry_scale, false);
|
||||
|
||||
struct index index;
|
||||
index.start = geomstart;
|
||||
index.end = *geompos;
|
||||
index.segment = segment;
|
||||
index.seq = *layer_seq;
|
||||
index.t = sf.t;
|
||||
index.index = bbox_index;
|
||||
|
||||
fwrite_check(&index, sizeof(struct index), 1, indexfile, fname);
|
||||
*indexpos += sizeof(struct index);
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
if (bbox[i] < file_bbox[i]) {
|
||||
file_bbox[i] = bbox[i];
|
||||
}
|
||||
}
|
||||
for (size_t i = 2; i < 4; i++) {
|
||||
if (bbox[i] > file_bbox[i]) {
|
||||
file_bbox[i] = bbox[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (*progress_seq % 10000 == 0) {
|
||||
checkdisk(readers, CPUS);
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "Read %.2f million features\r", *progress_seq / 1000000.0);
|
||||
}
|
||||
}
|
||||
(*progress_seq)++;
|
||||
(*layer_seq)++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void check_crs(json_object *j, const char *reading) {
|
||||
@ -251,55 +481,141 @@ void check_crs(json_object *j, const char *reading) {
|
||||
json_object *properties = json_hash_get(crs, "properties");
|
||||
if (properties != NULL) {
|
||||
json_object *name = json_hash_get(properties, "name");
|
||||
if (name != NULL && name->type == JSON_STRING) {
|
||||
if (name->type == JSON_STRING) {
|
||||
if (strcmp(name->string, projection->alias) != 0) {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "%s: Warning: GeoJSON specified projection \"%s\", not the expected \"%s\".\n", reading, name->string, projection->alias);
|
||||
fprintf(stderr, "%s: If \"%s\" is not the expected projection, use -s to specify the right one.\n", reading, projection->alias);
|
||||
}
|
||||
fprintf(stderr, "%s: Warning: GeoJSON specified projection \"%s\", not \"%s\".\n", reading, name->string, projection->alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct json_serialize_action : json_feature_action {
|
||||
serialization_state *sst;
|
||||
int layer;
|
||||
std::string layername;
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername, bool uses_gamma) {
|
||||
long long found_hashes = 0;
|
||||
long long found_features = 0;
|
||||
long long found_geometries = 0;
|
||||
|
||||
int add_feature(json_object *geometry, bool geometrycollection, json_object *properties, json_object *id, json_object *tippecanoe, json_object *feature) {
|
||||
sst->line = geometry->parser->line;
|
||||
if (geometrycollection) {
|
||||
int ret = 1;
|
||||
for (size_t g = 0; g < geometry->length; g++) {
|
||||
ret &= serialize_geojson_feature(sst, geometry->array[g], properties, id, layer, tippecanoe, feature, layername);
|
||||
while (1) {
|
||||
json_object *j = json_read(jp);
|
||||
if (j == NULL) {
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "%s:%d: %s\n", reading, jp->line, jp->error);
|
||||
if (jp->root != NULL) {
|
||||
json_context(jp->root);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return serialize_geojson_feature(sst, geometry, properties, id, layer, tippecanoe, feature, layername);
|
||||
|
||||
json_free(jp->root);
|
||||
break;
|
||||
}
|
||||
|
||||
if (j->type == JSON_HASH) {
|
||||
found_hashes++;
|
||||
|
||||
if (found_hashes == 50 && found_features == 0 && found_geometries == 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: not finding any GeoJSON features or geometries in input yet after 50 objects.\n", reading, jp->line);
|
||||
}
|
||||
}
|
||||
|
||||
json_object *type = json_hash_get(j, "type");
|
||||
if (type == NULL || type->type != JSON_STRING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (found_features == 0) {
|
||||
int i;
|
||||
int is_geometry = 0;
|
||||
for (i = 0; i < GEOM_TYPES; i++) {
|
||||
if (strcmp(type->string, geometry_names[i]) == 0) {
|
||||
is_geometry = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_geometry) {
|
||||
if (j->parent != NULL) {
|
||||
if (j->parent->type == JSON_ARRAY) {
|
||||
if (j->parent->parent->type == JSON_HASH) {
|
||||
json_object *geometries = json_hash_get(j->parent->parent, "geometries");
|
||||
if (geometries != NULL) {
|
||||
// Parent of Parent must be a GeometryCollection
|
||||
is_geometry = 0;
|
||||
}
|
||||
}
|
||||
} else if (j->parent->type == JSON_HASH) {
|
||||
json_object *geometry = json_hash_get(j->parent, "geometry");
|
||||
if (geometry != NULL) {
|
||||
// Parent must be a Feature
|
||||
is_geometry = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_geometry) {
|
||||
if (found_features != 0 && found_geometries == 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: found a mixture of features and bare geometries\n", reading, jp->line);
|
||||
}
|
||||
found_geometries++;
|
||||
|
||||
serialize_geometry(j, NULL, NULL, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, NULL, segment, initialized, initial_x, initial_y, readers, maxzoom, j, layermap, layername, uses_gamma);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(type->string, "Feature") != 0) {
|
||||
if (strcmp(type->string, "FeatureCollection") == 0) {
|
||||
check_crs(j, reading);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (found_features == 0 && found_geometries != 0) {
|
||||
fprintf(stderr, "%s:%d: Warning: found a mixture of features and bare geometries\n", reading, jp->line);
|
||||
}
|
||||
found_features++;
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "%s:%d: feature with no geometry\n", reading, jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
if (properties == NULL || (properties->type != JSON_HASH && properties->type != JSON_NULL)) {
|
||||
fprintf(stderr, "%s:%d: feature without properties hash\n", reading, jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *tippecanoe = json_hash_get(j, "tippecanoe");
|
||||
json_object *id = json_hash_get(j, "id");
|
||||
|
||||
json_object *geometries = json_hash_get(geometry, "geometries");
|
||||
if (geometries != NULL) {
|
||||
size_t g;
|
||||
for (g = 0; g < geometries->length; g++) {
|
||||
serialize_geometry(geometries->array[g], properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, maxzoom, j, layermap, layername, uses_gamma);
|
||||
}
|
||||
} else {
|
||||
serialize_geometry(geometry, properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, maxzoom, j, layermap, layername, uses_gamma);
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
|
||||
/* XXX check for any non-features in the outer object */
|
||||
}
|
||||
|
||||
void check_crs(json_object *j) {
|
||||
::check_crs(j, fname.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std::string layername) {
|
||||
json_serialize_action jsa;
|
||||
jsa.fname = sst->fname;
|
||||
jsa.sst = sst;
|
||||
jsa.layer = layer;
|
||||
jsa.layername = layername;
|
||||
|
||||
parse_json(&jsa, jp);
|
||||
}
|
||||
|
||||
void *run_parse_json(void *v) {
|
||||
struct parse_json_args *pja = (struct parse_json_args *) v;
|
||||
|
||||
parse_json(pja->sst, pja->jp, pja->layer, *pja->layername);
|
||||
parse_json(pja->jp, pja->reading, pja->layer_seq, pja->progress_seq, pja->metapos, pja->geompos, pja->indexpos, pja->exclude, pja->include, pja->exclude_all, pja->metafile, pja->geomfile, pja->indexfile, pja->poolfile, pja->treefile, pja->fname, pja->basezoom, pja->layer, pja->droprate, pja->file_bbox, pja->segment, pja->initialized, pja->initial_x, pja->initial_y, pja->readers, pja->maxzoom, pja->layermap, *pja->layername, pja->uses_gamma);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
47
geojson.hpp
47
geojson.hpp
@ -1,30 +1,37 @@
|
||||
#ifndef GEOJSON_HPP
|
||||
#define GEOJSON_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "mbtiles.hpp"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "serial.hpp"
|
||||
|
||||
struct parse_json_args {
|
||||
json_pull *jp;
|
||||
const char *reading;
|
||||
volatile long long *layer_seq;
|
||||
volatile long long *progress_seq;
|
||||
long long *metapos;
|
||||
long long *geompos;
|
||||
long long *indexpos;
|
||||
std::set<std::string> *exclude;
|
||||
std::set<std::string> *include;
|
||||
int exclude_all;
|
||||
FILE *metafile;
|
||||
FILE *geomfile;
|
||||
FILE *indexfile;
|
||||
struct memfile *poolfile;
|
||||
struct memfile *treefile;
|
||||
char *fname;
|
||||
int basezoom;
|
||||
int layer;
|
||||
double droprate;
|
||||
long long *file_bbox;
|
||||
int segment;
|
||||
int *initialized;
|
||||
unsigned *initial_x;
|
||||
unsigned *initial_y;
|
||||
struct reader *readers;
|
||||
int maxzoom;
|
||||
std::map<std::string, layermap_entry> *layermap;
|
||||
std::string *layername;
|
||||
|
||||
struct serialization_state *sst;
|
||||
|
||||
parse_json_args(json_pull *jp1, int layer1, std::string *layername1, struct serialization_state *sst1)
|
||||
: jp(jp1), layer(layer1), layername(layername1), sst(sst1) {
|
||||
}
|
||||
bool uses_gamma;
|
||||
};
|
||||
|
||||
struct json_pull *json_begin_map(char *map, long long len);
|
||||
void json_end_map(struct json_pull *jp);
|
||||
|
||||
void parse_json(struct serialization_state *sst, json_pull *jp, int layer, std::string layername);
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername, bool uses_gamma);
|
||||
void *run_parse_json(void *v);
|
||||
|
||||
#endif
|
||||
|
468
geometry.cpp
468
geometry.cpp
@ -3,28 +3,23 @@
|
||||
#include <string>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <cmath>
|
||||
#include <limits.h>
|
||||
#include <sqlite3.h>
|
||||
#include <mapbox/geometry/point.hpp>
|
||||
#include <mapbox/geometry/multi_polygon.hpp>
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <mapbox/geometry/wagyu/wagyu.hpp>
|
||||
#include <mapbox/geometry/wagyu/quick_clip.hpp>
|
||||
#include <mapbox/geometry/snap_rounding.hpp>
|
||||
#include "geometry.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "main.hpp"
|
||||
#include "options.hpp"
|
||||
|
||||
static int pnpoly(drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
||||
static int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymin, double xmax, double ymax);
|
||||
|
||||
drawvec decode_geometry(FILE *meta, std::atomic<long long> *geompos, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y) {
|
||||
drawvec decode_geometry(FILE *meta, long long *geompos, int z, unsigned tx, unsigned ty, int detail, long long *bbox, unsigned initial_x, unsigned initial_y) {
|
||||
drawvec out;
|
||||
|
||||
bbox[0] = LLONG_MAX;
|
||||
@ -169,27 +164,6 @@ double get_area(drawvec &geom, size_t i, size_t j) {
|
||||
return area;
|
||||
}
|
||||
|
||||
double get_mp_area(drawvec &geom) {
|
||||
double ret = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ret += get_area(geom, i, j);
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void decode_clipped(mapbox::geometry::multi_polygon<long long> &t, drawvec &out) {
|
||||
out.clear();
|
||||
|
||||
@ -197,8 +171,11 @@ static void decode_clipped(mapbox::geometry::multi_polygon<long long> &t, drawve
|
||||
for (size_t j = 0; j < t[i].size(); j++) {
|
||||
drawvec ring;
|
||||
|
||||
for (size_t k = 0; k < t[i][j].size(); k++) {
|
||||
ring.push_back(draw((k == 0) ? VT_MOVETO : VT_LINETO, t[i][j][k].x, t[i][j][k].y));
|
||||
// The coordinate system is swapped, so wagyu ring winding is
|
||||
// backwards from internal ring winding.
|
||||
ssize_t start = t[i][j].size() - 1;
|
||||
for (ssize_t k = start; k >= 0; --k) {
|
||||
ring.push_back(draw((k == start) ? VT_MOVETO : VT_LINETO, t[i][j][k].x, t[i][j][k].y));
|
||||
}
|
||||
|
||||
if (ring.size() > 0 && ring[ring.size() - 1] != ring[0]) {
|
||||
@ -220,10 +197,85 @@ static void decode_clipped(mapbox::geometry::multi_polygon<long long> &t, drawve
|
||||
}
|
||||
}
|
||||
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) {
|
||||
static void dump(drawvec &geom) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
printf("{ ClipperLib::Path path; ");
|
||||
|
||||
drawvec tmp;
|
||||
for (size_t k = i; k < j; k++) {
|
||||
printf("path.push_back(IntPoint(%lld,%lld)); ", geom[k].x, geom[k].y);
|
||||
}
|
||||
|
||||
printf("clipper.AddPath(path, ClipperLib::ptSubject, true); }\n");
|
||||
|
||||
i = j - 1;
|
||||
} else {
|
||||
fprintf(stderr, "Unexpected operation in polygon %d\n", (int) geom[i].op);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void divide_and_merge(std::vector<std::vector<mapbox::geometry::linear_ring<long long>>> &polys, size_t start, size_t end) {
|
||||
if (end <= start) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t mid = (start + end) / 2;
|
||||
|
||||
if (mid > start + 1) {
|
||||
divide_and_merge(polys, start, mid);
|
||||
}
|
||||
if (end > mid + 1) {
|
||||
divide_and_merge(polys, mid, end);
|
||||
}
|
||||
|
||||
mapbox::geometry::wagyu::wagyu<long long> wagyu;
|
||||
|
||||
geom = remove_noop(geom, VT_POLYGON, 0);
|
||||
// printf("going to merge rings %zu to %zu\n", start, end);
|
||||
|
||||
size_t in = 0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
for (size_t j = 0; j < polys[i].size(); j++) {
|
||||
wagyu.add_ring(polys[i][j]);
|
||||
in++;
|
||||
}
|
||||
|
||||
polys[i].clear();
|
||||
}
|
||||
|
||||
// printf("%zu rings in\n", in);
|
||||
|
||||
mapbox::geometry::multi_polygon<long long> result;
|
||||
wagyu.execute(mapbox::geometry::wagyu::clip_type_union, result, mapbox::geometry::wagyu::fill_type_positive, mapbox::geometry::wagyu::fill_type_positive);
|
||||
|
||||
size_t out = 0;
|
||||
for (size_t i = 0; i < result.size(); i++) {
|
||||
for (size_t j = 0; j < result[i].size(); j++) {
|
||||
// XXX Why do the rings come back reversed?
|
||||
mapbox::geometry::linear_ring<long long> rev;
|
||||
for (ssize_t k = result[i][j].size() - 1; k >= 0; k--) {
|
||||
rev.push_back(result[i][j][k]);
|
||||
}
|
||||
|
||||
polys[start].push_back(rev);
|
||||
out++;
|
||||
}
|
||||
}
|
||||
// printf("%zu rings out\n", out);
|
||||
}
|
||||
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool clip, bool merge) {
|
||||
std::vector<std::vector<mapbox::geometry::linear_ring<long long>>> polys;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
@ -241,7 +293,13 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) {
|
||||
}
|
||||
|
||||
if (lr.size() >= 3) {
|
||||
wagyu.add_ring(lr);
|
||||
if (get_area(geom, i, j) >= 0 || polys.size() == 0) {
|
||||
std::vector<mapbox::geometry::linear_ring<long long>> p;
|
||||
p.push_back(lr);
|
||||
polys.push_back(p);
|
||||
} else {
|
||||
polys[polys.size() - 1].push_back(lr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,6 +307,22 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) {
|
||||
}
|
||||
}
|
||||
|
||||
if (merge) {
|
||||
divide_and_merge(polys, 0, polys.size());
|
||||
}
|
||||
|
||||
mapbox::geometry::wagyu::wagyu<long long> wagyu;
|
||||
|
||||
size_t in = 0;
|
||||
for (size_t i = 0; i < polys.size(); i++) {
|
||||
for (size_t j = 0; j < polys[i].size(); j++) {
|
||||
wagyu.add_ring(polys[i][j]);
|
||||
in++;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("out here: %zu rings\n", in);
|
||||
|
||||
if (clip) {
|
||||
long long area = 0xFFFFFFFF;
|
||||
if (z != 0) {
|
||||
@ -270,8 +344,8 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) {
|
||||
mapbox::geometry::multi_polygon<long long> result;
|
||||
try {
|
||||
wagyu.execute(mapbox::geometry::wagyu::clip_type_union, result, mapbox::geometry::wagyu::fill_type_positive, mapbox::geometry::wagyu::fill_type_positive);
|
||||
} catch (std::runtime_error &e) {
|
||||
FILE *f = fopen("/tmp/wagyu.log", "w");
|
||||
} catch (std::runtime_error e) {
|
||||
FILE *f = fopen("wagyu.log", "a");
|
||||
fprintf(f, "%s\n", e.what());
|
||||
fprintf(stderr, "%s\n", e.what());
|
||||
fprintf(f, "[");
|
||||
@ -314,9 +388,9 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip) {
|
||||
fprintf(f, "]");
|
||||
fprintf(f, "\n\n\n\n\n");
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
fclose(f);
|
||||
fprintf(stderr, "Internal error: Polygon cleaning failed. Log in /tmp/wagyu.log\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
drawvec ret;
|
||||
@ -346,42 +420,31 @@ static int pnpoly(drawvec &vert, size_t start, size_t nvert, long long testx, lo
|
||||
return c;
|
||||
}
|
||||
|
||||
void check_polygon(drawvec &geom) {
|
||||
geom = remove_noop(geom, VT_POLYGON, 0);
|
||||
void check_polygon(drawvec &geom, drawvec &before) {
|
||||
for (size_t i = 0; i + 1 < geom.size(); i++) {
|
||||
for (size_t j = i + 1; j + 1 < geom.size(); j++) {
|
||||
if (geom[i + 1].op == VT_LINETO && geom[j + 1].op == VT_LINETO) {
|
||||
double s1_x = geom[i + 1].x - geom[i + 0].x;
|
||||
double s1_y = geom[i + 1].y - geom[i + 0].y;
|
||||
double s2_x = geom[j + 1].x - geom[j + 0].x;
|
||||
double s2_y = geom[j + 1].y - geom[j + 0].y;
|
||||
|
||||
mapbox::geometry::multi_polygon<long long> mp;
|
||||
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;
|
||||
double s, t;
|
||||
s = (-s1_y * (geom[i + 0].x - geom[j + 0].x) + s1_x * (geom[i + 0].y - geom[j + 0].y)) / (-s2_x * s1_y + s1_x * s2_y);
|
||||
t = (s2_x * (geom[i + 0].y - geom[j + 0].y) - s2_y * (geom[i + 0].x - geom[j + 0].x)) / (-s2_x * s1_y + s1_x * s2_y);
|
||||
|
||||
if (t > 0 && t < 1 && s > 0 && s < 1) {
|
||||
printf("Internal error: self-intersecting polygon. %lld,%lld to %lld,%lld intersects %lld,%lld to %lld,%lld\n",
|
||||
geom[i + 0].x, geom[i + 0].y,
|
||||
geom[i + 1].x, geom[i + 1].y,
|
||||
geom[j + 0].x, geom[j + 0].y,
|
||||
geom[j + 1].x, geom[j + 1].y);
|
||||
dump(before);
|
||||
}
|
||||
}
|
||||
|
||||
if (j >= i + 4) {
|
||||
mapbox::geometry::linear_ring<long long> lr;
|
||||
|
||||
for (size_t k = i; k < j; k++) {
|
||||
lr.push_back(mapbox::geometry::point<long long>(geom[k].x, geom[k].y));
|
||||
}
|
||||
|
||||
if (lr.size() >= 3) {
|
||||
mapbox::geometry::polygon<long long> p;
|
||||
p.push_back(lr);
|
||||
mp.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
|
||||
mapbox::geometry::multi_polygon<long long> mp2 = mapbox::geometry::snap_round(mp, true, true);
|
||||
if (mp != mp2) {
|
||||
fprintf(stderr, "Internal error: self-intersecting polygon\n");
|
||||
}
|
||||
|
||||
size_t outer_start = -1;
|
||||
size_t outer_len = 0;
|
||||
|
||||
@ -418,6 +481,7 @@ void check_polygon(drawvec &geom) {
|
||||
if (!on_edge) {
|
||||
printf("%lld,%lld at %lld not in outer ring (%lld to %lld)\n", geom[k].x, geom[k].y, (long long) k, (long long) outer_start, (long long) (outer_start + outer_len));
|
||||
|
||||
dump(before);
|
||||
#if 0
|
||||
for (size_t l = outer_start; l < outer_start + outer_len; l++) {
|
||||
fprintf(stderr, " %lld,%lld", geom[l].x, geom[l].y);
|
||||
@ -461,13 +525,103 @@ drawvec close_poly(drawvec &geom) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool inside(draw d, int edge, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
switch (edge) {
|
||||
case 0: // top
|
||||
return d.y > miny;
|
||||
|
||||
case 1: // right
|
||||
return d.x < maxx;
|
||||
|
||||
case 2: // bottom
|
||||
return d.y < maxy;
|
||||
|
||||
case 3: // left
|
||||
return d.x > minx;
|
||||
}
|
||||
|
||||
fprintf(stderr, "internal error inside\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static draw intersect(draw a, draw b, int edge, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
// The casts to double are because the product of coordinates
|
||||
// can overflow a long long if the tile buffer is large.
|
||||
|
||||
switch (edge) {
|
||||
case 0: // top
|
||||
return draw(VT_LINETO, a.x + (double) (b.x - a.x) * (miny - a.y) / (b.y - a.y), miny);
|
||||
|
||||
case 1: // right
|
||||
return draw(VT_LINETO, maxx, a.y + (double) (b.y - a.y) * (maxx - a.x) / (b.x - a.x));
|
||||
|
||||
case 2: // bottom
|
||||
return draw(VT_LINETO, a.x + (double) (b.x - a.x) * (maxy - a.y) / (b.y - a.y), maxy);
|
||||
|
||||
case 3: // left
|
||||
return draw(VT_LINETO, minx, a.y + (double) (b.y - a.y) * (minx - a.x) / (b.x - a.x));
|
||||
}
|
||||
|
||||
fprintf(stderr, "internal error intersecting\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm
|
||||
static drawvec clip_poly1(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
drawvec out = geom;
|
||||
|
||||
for (int edge = 0; edge < 4; edge++) {
|
||||
if (out.size() > 0) {
|
||||
drawvec in = out;
|
||||
out.resize(0);
|
||||
|
||||
draw S = in[in.size() - 1];
|
||||
|
||||
for (size_t e = 0; e < in.size(); e++) {
|
||||
draw E = in[e];
|
||||
|
||||
if (inside(E, edge, minx, miny, maxx, maxy)) {
|
||||
if (!inside(S, edge, minx, miny, maxx, maxy)) {
|
||||
out.push_back(intersect(S, E, edge, minx, miny, maxx, maxy));
|
||||
}
|
||||
out.push_back(E);
|
||||
} else if (inside(S, edge, minx, miny, maxx, maxy)) {
|
||||
out.push_back(intersect(S, E, edge, minx, miny, maxx, maxy));
|
||||
}
|
||||
|
||||
S = E;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (out.size() > 0) {
|
||||
// If the polygon begins and ends outside the edge,
|
||||
// the starting and ending points will be left as the
|
||||
// places where it intersects the edge. Need to add
|
||||
// another point to close the loop.
|
||||
|
||||
if (out[0].x != out[out.size() - 1].x || out[0].y != out[out.size() - 1].y) {
|
||||
out.push_back(out[0]);
|
||||
}
|
||||
|
||||
if (out.size() < 3) {
|
||||
// fprintf(stderr, "Polygon degenerated to a line segment\n");
|
||||
out.clear();
|
||||
return out;
|
||||
}
|
||||
|
||||
out[0].op = VT_MOVETO;
|
||||
for (size_t i = 1; i < out.size(); i++) {
|
||||
out[i].op = VT_LINETO;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
drawvec out;
|
||||
|
||||
mapbox::geometry::point<long long> min(minx, miny);
|
||||
mapbox::geometry::point<long long> max(maxx, maxy);
|
||||
mapbox::geometry::box<long long> bbox(min, max);
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
@ -477,26 +631,20 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
|
||||
}
|
||||
}
|
||||
|
||||
mapbox::geometry::linear_ring<long long> ring;
|
||||
drawvec tmp;
|
||||
for (size_t k = i; k < j; k++) {
|
||||
ring.push_back(mapbox::geometry::point<long long>(geom[k].x, geom[k].y));
|
||||
tmp.push_back(geom[k]);
|
||||
}
|
||||
|
||||
mapbox::geometry::linear_ring<long long> lr = mapbox::geometry::wagyu::quick_clip::quick_lr_clip(ring, bbox);
|
||||
|
||||
if (lr.size() > 0) {
|
||||
for (size_t k = 0; k < lr.size(); k++) {
|
||||
if (k == 0) {
|
||||
out.push_back(draw(VT_MOVETO, lr[k].x, lr[k].y));
|
||||
} else {
|
||||
out.push_back(draw(VT_LINETO, lr[k].x, lr[k].y));
|
||||
}
|
||||
}
|
||||
|
||||
if (lr.size() > 0 && lr[0] != lr[lr.size() - 1]) {
|
||||
out.push_back(draw(VT_LINETO, lr[0].x, lr[0].y));
|
||||
tmp = clip_poly1(tmp, minx, miny, maxx, maxy);
|
||||
if (tmp.size() > 0) {
|
||||
if (tmp[0].x != tmp[tmp.size() - 1].x || tmp[0].y != tmp[tmp.size() - 1].y) {
|
||||
fprintf(stderr, "Internal error: Polygon ring not closed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
for (size_t k = 0; k < tmp.size(); k++) {
|
||||
out.push_back(tmp[k]);
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
} else {
|
||||
@ -508,7 +656,7 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int buffer) {
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int detail, int buffer) {
|
||||
long long area = 1LL << (32 - z);
|
||||
long long clip_buffer = buffer * area / 256;
|
||||
|
||||
@ -594,21 +742,17 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec clip_point(drawvec &geom, int z, long long buffer) {
|
||||
drawvec clip_point(drawvec &geom, int z, int detail, long long buffer) {
|
||||
drawvec out;
|
||||
|
||||
long long min = 0;
|
||||
long long area = 1LL << (32 - z);
|
||||
|
||||
min -= buffer * area / 256;
|
||||
area += buffer * area / 256;
|
||||
|
||||
return clip_point(geom, min, min, area, area);
|
||||
}
|
||||
|
||||
drawvec clip_point(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
drawvec out;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].x >= minx && geom[i].y >= miny && geom[i].x <= maxx && geom[i].y <= maxy) {
|
||||
if (geom[i].x >= min && geom[i].y >= min && geom[i].x <= area && geom[i].y <= area) {
|
||||
out.push_back(geom[i]);
|
||||
}
|
||||
}
|
||||
@ -616,7 +760,7 @@ drawvec clip_point(drawvec &geom, long long minx, long long miny, long long maxx
|
||||
return out;
|
||||
}
|
||||
|
||||
int quick_check(long long *bbox, int z, long long buffer) {
|
||||
int quick_check(long long *bbox, int z, int detail, long long buffer) {
|
||||
long long min = 0;
|
||||
long long area = 1LL << (32 - z);
|
||||
|
||||
@ -640,7 +784,7 @@ int quick_check(long long *bbox, int z, long long buffer) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool point_within_tile(long long x, long long y, int z) {
|
||||
bool point_within_tile(long long x, long long y, int z, int detail, long long buffer) {
|
||||
// No adjustment for buffer, because the point must be
|
||||
// strictly within the tile to appear exactly once
|
||||
|
||||
@ -649,18 +793,14 @@ bool point_within_tile(long long x, long long y, int z) {
|
||||
return x >= 0 && y >= 0 && x < area && y < area;
|
||||
}
|
||||
|
||||
drawvec clip_lines(drawvec &geom, int z, long long buffer) {
|
||||
drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer) {
|
||||
drawvec out;
|
||||
|
||||
long long min = 0;
|
||||
long long area = 1LL << (32 - z);
|
||||
min -= buffer * area / 256;
|
||||
area += buffer * area / 256;
|
||||
|
||||
return clip_lines(geom, min, min, area, area);
|
||||
}
|
||||
|
||||
drawvec clip_lines(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
drawvec out;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (i > 0 && (geom[i - 1].op == VT_MOVETO || geom[i - 1].op == VT_LINETO) && geom[i].op == VT_LINETO) {
|
||||
double x1 = geom[i - 1].x;
|
||||
@ -669,7 +809,7 @@ drawvec clip_lines(drawvec &geom, long long minx, long long miny, long long maxx
|
||||
double x2 = geom[i - 0].x;
|
||||
double y2 = geom[i - 0].y;
|
||||
|
||||
int c = clip(&x1, &y1, &x2, &y2, minx, miny, maxx, maxy);
|
||||
int c = clip(&x1, &y1, &x2, &y2, min, min, area, area);
|
||||
|
||||
if (c > 1) { // clipped
|
||||
out.push_back(draw(VT_MOVETO, x1, y1));
|
||||
@ -802,7 +942,7 @@ drawvec impose_tile_boundaries(drawvec &geom, long long extent) {
|
||||
return out;
|
||||
}
|
||||
|
||||
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes) {
|
||||
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain) {
|
||||
int res = 1 << (32 - detail - z);
|
||||
long long area = 1LL << (32 - z);
|
||||
|
||||
@ -814,13 +954,6 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
|
||||
} else {
|
||||
geom[i].necessary = 1;
|
||||
}
|
||||
|
||||
if (prevent[P_SIMPLIFY_SHARED_NODES]) {
|
||||
auto pt = std::lower_bound(shared_nodes.begin(), shared_nodes.end(), geom[i]);
|
||||
if (pt != shared_nodes.end() && *pt == geom[i]) {
|
||||
geom[i].necessary = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mark_tile_bounds) {
|
||||
@ -881,8 +1014,8 @@ drawvec reorder_lines(drawvec &geom) {
|
||||
// instead of down and to the right
|
||||
// so that it will coalesce better
|
||||
|
||||
unsigned long long l1 = encode_index(geom[0].x, geom[0].y);
|
||||
unsigned long long l2 = encode_index(geom[geom.size() - 1].x, geom[geom.size() - 1].y);
|
||||
unsigned long long l1 = encode(geom[0].x, geom[0].y);
|
||||
unsigned long long l2 = encode(geom[geom.size() - 1].x, geom[geom.size() - 1].y);
|
||||
|
||||
if (l1 > l2) {
|
||||
drawvec out;
|
||||
@ -928,21 +1061,8 @@ drawvec fix_polygon(drawvec &geom) {
|
||||
// Reverse ring if winding order doesn't match
|
||||
// inner/outer expectation
|
||||
|
||||
bool reverse_ring = false;
|
||||
if (prevent[P_USE_SOURCE_POLYGON_WINDING]) {
|
||||
// GeoJSON winding is reversed from vector winding
|
||||
reverse_ring = true;
|
||||
} else if (prevent[P_REVERSE_SOURCE_POLYGON_WINDING]) {
|
||||
// GeoJSON winding is reversed from vector winding
|
||||
reverse_ring = false;
|
||||
} else {
|
||||
double area = get_area(ring, 0, ring.size());
|
||||
if ((area > 0) != outer) {
|
||||
reverse_ring = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reverse_ring) {
|
||||
double area = get_area(ring, 0, ring.size());
|
||||
if ((area > 0) != outer) {
|
||||
drawvec tmp;
|
||||
for (int a = ring.size() - 1; a >= 0; a--) {
|
||||
tmp.push_back(ring[a]);
|
||||
@ -1136,89 +1256,3 @@ static int clip(double *x0, double *y0, double *x1, double *y1, double xmin, dou
|
||||
return changed + 1;
|
||||
}
|
||||
}
|
||||
|
||||
drawvec stairstep(drawvec &geom, int z, int detail) {
|
||||
drawvec out;
|
||||
double scale = 1 << (32 - detail - z);
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
geom[i].x = std::floor(geom[i].x / scale);
|
||||
geom[i].y = std::floor(geom[i].y / scale);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
out.push_back(geom[i]);
|
||||
} else if (out.size() > 0) {
|
||||
long long x0 = out[out.size() - 1].x;
|
||||
long long y0 = out[out.size() - 1].y;
|
||||
long long x1 = geom[i].x;
|
||||
long long y1 = geom[i].y;
|
||||
bool swap = false;
|
||||
|
||||
if (y0 < y1) {
|
||||
swap = true;
|
||||
std::swap(x0, x1);
|
||||
std::swap(y0, y1);
|
||||
}
|
||||
|
||||
long long xx = x0, yy = y0;
|
||||
long long dx = std::abs(x1 - x0);
|
||||
long long sx = (x0 < x1) ? 1 : -1;
|
||||
long long dy = std::abs(y1 - y0);
|
||||
long long sy = (y0 < y1) ? 1 : -1;
|
||||
long long err = ((dx > dy) ? dx : -dy) / 2;
|
||||
int last = -1;
|
||||
|
||||
drawvec tmp;
|
||||
tmp.push_back(draw(VT_LINETO, xx, yy));
|
||||
|
||||
while (xx != x1 || yy != y1) {
|
||||
long long e2 = err;
|
||||
|
||||
if (e2 > -dx) {
|
||||
err -= dy;
|
||||
xx += sx;
|
||||
if (last == 1) {
|
||||
tmp[tmp.size() - 1] = draw(VT_LINETO, xx, yy);
|
||||
} else {
|
||||
tmp.push_back(draw(VT_LINETO, xx, yy));
|
||||
}
|
||||
last = 1;
|
||||
}
|
||||
if (e2 < dy) {
|
||||
err += dx;
|
||||
yy += sy;
|
||||
if (last == 2) {
|
||||
tmp[tmp.size() - 1] = draw(VT_LINETO, xx, yy);
|
||||
} else {
|
||||
tmp.push_back(draw(VT_LINETO, xx, yy));
|
||||
}
|
||||
last = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (swap) {
|
||||
for (size_t j = tmp.size(); j > 0; j--) {
|
||||
out.push_back(tmp[j - 1]);
|
||||
}
|
||||
} else {
|
||||
for (size_t j = 0; j < tmp.size(); j++) {
|
||||
out.push_back(tmp[j]);
|
||||
}
|
||||
}
|
||||
|
||||
// out.push_back(draw(VT_LINETO, xx, yy));
|
||||
} else {
|
||||
fprintf(stderr, "Can't happen: stairstepping lineto with no moveto\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < out.size(); i++) {
|
||||
out[i].x *= 1 << (32 - detail - z);
|
||||
out[i].y *= 1 << (32 - detail - z);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
57
geometry.hpp
57
geometry.hpp
@ -1,10 +1,3 @@
|
||||
#ifndef GEOMETRY_HPP
|
||||
#define GEOMETRY_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#define VT_POINT 1
|
||||
#define VT_LINE 2
|
||||
#define VT_POLYGON 3
|
||||
@ -14,6 +7,10 @@
|
||||
#define VT_LINETO 2
|
||||
#define VT_CLOSEPATH 7
|
||||
|
||||
#define VT_STRING 1
|
||||
#define VT_NUMBER 2
|
||||
#define VT_BOOLEAN 7
|
||||
|
||||
// The bitfield is to make sizeof(draw) be 16 instead of 24
|
||||
// at the cost, apparently, of a 0.7% increase in running time
|
||||
// for packing and unpacking.
|
||||
@ -23,18 +20,18 @@ struct draw {
|
||||
long long y : 40;
|
||||
signed char necessary;
|
||||
|
||||
draw(int nop, long long nx, long long ny)
|
||||
: x(nx),
|
||||
op(nop),
|
||||
y(ny),
|
||||
necessary(0) {
|
||||
draw(int nop, long long nx, long long ny) {
|
||||
this->op = nop;
|
||||
this->x = nx;
|
||||
this->y = ny;
|
||||
this->necessary = 0;
|
||||
}
|
||||
|
||||
draw()
|
||||
: x(0),
|
||||
op(0),
|
||||
y(0),
|
||||
necessary(0) {
|
||||
draw() {
|
||||
this->op = 0;
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->necessary = 0;
|
||||
}
|
||||
|
||||
bool operator<(draw const &s) const {
|
||||
@ -56,28 +53,20 @@ struct draw {
|
||||
|
||||
typedef std::vector<draw> drawvec;
|
||||
|
||||
drawvec decode_geometry(FILE *meta, std::atomic<long long> *geompos, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y);
|
||||
drawvec decode_geometry(FILE *meta, long long *geompos, int z, unsigned tx, unsigned ty, int detail, long long *bbox, unsigned initial_x, unsigned initial_y);
|
||||
void to_tile_scale(drawvec &geom, int z, int detail);
|
||||
drawvec remove_noop(drawvec geom, int type, int shift);
|
||||
drawvec clip_point(drawvec &geom, int z, long long buffer);
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip);
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int buffer);
|
||||
drawvec clip_point(drawvec &geom, int z, int detail, long long buffer);
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool clip, bool merge);
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int detail, int buffer);
|
||||
drawvec close_poly(drawvec &geom);
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area);
|
||||
drawvec clip_lines(drawvec &geom, int z, long long buffer);
|
||||
drawvec stairstep(drawvec &geom, int z, int detail);
|
||||
bool point_within_tile(long long x, long long y, int z);
|
||||
int quick_check(long long *bbox, int z, long long buffer);
|
||||
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes);
|
||||
drawvec clip_lines(drawvec &geom, int z, int detail, long long buffer);
|
||||
bool point_within_tile(long long x, long long y, int z, int detail, long long buffer);
|
||||
int quick_check(long long *bbox, int z, int detail, long long buffer);
|
||||
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain);
|
||||
drawvec reorder_lines(drawvec &geom);
|
||||
drawvec fix_polygon(drawvec &geom);
|
||||
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms);
|
||||
void check_polygon(drawvec &geom);
|
||||
void check_polygon(drawvec &geom, drawvec &before);
|
||||
double get_area(drawvec &geom, size_t i, size_t j);
|
||||
double get_mp_area(drawvec &geom);
|
||||
|
||||
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
||||
drawvec clip_lines(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
||||
drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long long y2);
|
||||
|
||||
#endif
|
||||
|
@ -36,14 +36,14 @@ json_pull *json_begin(ssize_t (*read)(struct json_pull *, char *buffer, size_t n
|
||||
|
||||
static inline int peek(json_pull *j) {
|
||||
if (j->buffer_head < j->buffer_tail) {
|
||||
return (unsigned char) j->buffer[j->buffer_head];
|
||||
return j->buffer[j->buffer_head];
|
||||
} else {
|
||||
j->buffer_head = 0;
|
||||
j->buffer_tail = j->read(j, j->buffer, BUFFER);
|
||||
if (j->buffer_head >= j->buffer_tail) {
|
||||
return EOF;
|
||||
}
|
||||
return (unsigned char) j->buffer[j->buffer_head];
|
||||
return j->buffer[j->buffer_head];
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ json_pull *json_begin_file(FILE *f) {
|
||||
}
|
||||
|
||||
static ssize_t read_string(json_pull *j, char *buffer, size_t n) {
|
||||
const char *cp = j->source;
|
||||
char *cp = j->source;
|
||||
size_t out = 0;
|
||||
|
||||
while (out < n && cp[out] != '\0') {
|
||||
@ -77,12 +77,12 @@ static ssize_t read_string(json_pull *j, char *buffer, size_t n) {
|
||||
out++;
|
||||
}
|
||||
|
||||
j->source = (void *) (cp + out);
|
||||
j->source = cp + out;
|
||||
return out;
|
||||
}
|
||||
|
||||
json_pull *json_begin_string(const char *s) {
|
||||
return json_begin(read_string, (void *) s);
|
||||
json_pull *json_begin_string(char *s) {
|
||||
return json_begin(read_string, s);
|
||||
}
|
||||
|
||||
void json_end(json_pull *p) {
|
||||
@ -295,23 +295,7 @@ again:
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Byte-order mark
|
||||
if (c == 0xEF) {
|
||||
int c2 = peek(j);
|
||||
if (c2 == 0xBB) {
|
||||
c2 = read_wrap(j);
|
||||
c2 = peek(j);
|
||||
if (c2 == 0xBF) {
|
||||
c2 = read_wrap(j);
|
||||
c = ' ';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
j->error = "Corrupt byte-order mark found";
|
||||
return NULL;
|
||||
}
|
||||
} while (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 0x1E);
|
||||
} while (c == ' ' || c == '\t' || c == '\r' || c == '\n');
|
||||
|
||||
/////////////////////////// Arrays
|
||||
|
||||
@ -400,32 +384,6 @@ again:
|
||||
return add_object(j, JSON_NULL);
|
||||
}
|
||||
|
||||
/////////////////////////// NaN
|
||||
|
||||
if (c == 'N') {
|
||||
if (read_wrap(j) != 'a' || read_wrap(j) != 'N') {
|
||||
j->error = "Found misspelling of NaN";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
j->error = "JSON does not allow NaN";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////// Infinity
|
||||
|
||||
if (c == 'I') {
|
||||
if (read_wrap(j) != 'n' || read_wrap(j) != 'f' || read_wrap(j) != 'i' ||
|
||||
read_wrap(j) != 'n' || read_wrap(j) != 'i' || read_wrap(j) != 't' ||
|
||||
read_wrap(j) != 'y') {
|
||||
j->error = "Found misspelling of Infinity";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
j->error = "JSON does not allow Infinity";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////// True
|
||||
|
||||
if (c == 't') {
|
||||
@ -569,21 +527,29 @@ again:
|
||||
struct string val;
|
||||
string_init(&val);
|
||||
|
||||
int surrogate = -1;
|
||||
while ((c = read_wrap(j)) != EOF) {
|
||||
if (c == '"') {
|
||||
if (surrogate >= 0) {
|
||||
string_append(&val, 0xE0 | (surrogate >> 12));
|
||||
string_append(&val, 0x80 | ((surrogate >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (surrogate & 0x3F));
|
||||
surrogate = -1;
|
||||
}
|
||||
|
||||
break;
|
||||
} else if (c == '\\') {
|
||||
c = read_wrap(j);
|
||||
|
||||
if (c == 'u') {
|
||||
if (c == '"') {
|
||||
string_append(&val, '"');
|
||||
} else if (c == '\\') {
|
||||
string_append(&val, '\\');
|
||||
} else if (c == '/') {
|
||||
string_append(&val, '/');
|
||||
} else if (c == 'b') {
|
||||
string_append(&val, '\b');
|
||||
} else if (c == 'f') {
|
||||
string_append(&val, '\f');
|
||||
} else if (c == 'n') {
|
||||
string_append(&val, '\n');
|
||||
} else if (c == 'r') {
|
||||
string_append(&val, '\r');
|
||||
} else if (c == 't') {
|
||||
string_append(&val, '\t');
|
||||
} else if (c == 'u') {
|
||||
char hex[5] = "aaaa";
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
@ -594,93 +560,27 @@ again:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long ch = strtoul(hex, NULL, 16);
|
||||
if (ch >= 0xd800 && ch <= 0xdbff) {
|
||||
if (surrogate < 0) {
|
||||
surrogate = ch;
|
||||
} else {
|
||||
// Impossible surrogate, so output the first half,
|
||||
// keep what might be a legitimate new first half.
|
||||
string_append(&val, 0xE0 | (surrogate >> 12));
|
||||
string_append(&val, 0x80 | ((surrogate >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (surrogate & 0x3F));
|
||||
surrogate = ch;
|
||||
}
|
||||
continue;
|
||||
} else if (ch >= 0xdc00 && c <= 0xdfff) {
|
||||
if (surrogate >= 0) {
|
||||
long c1 = surrogate - 0xd800;
|
||||
long c2 = ch - 0xdc00;
|
||||
ch = ((c1 << 10) | c2) + 0x010000;
|
||||
surrogate = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (surrogate >= 0) {
|
||||
string_append(&val, 0xE0 | (surrogate >> 12));
|
||||
string_append(&val, 0x80 | ((surrogate >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (surrogate & 0x3F));
|
||||
surrogate = -1;
|
||||
}
|
||||
|
||||
if (ch <= 0x7F) {
|
||||
string_append(&val, ch);
|
||||
} else if (ch <= 0x7FF) {
|
||||
string_append(&val, 0xC0 | (ch >> 6));
|
||||
string_append(&val, 0x80 | (ch & 0x3F));
|
||||
} else if (ch < 0xFFFF) {
|
||||
string_append(&val, 0xE0 | (ch >> 12));
|
||||
string_append(&val, 0x80 | ((ch >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (ch & 0x3F));
|
||||
} else {
|
||||
string_append(&val, 0xF0 | (ch >> 18));
|
||||
string_append(&val, 0x80 | ((ch >> 12) & 0x3F));
|
||||
string_append(&val, 0xE0 | (ch >> 12));
|
||||
string_append(&val, 0x80 | ((ch >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (ch & 0x3F));
|
||||
}
|
||||
} else {
|
||||
if (surrogate >= 0) {
|
||||
string_append(&val, 0xE0 | (surrogate >> 12));
|
||||
string_append(&val, 0x80 | ((surrogate >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (surrogate & 0x3F));
|
||||
surrogate = -1;
|
||||
}
|
||||
|
||||
if (c == '"') {
|
||||
string_append(&val, '"');
|
||||
} else if (c == '\\') {
|
||||
string_append(&val, '\\');
|
||||
} else if (c == '/') {
|
||||
string_append(&val, '/');
|
||||
} else if (c == 'b') {
|
||||
string_append(&val, '\b');
|
||||
} else if (c == 'f') {
|
||||
string_append(&val, '\f');
|
||||
} else if (c == 'n') {
|
||||
string_append(&val, '\n');
|
||||
} else if (c == 'r') {
|
||||
string_append(&val, '\r');
|
||||
} else if (c == 't') {
|
||||
string_append(&val, '\t');
|
||||
} else {
|
||||
j->error = "Found backslash followed by unknown character";
|
||||
string_free(&val);
|
||||
return NULL;
|
||||
}
|
||||
j->error = "Found backslash followed by unknown character";
|
||||
string_free(&val);
|
||||
return NULL;
|
||||
}
|
||||
} else if (c < ' ') {
|
||||
j->error = "Found control character in string";
|
||||
string_free(&val);
|
||||
return NULL;
|
||||
} else {
|
||||
if (surrogate >= 0) {
|
||||
string_append(&val, 0xE0 | (surrogate >> 12));
|
||||
string_append(&val, 0x80 | ((surrogate >> 6) & 0x3F));
|
||||
string_append(&val, 0x80 | (surrogate & 0x3F));
|
||||
surrogate = -1;
|
||||
}
|
||||
|
||||
string_append(&val, c);
|
||||
}
|
||||
}
|
||||
@ -766,23 +666,6 @@ void json_free(json_object *o) {
|
||||
free(o);
|
||||
}
|
||||
|
||||
static void json_disconnect_parser(json_object *o) {
|
||||
if (o->type == JSON_HASH) {
|
||||
size_t i;
|
||||
for (i = 0; i < o->length; i++) {
|
||||
json_disconnect_parser(o->keys[i]);
|
||||
json_disconnect_parser(o->values[i]);
|
||||
}
|
||||
} else if (o->type == JSON_ARRAY) {
|
||||
size_t i;
|
||||
for (i = 0; i < o->length; i++) {
|
||||
json_disconnect_parser(o->array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
o->parser = NULL;
|
||||
}
|
||||
|
||||
void json_disconnect(json_object *o) {
|
||||
// Expunge references to this as an array element
|
||||
// or a hash key or value.
|
||||
@ -836,13 +719,12 @@ void json_disconnect(json_object *o) {
|
||||
o->parser->root = NULL;
|
||||
}
|
||||
|
||||
json_disconnect_parser(o);
|
||||
o->parent = NULL;
|
||||
}
|
||||
|
||||
static void json_print_one(struct string *val, json_object *o) {
|
||||
if (o == NULL) {
|
||||
string_append_string(val, "...");
|
||||
string_append_string(val, "NULL");
|
||||
} else if (o->type == JSON_STRING) {
|
||||
string_append(val, '\"');
|
||||
|
||||
@ -881,7 +763,7 @@ static void json_print_one(struct string *val, json_object *o) {
|
||||
static void json_print(struct string *val, json_object *o) {
|
||||
if (o == NULL) {
|
||||
// Hash value in incompletely read hash
|
||||
string_append_string(val, "...");
|
||||
string_append_string(val, "NULL");
|
||||
} else if (o->type == JSON_HASH) {
|
||||
string_append(val, '{');
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
#ifndef JSONPULL_H
|
||||
#define JSONPULL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum json_type {
|
||||
// These types can be returned by json_read()
|
||||
JSON_HASH,
|
||||
@ -56,7 +49,7 @@ typedef struct json_pull {
|
||||
} json_pull;
|
||||
|
||||
json_pull *json_begin_file(FILE *f);
|
||||
json_pull *json_begin_string(const char *s);
|
||||
json_pull *json_begin_string(char *s);
|
||||
|
||||
json_pull *json_begin(ssize_t (*read)(struct json_pull *, char *buffer, size_t n), void *source);
|
||||
void json_end(json_pull *p);
|
||||
@ -72,9 +65,3 @@ void json_disconnect(json_object *j);
|
||||
json_object *json_hash_get(json_object *o, const char *s);
|
||||
|
||||
char *json_stringify(json_object *o);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
499
jsontool.cpp
499
jsontool.cpp
@ -1,499 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
#include <vector>
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "csv.hpp"
|
||||
#include "text.hpp"
|
||||
#include "geojson-loop.hpp"
|
||||
|
||||
int fail = EXIT_SUCCESS;
|
||||
bool wrap = false;
|
||||
const char *extract = NULL;
|
||||
|
||||
FILE *csvfile = NULL;
|
||||
std::vector<std::string> header;
|
||||
std::vector<std::string> fields;
|
||||
int pe = false;
|
||||
|
||||
std::string buffered;
|
||||
int buffered_type = -1;
|
||||
// 0: nothing yet
|
||||
// 1: buffered a line
|
||||
// 2: wrote the line and the wrapper
|
||||
int buffer_state = 0;
|
||||
|
||||
std::vector<unsigned long> decode32(const char *s) {
|
||||
std::vector<unsigned long> utf32;
|
||||
|
||||
while (*s != '\0') {
|
||||
unsigned long b = *(s++) & 0xFF;
|
||||
|
||||
if (b < 0x80) {
|
||||
utf32.push_back(b);
|
||||
} else if ((b & 0xe0) == 0xc0) {
|
||||
unsigned long c = (b & 0x1f) << 6;
|
||||
unsigned long b1 = *(s++) & 0xFF;
|
||||
|
||||
if ((b1 & 0xc0) == 0x80) {
|
||||
c |= b1 & 0x3f;
|
||||
utf32.push_back(c);
|
||||
} else {
|
||||
s--;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else if ((b & 0xf0) == 0xe0) {
|
||||
unsigned long c = (b & 0x0f) << 12;
|
||||
unsigned long b1 = *(s++) & 0xFF;
|
||||
|
||||
if ((b1 & 0xc0) == 0x80) {
|
||||
c |= (b1 & 0x3f) << 6;
|
||||
unsigned long b2 = *(s++) & 0xFF;
|
||||
|
||||
if ((b2 & 0xc0) == 0x80) {
|
||||
c |= b2 & 0x3f;
|
||||
utf32.push_back(c);
|
||||
} else {
|
||||
s -= 2;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else {
|
||||
s--;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else if ((b & 0xf8) == 0xf0) {
|
||||
unsigned long c = (b & 0x07) << 18;
|
||||
unsigned long b1 = *(s++) & 0xFF;
|
||||
|
||||
if ((b1 & 0xc0) == 0x80) {
|
||||
c |= (b1 & 0x3f) << 12;
|
||||
unsigned long b2 = *(s++) & 0xFF;
|
||||
|
||||
if ((b2 & 0xc0) == 0x80) {
|
||||
c |= (b2 & 0x3f) << 6;
|
||||
unsigned long b3 = *(s++) & 0xFF;
|
||||
|
||||
if ((b3 & 0xc0) == 0x80) {
|
||||
c |= b3 & 0x3f;
|
||||
|
||||
utf32.push_back(c);
|
||||
} else {
|
||||
s -= 3;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else {
|
||||
s -= 2;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else {
|
||||
s -= 1;
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
} else {
|
||||
utf32.push_back(0xfffd);
|
||||
}
|
||||
}
|
||||
|
||||
return utf32;
|
||||
}
|
||||
|
||||
// This uses a really weird encoding for strings
|
||||
// so that they will sort in UTF-32 order in spite of quoting
|
||||
|
||||
std::string sort_quote(const char *s) {
|
||||
std::vector<unsigned long> utf32 = decode32(s);
|
||||
std::string ret;
|
||||
|
||||
for (size_t i = 0; i < utf32.size(); i++) {
|
||||
if (utf32[i] < 0xD800) {
|
||||
char buf[8];
|
||||
sprintf(buf, "\\u%04lu", utf32[i]);
|
||||
ret.append(std::string(buf));
|
||||
} else {
|
||||
unsigned long c = utf32[i];
|
||||
|
||||
if (c <= 0x7f) {
|
||||
ret.push_back(c);
|
||||
} else if (c <= 0x7ff) {
|
||||
ret.push_back(0xc0 | (c >> 6));
|
||||
ret.push_back(0x80 | (c & 0x3f));
|
||||
} else if (c <= 0xffff) {
|
||||
ret.push_back(0xe0 | (c >> 12));
|
||||
ret.push_back(0x80 | ((c >> 6) & 0x3f));
|
||||
ret.push_back(0x80 | (c & 0x3f));
|
||||
} else {
|
||||
ret.push_back(0xf0 | (c >> 18));
|
||||
ret.push_back(0x80 | ((c >> 12) & 0x3f));
|
||||
ret.push_back(0x80 | ((c >> 6) & 0x3f));
|
||||
ret.push_back(0x80 | (c & 0x3f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void out(std::string const &s, int type, json_object *properties) {
|
||||
if (extract != NULL) {
|
||||
std::string extracted = sort_quote("null");
|
||||
bool found = false;
|
||||
|
||||
json_object *o = json_hash_get(properties, extract);
|
||||
if (o != NULL) {
|
||||
found = true;
|
||||
if (o->type == JSON_STRING || o->type == JSON_NUMBER) {
|
||||
extracted = sort_quote(o->string);
|
||||
} else {
|
||||
// Don't really know what to do about sort quoting
|
||||
// for arbitrary objects
|
||||
|
||||
const char *out = json_stringify(o);
|
||||
extracted = sort_quote(out);
|
||||
free((void *) out);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: extract key \"%s\" not found in JSON\n", extract);
|
||||
warned = true;
|
||||
}
|
||||
}
|
||||
|
||||
printf("{\"%s\":%s}\n", extracted.c_str(), s.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wrap) {
|
||||
printf("%s\n", s.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer_state == 0) {
|
||||
buffered = s;
|
||||
buffered_type = type;
|
||||
buffer_state = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer_state == 1) {
|
||||
if (buffered_type == 1) {
|
||||
printf("{\"type\":\"FeatureCollection\",\"features\":[\n");
|
||||
} else {
|
||||
printf("{\"type\":\"GeometryCollection\",\"geometries\":[\n");
|
||||
}
|
||||
|
||||
printf("%s\n", buffered.c_str());
|
||||
buffer_state = 2;
|
||||
}
|
||||
|
||||
printf(",\n%s\n", s.c_str());
|
||||
|
||||
if (type != buffered_type) {
|
||||
fprintf(stderr, "Error: mix of bare geometries and features\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
std::string prev_joinkey;
|
||||
|
||||
void join_csv(json_object *j) {
|
||||
if (header.size() == 0) {
|
||||
std::string s = csv_getline(csvfile);
|
||||
if (s.size() == 0) {
|
||||
fprintf(stderr, "Couldn't get column header from CSV file\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s\n", err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
header = csv_split(s.c_str());
|
||||
|
||||
for (size_t i = 0; i < header.size(); i++) {
|
||||
header[i] = csv_dequote(header[i]);
|
||||
}
|
||||
|
||||
if (header.size() == 0) {
|
||||
fprintf(stderr, "No columns in CSV header \"%s\"\n", s.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
json_object *key = NULL;
|
||||
|
||||
if (properties != NULL) {
|
||||
key = json_hash_get(properties, header[0].c_str());
|
||||
}
|
||||
|
||||
if (key == NULL) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: couldn't find CSV key \"%s\" in JSON\n", header[0].c_str());
|
||||
warned = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string joinkey;
|
||||
if (key->type == JSON_STRING || key->type == JSON_NUMBER) {
|
||||
joinkey = key->string;
|
||||
} else {
|
||||
const char *s = json_stringify(key);
|
||||
joinkey = s;
|
||||
free((void *) s);
|
||||
}
|
||||
|
||||
if (joinkey < prev_joinkey) {
|
||||
fprintf(stderr, "GeoJSON file is out of sort: \"%s\" follows \"%s\"\n", joinkey.c_str(), prev_joinkey.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
prev_joinkey = joinkey;
|
||||
|
||||
if (fields.size() == 0 || joinkey > fields[0]) {
|
||||
std::string prevkey;
|
||||
if (fields.size() > 0) {
|
||||
prevkey = fields[0];
|
||||
}
|
||||
|
||||
while (true) {
|
||||
std::string s = csv_getline(csvfile);
|
||||
if (s.size() == 0) {
|
||||
fields.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
std::string err = check_utf8(s);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s\n", err.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fields = csv_split(s.c_str());
|
||||
|
||||
for (size_t i = 0; i < fields.size(); i++) {
|
||||
fields[i] = csv_dequote(fields[i]);
|
||||
}
|
||||
|
||||
if (fields.size() > 0 && fields[0] < prevkey) {
|
||||
fprintf(stderr, "CSV file is out of sort: \"%s\" follows \"%s\"\n", fields[0].c_str(), prevkey.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (fields.size() > 0 && fields[0] >= joinkey) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (fields.size() > 0) {
|
||||
prevkey = fields[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fields.size() > 0 && joinkey == fields[0]) {
|
||||
// This knows more about the structure of JSON objects than it ought to
|
||||
properties->keys = (json_object **) realloc((void *) properties->keys, (properties->length + 32 + fields.size()) * sizeof(json_object *));
|
||||
properties->values = (json_object **) realloc((void *) properties->values, (properties->length + 32 + fields.size()) * sizeof(json_object *));
|
||||
if (properties->keys == NULL || properties->values == NULL) {
|
||||
perror("realloc");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < fields.size(); i++) {
|
||||
std::string k = header[i];
|
||||
std::string v = fields[i];
|
||||
json_type attr_type = JSON_STRING;
|
||||
|
||||
if (v.size() > 0) {
|
||||
if (v[0] == '"') {
|
||||
v = csv_dequote(v);
|
||||
} else if (is_number(v)) {
|
||||
attr_type = JSON_NUMBER;
|
||||
}
|
||||
} else if (pe) {
|
||||
attr_type = JSON_NULL;
|
||||
}
|
||||
|
||||
if (attr_type != JSON_NULL) {
|
||||
// This knows more about the structure of JSON objects than it ought to
|
||||
|
||||
json_object *ko = (json_object *) malloc(sizeof(json_object));
|
||||
json_object *vo = (json_object *) malloc(sizeof(json_object));
|
||||
if (ko == NULL || vo == NULL) {
|
||||
perror("malloc");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ko->type = JSON_STRING;
|
||||
vo->type = attr_type;
|
||||
|
||||
ko->parent = vo->parent = properties;
|
||||
ko->array = vo->array = NULL;
|
||||
ko->keys = vo->keys = NULL;
|
||||
ko->values = vo->values = NULL;
|
||||
ko->parser = vo->parser = properties->parser;
|
||||
|
||||
ko->string = strdup(k.c_str());
|
||||
vo->string = strdup(v.c_str());
|
||||
|
||||
if (ko->string == NULL || vo->string == NULL) {
|
||||
perror("strdup");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ko->length = strlen(ko->string);
|
||||
vo->length = strlen(vo->string);
|
||||
vo->number = atof(vo->string);
|
||||
|
||||
properties->keys[properties->length] = ko;
|
||||
properties->values[properties->length] = vo;
|
||||
properties->length++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct json_join_action : json_feature_action {
|
||||
int add_feature(json_object *geometry, bool, json_object *, json_object *, json_object *, json_object *feature) {
|
||||
if (feature != geometry) { // a real feature, not a bare geometry
|
||||
if (csvfile != NULL) {
|
||||
join_csv(feature);
|
||||
}
|
||||
|
||||
char *s = json_stringify(feature);
|
||||
out(s, 1, json_hash_get(feature, "properties"));
|
||||
free(s);
|
||||
} else {
|
||||
char *s = json_stringify(geometry);
|
||||
out(s, 2, NULL);
|
||||
free(s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void check_crs(json_object *) {
|
||||
}
|
||||
};
|
||||
|
||||
void process(FILE *fp, const char *fname) {
|
||||
json_pull *jp = json_begin_file(fp);
|
||||
|
||||
json_join_action jja;
|
||||
jja.fname = fname;
|
||||
parse_json(&jja, jp);
|
||||
json_end(jp);
|
||||
}
|
||||
|
||||
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(':');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int optind;
|
||||
int i;
|
||||
|
||||
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
extract = optarg;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
csv = optarg;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (strcmp(optarg, "e") == 0) {
|
||||
pe = true;
|
||||
} else {
|
||||
fprintf(stderr, "%s: Unknown option for -p%s\n", argv[0], optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unexpected option -%c\n", i);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (extract != NULL && wrap) {
|
||||
fprintf(stderr, "%s: --wrap and --extract not supported together\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (csv != NULL) {
|
||||
csvfile = fopen(csv, "r");
|
||||
if (csvfile == NULL) {
|
||||
perror(csv);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind >= argc) {
|
||||
process(stdin, "standard input");
|
||||
} else {
|
||||
for (i = optind; i < argc; i++) {
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
if (f == NULL) {
|
||||
perror(argv[i]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
process(f, argv[i]);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer_state == 1) {
|
||||
printf("%s\n", buffered.c_str());
|
||||
} else if (buffer_state == 2) {
|
||||
printf("]}\n");
|
||||
}
|
||||
|
||||
if (csvfile != NULL) {
|
||||
if (fclose(csvfile) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
return fail;
|
||||
}
|
50
main.hpp
50
main.hpp
@ -1,58 +1,18 @@
|
||||
#ifndef MAIN_HPP
|
||||
#define MAIN_HPP
|
||||
|
||||
#include <stddef.h>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
struct index {
|
||||
long long start = 0;
|
||||
long long end = 0;
|
||||
unsigned long long ix = 0;
|
||||
short segment = 0;
|
||||
long long start;
|
||||
long long end;
|
||||
unsigned long long index;
|
||||
short segment;
|
||||
unsigned short t : 2;
|
||||
unsigned long long seq : (64 - 18); // pack with segment and t to stay in 32 bytes
|
||||
|
||||
index()
|
||||
: t(0),
|
||||
seq(0) {
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
void checkdisk(struct reader *r, int nreader);
|
||||
|
||||
extern int geometry_scale;
|
||||
extern int quiet;
|
||||
extern int quiet_progress;
|
||||
extern double progress_interval;
|
||||
extern std::atomic<double> last_progress;
|
||||
|
||||
extern size_t CPUS;
|
||||
extern size_t TEMP_FILES;
|
||||
|
||||
extern size_t max_tile_size;
|
||||
extern size_t max_tile_features;
|
||||
extern int cluster_distance;
|
||||
extern std::string attribute_for_id;
|
||||
|
||||
int mkstemp_cloexec(char *name);
|
||||
FILE *fopen_oflag(const char *name, const char *mode, int oflag);
|
||||
bool progress_time();
|
||||
|
||||
#define MAX_ZOOM 24
|
||||
|
||||
#endif
|
||||
|
1056
man/tippecanoe.1
1056
man/tippecanoe.1
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
Copyright (c) 2016, Mapbox
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
@ -1,25 +0,0 @@
|
||||
Copyright (c) MapBox
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
- Neither the name "MapBox" nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -1,39 +0,0 @@
|
||||
Parts of the code in the Wagyu Library are derived from the version of the
|
||||
Clipper Library by Angus Johnson listed below.
|
||||
|
||||
Author : Angus Johnson
|
||||
Version : 6.4.0
|
||||
Date : 2 July 2015
|
||||
Website : http://www.angusj.com
|
||||
|
||||
Copyright for portions of the derived code in the Wagyu library are held
|
||||
by Angus Johnson, 2010-2015. Copyright for the "include/mapbox/geometry/wagyu/almost_equal.hpp"
|
||||
file is held by Google Inc and its license is listed at the top of that file.
|
||||
All other copyright for the Wagyu Library are held by Mapbox, 2016. This code
|
||||
is published in accordance with, and retains the same license as the Clipper
|
||||
Library by Angus Johnson.
|
||||
|
||||
Copyright (c) 2010-2015, Angus Johnson
|
||||
Copyright (c) 2016-2020, Mapbox
|
||||
|
||||
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.
|
@ -1,466 +0,0 @@
|
||||
#include <mapbox/geometry/geometry.hpp>
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
|
||||
template <typename T>
|
||||
void add_vertical(size_t intermediate, size_t which_end, size_t into, std::vector<std::vector<point<T>>> &segments, bool &again, std::vector<size_t> &nexts) {
|
||||
again = true;
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(segments[intermediate][which_end]);
|
||||
dv.push_back(segments[into][1]);
|
||||
segments.push_back(dv);
|
||||
segments[into][1] = segments[intermediate][which_end];
|
||||
nexts.push_back(nexts[into]);
|
||||
nexts[into] = nexts.size() - 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_horizontal(size_t intermediate, size_t which_end, size_t into, std::vector<std::vector<point<T>>> &segments, bool &again, std::vector<size_t> &nexts) {
|
||||
again = true;
|
||||
|
||||
T x = segments[intermediate][which_end].x;
|
||||
T y = segments[intermediate][0].y +
|
||||
(segments[intermediate][which_end].x - segments[intermediate][0].x) *
|
||||
(segments[intermediate][1].y - segments[intermediate][0].y) /
|
||||
(segments[intermediate][1].x - segments[intermediate][0].x);
|
||||
point<T> d(x, y);
|
||||
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(d);
|
||||
dv.push_back(segments[into][1]);
|
||||
segments.push_back(dv);
|
||||
segments[into][1] = d;
|
||||
nexts.push_back(nexts[into]);
|
||||
nexts[into] = nexts.size() - 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void warn(std::vector<std::vector<point<T>>> &segments, size_t a, size_t b, bool do_warn) {
|
||||
if (do_warn) {
|
||||
fprintf(stderr, "%lld,%lld to %lld,%lld intersects %lld,%lld to %lld,%lld\n",
|
||||
(long long) segments[a][0].x, (long long) segments[a][0].y,
|
||||
(long long) segments[a][1].x, (long long) segments[a][1].y,
|
||||
(long long) segments[b][0].x, (long long) segments[b][0].y,
|
||||
(long long) segments[b][1].x, (long long) segments[b][1].y);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void check_intersection(std::vector<std::vector<point<T>>> &segments, size_t a, size_t b, bool &again, std::vector<size_t> &nexts, bool do_warn, bool endpoint_ok) {
|
||||
T s10_x = segments[a][1].x - segments[a][0].x;
|
||||
T s10_y = segments[a][1].y - segments[a][0].y;
|
||||
T s32_x = segments[b][1].x - segments[b][0].x;
|
||||
T s32_y = segments[b][1].y - segments[b][0].y;
|
||||
|
||||
// http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
|
||||
T denom = s10_x * s32_y - s32_x * s10_y;
|
||||
|
||||
if (denom == 0) {
|
||||
// They are parallel or collinear. Find out if they are collinear.
|
||||
// http://www.cpsc.ucalgary.ca/~marina/papers/Segment_intersection.ps
|
||||
|
||||
T ccw =
|
||||
segments[a][0].x * segments[a][1].y +
|
||||
segments[a][1].x * segments[b][0].y +
|
||||
segments[b][0].x * segments[a][0].y -
|
||||
segments[a][0].x * segments[b][0].y -
|
||||
segments[a][1].x * segments[a][0].y -
|
||||
segments[b][0].x * segments[a][1].y;
|
||||
|
||||
if (ccw == 0) {
|
||||
if (segments[a][0].x == segments[a][1].x) {
|
||||
// Vertical
|
||||
|
||||
T amin, amax, bmin, bmax;
|
||||
if (segments[a][0].y < segments[a][1].y) {
|
||||
amin = segments[a][0].y;
|
||||
amax = segments[a][1].y;
|
||||
} else {
|
||||
amin = segments[a][1].y;
|
||||
amax = segments[a][0].y;
|
||||
}
|
||||
if (segments[b][0].y < segments[b][1].y) {
|
||||
bmin = segments[b][0].y;
|
||||
bmax = segments[b][1].y;
|
||||
} else {
|
||||
bmin = segments[b][1].y;
|
||||
bmax = segments[b][0].y;
|
||||
}
|
||||
|
||||
// All of these transformations preserve verticality so we can check multiple cases
|
||||
if (segments[b][0].y > amin && segments[b][0].y < amax) {
|
||||
// B0 is in A
|
||||
warn(segments, a, b, do_warn);
|
||||
add_vertical(b, 0, a, segments, again, nexts);
|
||||
}
|
||||
if (segments[b][1].y > amin && segments[b][1].y < amax) {
|
||||
// B1 is in A
|
||||
warn(segments, a, b, do_warn);
|
||||
add_vertical(b, 1, a, segments, again, nexts);
|
||||
}
|
||||
if (segments[a][0].y > bmin && segments[a][0].y < bmax) {
|
||||
// A0 is in B
|
||||
warn(segments, a, b, do_warn);
|
||||
add_vertical(a, 0, b, segments, again, nexts);
|
||||
}
|
||||
if (segments[a][1].y > bmin && segments[a][1].y < bmax) {
|
||||
// A1 is in B
|
||||
warn(segments, a, b, do_warn);
|
||||
add_vertical(a, 1, b, segments, again, nexts);
|
||||
}
|
||||
} else {
|
||||
// Horizontal or diagonal
|
||||
|
||||
T amin, amax, bmin, bmax;
|
||||
if (segments[a][0].x < segments[a][1].x) {
|
||||
amin = segments[a][0].x;
|
||||
amax = segments[a][1].x;
|
||||
} else {
|
||||
amin = segments[a][1].x;
|
||||
amax = segments[a][0].x;
|
||||
}
|
||||
if (segments[b][0].x < segments[b][1].x) {
|
||||
bmin = segments[b][0].x;
|
||||
bmax = segments[b][1].x;
|
||||
} else {
|
||||
bmin = segments[b][1].x;
|
||||
bmax = segments[b][0].x;
|
||||
}
|
||||
|
||||
// Don't check multiples, because rounding may corrupt collinearity
|
||||
if (segments[b][0].x > amin && segments[b][0].x < amax) {
|
||||
// B0 is in A
|
||||
add_horizontal(b, 0, a, segments, again, nexts);
|
||||
warn(segments, a, b, do_warn);
|
||||
} else if (segments[b][1].x > amin && segments[b][1].x < amax) {
|
||||
// B1 is in A
|
||||
add_horizontal(b, 1, a, segments, again, nexts);
|
||||
warn(segments, a, b, do_warn);
|
||||
} else if (segments[a][0].x > bmin && segments[a][0].x < bmax) {
|
||||
// A0 is in B
|
||||
warn(segments, a, b, do_warn);
|
||||
add_horizontal(a, 0, b, segments, again, nexts);
|
||||
} else if (segments[a][1].x > bmin && segments[a][1].x < bmax) {
|
||||
// A1 is in B
|
||||
warn(segments, a, b, do_warn);
|
||||
add_horizontal(a, 1, b, segments, again, nexts);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Neither parallel nor collinear, so may intersect at a single point
|
||||
|
||||
T s02_x = segments[a][0].x - segments[b][0].x;
|
||||
T s02_y = segments[a][0].y - segments[b][0].y;
|
||||
|
||||
double s = (s10_x * s02_y - s10_y * s02_x) / (long double) denom;
|
||||
double t = (s32_x * s02_y - s32_y * s02_x) / (long double) denom;
|
||||
|
||||
if (t >= 0 && t <= 1 && s >= 0 && s <= 1) {
|
||||
T x = (T) round(segments[a][0].x + t * s10_x);
|
||||
T y = (T) round(segments[a][0].y + t * s10_y);
|
||||
|
||||
if ((t > 0 && t < 1 && s > 0 && s < 1) || !endpoint_ok) {
|
||||
if (t >= 0 && t <= 1) {
|
||||
if ((x != segments[a][0].x || y != segments[a][0].y) && (x != segments[a][1].x || y != segments[a][1].y)) {
|
||||
warn(segments, a, b, do_warn);
|
||||
// splitting a
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(point<T>(x, y));
|
||||
dv.push_back(segments[a][1]);
|
||||
segments.push_back(dv);
|
||||
segments[a][1] = point<T>(x, y);
|
||||
nexts.push_back(nexts[a]);
|
||||
nexts[a] = nexts.size() - 1;
|
||||
again = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (s >= 0 && s <= 1) {
|
||||
if ((x != segments[b][0].x || y != segments[b][0].y) && (x != segments[b][1].x || y != segments[b][1].y)) {
|
||||
// splitting b
|
||||
warn(segments, a, b, do_warn);
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(point<T>(x, y));
|
||||
dv.push_back(segments[b][1]);
|
||||
segments.push_back(dv);
|
||||
segments[b][1] = point<T>(x, y);
|
||||
nexts.push_back(nexts[b]);
|
||||
nexts[b] = nexts.size() - 1;
|
||||
again = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void partition(std::vector<std::vector<point<T>>> &segs, std::vector<size_t> &subset, int direction, std::set<std::pair<size_t, size_t>> &possible) {
|
||||
std::vector<T> points;
|
||||
|
||||
// List of X or Y midpoints of edges, so we can find the median
|
||||
|
||||
if (direction == 0) {
|
||||
for (size_t i = 0; i < subset.size(); i++) {
|
||||
points.push_back((segs[subset[i]][0].x + segs[subset[i]][1].x) / 2);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < subset.size(); i++) {
|
||||
points.push_back((segs[subset[i]][0].y + segs[subset[i]][1].y) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (points.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t mid = points.size() / 2;
|
||||
std::nth_element(points.begin(), points.begin() + mid, points.end());
|
||||
T median = points[mid];
|
||||
|
||||
// Partition into sets that are above or below, or to the left or to the right of, the median.
|
||||
// Segments that cross the median appear in both.
|
||||
|
||||
std::vector<size_t> one;
|
||||
std::vector<size_t> two;
|
||||
|
||||
if (direction == 0) {
|
||||
for (size_t i = 0; i < subset.size(); i++) {
|
||||
if (segs[subset[i]][0].x <= median || segs[subset[i]][1].x <= median) {
|
||||
one.push_back(subset[i]);
|
||||
}
|
||||
if (segs[subset[i]][0].x >= median || segs[subset[i]][1].x >= median) {
|
||||
two.push_back(subset[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < subset.size(); i++) {
|
||||
if (segs[subset[i]][0].y <= median || segs[subset[i]][1].y <= median) {
|
||||
one.push_back(subset[i]);
|
||||
}
|
||||
if (segs[subset[i]][0].y >= median || segs[subset[i]][1].y >= median) {
|
||||
two.push_back(subset[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (one.size() >= subset.size() || two.size() >= subset.size()) {
|
||||
for (size_t i = 0; i < subset.size(); i++) {
|
||||
for (size_t j = i + 1; j < subset.size(); j++) {
|
||||
possible.insert(std::pair<size_t, size_t>(subset[i], subset[j]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// By experiment, stopping at 10 is a little faster than either 5 or 20
|
||||
|
||||
if (one.size() < 10) {
|
||||
for (size_t i = 0; i < one.size(); i++) {
|
||||
for (size_t j = i + 1; j < one.size(); j++) {
|
||||
possible.insert(std::pair<size_t, size_t>(one[i], one[j]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partition(segs, one, !direction, possible);
|
||||
}
|
||||
|
||||
if (two.size() < 10) {
|
||||
for (size_t i = 0; i < two.size(); i++) {
|
||||
for (size_t j = i + 1; j < two.size(); j++) {
|
||||
possible.insert(std::pair<size_t, size_t>(two[i], two[j]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partition(segs, two, !direction, possible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<std::vector<point<T>>> intersect_segments(std::vector<std::vector<point<T>>> segments, std::vector<size_t> &nexts, bool do_warn, bool endpoint_ok) {
|
||||
bool again = true;
|
||||
|
||||
while (again) {
|
||||
again = false;
|
||||
|
||||
std::set<std::pair<size_t, size_t>> possible;
|
||||
|
||||
std::vector<size_t> subset;
|
||||
for (size_t i = 0; i < segments.size(); i++) {
|
||||
subset.push_back(i);
|
||||
}
|
||||
|
||||
partition(segments, subset, 0, possible);
|
||||
|
||||
for (auto it = possible.begin(); it != possible.end(); ++it) {
|
||||
check_intersection(segments, it->first, it->second, again, nexts, do_warn, endpoint_ok);
|
||||
}
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
linear_ring<T> remove_collinear(linear_ring<T> ring) {
|
||||
linear_ring<T> out;
|
||||
|
||||
size_t len = ring.size() - 1; // Exclude duplicated last point
|
||||
for (size_t j = 0; j < len; j++) {
|
||||
long long ccw =
|
||||
ring[(j + len - 1) % len].x * ring[(j + len - 0) % len].y +
|
||||
ring[(j + len - 0) % len].x * ring[(j + len + 1) % len].y +
|
||||
ring[(j + len + 1) % len].x * ring[(j + len - 1) % len].y -
|
||||
ring[(j + len - 1) % len].x * ring[(j + len + 1) % len].y -
|
||||
ring[(j + len - 0) % len].x * ring[(j + len - 1) % len].y -
|
||||
ring[(j + len + 1) % len].x * ring[(j + len - 0) % len].y;
|
||||
|
||||
if (ccw != 0) {
|
||||
out.push_back(ring[j]);
|
||||
}
|
||||
|
||||
if (ring.size() > 0 && ring[0] != ring[ring.size() - 1]) {
|
||||
ring.push_back(ring[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
multi_polygon<T> snap_round(multi_polygon<T> geom, bool do_warn, bool endpoint_ok) {
|
||||
std::vector<std::vector<point<T>>> segments;
|
||||
std::vector<size_t> nexts;
|
||||
std::vector<std::vector<size_t>> ring_starts;
|
||||
|
||||
// Crunch out any 0-length segments
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
for (size_t j = 0; j < geom[i].size(); j++) {
|
||||
for (ssize_t k = geom[i][j].size() - 1; k > 0; k--) {
|
||||
if (geom[i][j][k] == geom[i][j][k - 1]) {
|
||||
geom[i][j].erase(geom[i][j].begin() + k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
ring_starts.push_back(std::vector<size_t>());
|
||||
|
||||
for (size_t j = 0; j < geom[i].size(); j++) {
|
||||
size_t s = geom[i][j].size();
|
||||
|
||||
if (s > 1) {
|
||||
ring_starts[i].push_back(segments.size());
|
||||
size_t first = nexts.size();
|
||||
|
||||
for (size_t k = 0; k + 1 < s; k++) {
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(geom[i][j][k]);
|
||||
dv.push_back(geom[i][j][k + 1]);
|
||||
|
||||
segments.push_back(dv);
|
||||
nexts.push_back(nexts.size() + 1);
|
||||
}
|
||||
|
||||
// Fabricate a point if ring was not closed
|
||||
if (geom[i][j][0] != geom[i][j][s - 1]) {
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(geom[i][j][s - 1]);
|
||||
dv.push_back(geom[i][j][0]);
|
||||
|
||||
segments.push_back(dv);
|
||||
nexts.push_back(nexts.size() + 1);
|
||||
}
|
||||
|
||||
// Last point of ring points back to first
|
||||
nexts[nexts.size() - 1] = first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
segments = intersect_segments(segments, nexts, do_warn, endpoint_ok);
|
||||
|
||||
multi_polygon<T> mp;
|
||||
for (size_t i = 0; i < ring_starts.size(); i++) {
|
||||
mp.push_back(polygon<T>());
|
||||
|
||||
for (size_t j = 0; j < ring_starts[i].size(); j++) {
|
||||
mp[i].push_back(linear_ring<T>());
|
||||
|
||||
size_t k = ring_starts[i][j];
|
||||
do {
|
||||
mp[i][j].push_back(segments[k][0]);
|
||||
k = nexts[k];
|
||||
} while (k != ring_starts[i][j]);
|
||||
|
||||
mp[i][j].push_back(segments[ring_starts[i][j]][0]);
|
||||
}
|
||||
}
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
multi_line_string<T> snap_round(multi_line_string<T> geom, bool do_warn, bool endpoint_ok) {
|
||||
std::vector<std::vector<point<T>>> segments;
|
||||
std::vector<size_t> nexts;
|
||||
std::vector<size_t> ring_starts;
|
||||
|
||||
// Crunch out any 0-length segments
|
||||
for (size_t j = 0; j < geom.size(); j++) {
|
||||
for (ssize_t k = geom[j].size() - 1; k > 0; k--) {
|
||||
if (geom[j][k] == geom[j][k - 1]) {
|
||||
geom[j].erase(geom[j].begin() + k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < geom.size(); j++) {
|
||||
size_t s = geom[j].size();
|
||||
|
||||
if (s > 1) {
|
||||
ring_starts.push_back(segments.size());
|
||||
size_t first = nexts.size();
|
||||
|
||||
for (size_t k = 0; k + 1 < s; k++) {
|
||||
std::vector<point<T>> dv;
|
||||
dv.push_back(geom[j][k]);
|
||||
dv.push_back(geom[j][k + 1]);
|
||||
|
||||
segments.push_back(dv);
|
||||
nexts.push_back(nexts.size() + 1);
|
||||
}
|
||||
|
||||
// Last point of ring points back to first
|
||||
nexts[nexts.size() - 1] = first;
|
||||
}
|
||||
}
|
||||
|
||||
segments = intersect_segments(segments, nexts, do_warn, endpoint_ok);
|
||||
|
||||
multi_line_string<T> mp;
|
||||
for (size_t j = 0; j < ring_starts.size(); j++) {
|
||||
mp.push_back(line_string<T>());
|
||||
|
||||
size_t k = ring_starts[j];
|
||||
size_t last = k;
|
||||
do {
|
||||
mp[j].push_back(segments[k][0]);
|
||||
last = k;
|
||||
k = nexts[k];
|
||||
} while (k != ring_starts[j]);
|
||||
|
||||
mp[j].push_back(segments[last][1]);
|
||||
}
|
||||
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,396 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <mapbox/geometry/wagyu/bound.hpp>
|
||||
#include <mapbox/geometry/wagyu/config.hpp>
|
||||
#include <mapbox/geometry/wagyu/edge.hpp>
|
||||
#include <mapbox/geometry/wagyu/local_minimum.hpp>
|
||||
#include <mapbox/geometry/wagyu/local_minimum_util.hpp>
|
||||
#include <mapbox/geometry/wagyu/ring.hpp>
|
||||
#include <mapbox/geometry/wagyu/scanbeam.hpp>
|
||||
#include <mapbox/geometry/wagyu/util.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T>
|
||||
using active_bound_list = std::vector<bound_ptr<T>>;
|
||||
|
||||
template <typename T>
|
||||
using active_bound_list_itr = typename active_bound_list<T>::iterator;
|
||||
|
||||
template <typename T>
|
||||
using active_bound_list_rev_itr = typename active_bound_list<T>::reverse_iterator;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
template <class charT, class traits, typename T>
|
||||
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
|
||||
const active_bound_list<T>& bnds) {
|
||||
std::size_t c = 0;
|
||||
for (auto const& bnd : bnds) {
|
||||
out << "Index: " << c++ << std::endl;
|
||||
out << *bnd;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string output_edges(active_bound_list<T> const& bnds) {
|
||||
std::ostringstream out;
|
||||
out << "[";
|
||||
bool first = true;
|
||||
for (auto const& bnd : bnds) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
out << ",";
|
||||
}
|
||||
out << "[[" << bnd->current_edge->bot.x << "," << bnd->current_edge->bot.y << "],[";
|
||||
out << bnd->current_edge->top.x << "," << bnd->current_edge->top.y << "]]";
|
||||
}
|
||||
out << "]";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
bool is_even_odd_fill_type(bound<T> const& bound, fill_type subject_fill_type, fill_type clip_fill_type) {
|
||||
if (bound.poly_type == polygon_type_subject) {
|
||||
return subject_fill_type == fill_type_even_odd;
|
||||
} else {
|
||||
return clip_fill_type == fill_type_even_odd;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool is_even_odd_alt_fill_type(bound<T> const& bound, fill_type subject_fill_type, fill_type clip_fill_type) {
|
||||
if (bound.poly_type == polygon_type_subject) {
|
||||
return clip_fill_type == fill_type_even_odd;
|
||||
} else {
|
||||
return subject_fill_type == fill_type_even_odd;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct bound_insert_location {
|
||||
|
||||
bound<T> const& bound2;
|
||||
|
||||
bound_insert_location(bound<T> const& b) : bound2(b) {
|
||||
}
|
||||
|
||||
bool operator()(bound_ptr<T> const& b) {
|
||||
auto const& bound1 = *b;
|
||||
if (values_are_equal(bound2.current_x, bound1.current_x)) {
|
||||
if (bound2.current_edge->top.y > bound1.current_edge->top.y) {
|
||||
return less_than(static_cast<double>(bound2.current_edge->top.x),
|
||||
get_current_x(*(bound1.current_edge), bound2.current_edge->top.y));
|
||||
} else {
|
||||
return greater_than(static_cast<double>(bound1.current_edge->top.x),
|
||||
get_current_x(*(bound2.current_edge), bound1.current_edge->top.y));
|
||||
}
|
||||
} else {
|
||||
return bound2.current_x < bound1.current_x;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
active_bound_list_itr<T> insert_bound_into_ABL(bound<T>& left, bound<T>& right, active_bound_list<T>& active_bounds) {
|
||||
|
||||
auto itr = std::find_if(active_bounds.begin(), active_bounds.end(), bound_insert_location<T>(left));
|
||||
#ifdef GCC_MISSING_VECTOR_RANGE_INSERT
|
||||
itr = active_bounds.insert(itr, &right);
|
||||
return active_bounds.insert(itr, &left);
|
||||
#else
|
||||
return active_bounds.insert(itr, { &left, &right });
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_maxima(bound<T> const& bnd, T y) {
|
||||
return bnd.next_edge == bnd.edges.end() && bnd.current_edge->top.y == y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_maxima(active_bound_list_itr<T> const& bnd, T y) {
|
||||
return is_maxima(*(*bnd), y);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_intermediate(bound<T> const& bnd, T y) {
|
||||
return bnd.next_edge != bnd.edges.end() && bnd.current_edge->top.y == y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_intermediate(active_bound_list_itr<T> const& bnd, T y) {
|
||||
return is_intermediate(*(*bnd), y);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool current_edge_is_horizontal(active_bound_list_itr<T> const& bnd) {
|
||||
return is_horizontal(*((*bnd)->current_edge));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool next_edge_is_horizontal(active_bound_list_itr<T> const& bnd) {
|
||||
return is_horizontal(*((*bnd)->next_edge));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void next_edge_in_bound(bound<T>& bnd, scanbeam_list<T>& scanbeam) {
|
||||
auto& current_edge = bnd.current_edge;
|
||||
++current_edge;
|
||||
if (current_edge != bnd.edges.end()) {
|
||||
++(bnd.next_edge);
|
||||
bnd.current_x = static_cast<double>(current_edge->bot.x);
|
||||
if (!is_horizontal<T>(*current_edge)) {
|
||||
insert_sorted_scanbeam(scanbeam, current_edge->top.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
active_bound_list_itr<T> get_maxima_pair(active_bound_list_itr<T> bnd, active_bound_list<T>& active_bounds) {
|
||||
bound_ptr<T> maximum = (*bnd)->maximum_bound;
|
||||
return std::find(active_bounds.begin(), active_bounds.end(), maximum);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void set_winding_count(active_bound_list_itr<T> bnd_itr,
|
||||
active_bound_list<T>& active_bounds,
|
||||
fill_type subject_fill_type,
|
||||
fill_type clip_fill_type) {
|
||||
|
||||
auto rev_bnd_itr = active_bound_list_rev_itr<T>(bnd_itr);
|
||||
if (rev_bnd_itr == active_bounds.rend()) {
|
||||
(*bnd_itr)->winding_count = (*bnd_itr)->winding_delta;
|
||||
(*bnd_itr)->winding_count2 = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// find the edge of the same polytype that immediately preceeds 'edge' in
|
||||
// AEL
|
||||
while (rev_bnd_itr != active_bounds.rend() && (*rev_bnd_itr)->poly_type != (*bnd_itr)->poly_type) {
|
||||
++rev_bnd_itr;
|
||||
}
|
||||
if (rev_bnd_itr == active_bounds.rend()) {
|
||||
(*bnd_itr)->winding_count = (*bnd_itr)->winding_delta;
|
||||
(*bnd_itr)->winding_count2 = 0;
|
||||
} else if (is_even_odd_fill_type(*(*bnd_itr), subject_fill_type, clip_fill_type)) {
|
||||
// EvenOdd filling ...
|
||||
(*bnd_itr)->winding_count = (*bnd_itr)->winding_delta;
|
||||
(*bnd_itr)->winding_count2 = (*rev_bnd_itr)->winding_count2;
|
||||
} else {
|
||||
// nonZero, Positive or Negative filling ...
|
||||
if ((*rev_bnd_itr)->winding_count * (*rev_bnd_itr)->winding_delta < 0) {
|
||||
// prev edge is 'decreasing' WindCount (WC) toward zero
|
||||
// so we're outside the previous polygon ...
|
||||
if (std::abs(static_cast<int>((*rev_bnd_itr)->winding_count)) > 1) {
|
||||
// outside prev poly but still inside another.
|
||||
// when reversing direction of prev poly use the same WC
|
||||
if ((*rev_bnd_itr)->winding_delta * (*bnd_itr)->winding_delta < 0) {
|
||||
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count;
|
||||
} else {
|
||||
// otherwise continue to 'decrease' WC ...
|
||||
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
|
||||
}
|
||||
} else {
|
||||
// now outside all polys of same polytype so set own WC ...
|
||||
(*bnd_itr)->winding_count = (*bnd_itr)->winding_delta;
|
||||
}
|
||||
} else {
|
||||
// prev edge is 'increasing' WindCount (WC) away from zero
|
||||
// so we're inside the previous polygon ...
|
||||
if ((*rev_bnd_itr)->winding_delta * (*bnd_itr)->winding_delta < 0) {
|
||||
// if wind direction is reversing prev then use same WC
|
||||
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count;
|
||||
} else {
|
||||
// otherwise add to WC ...
|
||||
(*bnd_itr)->winding_count = (*rev_bnd_itr)->winding_count + (*bnd_itr)->winding_delta;
|
||||
}
|
||||
}
|
||||
(*bnd_itr)->winding_count2 = (*rev_bnd_itr)->winding_count2;
|
||||
}
|
||||
|
||||
// update winding_count2 ...
|
||||
auto bnd_itr_forward = rev_bnd_itr.base();
|
||||
if (is_even_odd_alt_fill_type(*(*bnd_itr), subject_fill_type, clip_fill_type)) {
|
||||
// EvenOdd filling ...
|
||||
while (bnd_itr_forward != bnd_itr) {
|
||||
(*bnd_itr)->winding_count2 = ((*bnd_itr)->winding_count2 == 0 ? 1 : 0);
|
||||
++bnd_itr_forward;
|
||||
}
|
||||
} else {
|
||||
// nonZero, Positive or Negative filling ...
|
||||
while (bnd_itr_forward != bnd_itr) {
|
||||
(*bnd_itr)->winding_count2 += (*bnd_itr_forward)->winding_delta;
|
||||
++bnd_itr_forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool is_contributing(bound<T> const& bnd, clip_type cliptype, fill_type subject_fill_type, fill_type clip_fill_type) {
|
||||
fill_type pft = subject_fill_type;
|
||||
fill_type pft2 = clip_fill_type;
|
||||
if (bnd.poly_type != polygon_type_subject) {
|
||||
pft = clip_fill_type;
|
||||
pft2 = subject_fill_type;
|
||||
}
|
||||
|
||||
switch (pft) {
|
||||
case fill_type_even_odd:
|
||||
break;
|
||||
case fill_type_non_zero:
|
||||
if (std::abs(static_cast<int>(bnd.winding_count)) != 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case fill_type_positive:
|
||||
if (bnd.winding_count != 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case fill_type_negative:
|
||||
default:
|
||||
if (bnd.winding_count != -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (cliptype) {
|
||||
case clip_type_intersection:
|
||||
switch (pft2) {
|
||||
case fill_type_even_odd:
|
||||
case fill_type_non_zero:
|
||||
return (bnd.winding_count2 != 0);
|
||||
case fill_type_positive:
|
||||
return (bnd.winding_count2 > 0);
|
||||
case fill_type_negative:
|
||||
default:
|
||||
return (bnd.winding_count2 < 0);
|
||||
}
|
||||
break;
|
||||
case clip_type_union:
|
||||
switch (pft2) {
|
||||
case fill_type_even_odd:
|
||||
case fill_type_non_zero:
|
||||
return (bnd.winding_count2 == 0);
|
||||
case fill_type_positive:
|
||||
return (bnd.winding_count2 <= 0);
|
||||
case fill_type_negative:
|
||||
default:
|
||||
return (bnd.winding_count2 >= 0);
|
||||
}
|
||||
break;
|
||||
case clip_type_difference:
|
||||
if (bnd.poly_type == polygon_type_subject) {
|
||||
switch (pft2) {
|
||||
case fill_type_even_odd:
|
||||
case fill_type_non_zero:
|
||||
return (bnd.winding_count2 == 0);
|
||||
case fill_type_positive:
|
||||
return (bnd.winding_count2 <= 0);
|
||||
case fill_type_negative:
|
||||
default:
|
||||
return (bnd.winding_count2 >= 0);
|
||||
}
|
||||
} else {
|
||||
switch (pft2) {
|
||||
case fill_type_even_odd:
|
||||
case fill_type_non_zero:
|
||||
return (bnd.winding_count2 != 0);
|
||||
case fill_type_positive:
|
||||
return (bnd.winding_count2 > 0);
|
||||
case fill_type_negative:
|
||||
default:
|
||||
return (bnd.winding_count2 < 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case clip_type_x_or:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void insert_lm_left_and_right_bound(bound<T>& left_bound,
|
||||
bound<T>& right_bound,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& rings,
|
||||
scanbeam_list<T>& scanbeam,
|
||||
clip_type cliptype,
|
||||
fill_type subject_fill_type,
|
||||
fill_type clip_fill_type) {
|
||||
|
||||
// Both left and right bound
|
||||
auto lb_abl_itr = insert_bound_into_ABL(left_bound, right_bound, active_bounds);
|
||||
auto rb_abl_itr = std::next(lb_abl_itr);
|
||||
set_winding_count(lb_abl_itr, active_bounds, subject_fill_type, clip_fill_type);
|
||||
(*rb_abl_itr)->winding_count = (*lb_abl_itr)->winding_count;
|
||||
(*rb_abl_itr)->winding_count2 = (*lb_abl_itr)->winding_count2;
|
||||
if (is_contributing(left_bound, cliptype, subject_fill_type, clip_fill_type)) {
|
||||
add_local_minimum_point(*(*lb_abl_itr), *(*rb_abl_itr), active_bounds, (*lb_abl_itr)->current_edge->bot, rings);
|
||||
}
|
||||
|
||||
// Add top of edges to scanbeam
|
||||
insert_sorted_scanbeam(scanbeam, (*lb_abl_itr)->current_edge->top.y);
|
||||
|
||||
if (!current_edge_is_horizontal<T>(rb_abl_itr)) {
|
||||
insert_sorted_scanbeam(scanbeam, (*rb_abl_itr)->current_edge->top.y);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void insert_local_minima_into_ABL(T const bot_y,
|
||||
local_minimum_ptr_list<T> const& minima_sorted,
|
||||
local_minimum_ptr_list_itr<T>& current_lm,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& rings,
|
||||
scanbeam_list<T>& scanbeam,
|
||||
clip_type cliptype,
|
||||
fill_type subject_fill_type,
|
||||
fill_type clip_fill_type) {
|
||||
while (current_lm != minima_sorted.end() && bot_y == (*current_lm)->y) {
|
||||
initialize_lm<T>(current_lm);
|
||||
auto& left_bound = (*current_lm)->left_bound;
|
||||
auto& right_bound = (*current_lm)->right_bound;
|
||||
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam, cliptype,
|
||||
subject_fill_type, clip_fill_type);
|
||||
++current_lm;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void insert_horizontal_local_minima_into_ABL(T const top_y,
|
||||
local_minimum_ptr_list<T> const& minima_sorted,
|
||||
local_minimum_ptr_list_itr<T>& current_lm,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& rings,
|
||||
scanbeam_list<T>& scanbeam,
|
||||
clip_type cliptype,
|
||||
fill_type subject_fill_type,
|
||||
fill_type clip_fill_type) {
|
||||
while (current_lm != minima_sorted.end() && top_y == (*current_lm)->y && (*current_lm)->minimum_has_horizontal) {
|
||||
initialize_lm<T>(current_lm);
|
||||
auto& left_bound = (*current_lm)->left_bound;
|
||||
auto& right_bound = (*current_lm)->right_bound;
|
||||
insert_lm_left_and_right_bound(left_bound, right_bound, active_bounds, rings, scanbeam, cliptype,
|
||||
subject_fill_type, clip_fill_type);
|
||||
++current_lm;
|
||||
}
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,277 +0,0 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
|
||||
// This template class serves as a compile-time function from size to
|
||||
// type. It maps a size in bytes to a primitive type with that
|
||||
// size. e.g.
|
||||
//
|
||||
// TypeWithSize<4>::UInt
|
||||
//
|
||||
// is typedef-ed to be unsigned int (unsigned integer made up of 4
|
||||
// bytes).
|
||||
//
|
||||
// Such functionality should belong to STL, but I cannot find it
|
||||
// there.
|
||||
//
|
||||
// Google Test uses this class in the implementation of floating-point
|
||||
// comparison.
|
||||
//
|
||||
// For now it only handles UInt (unsigned int) as that's all Google Test
|
||||
// needs. Other types can be easily added in the future if need
|
||||
// arises.
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
namespace util {
|
||||
|
||||
template <size_t size>
|
||||
class TypeWithSize {
|
||||
public:
|
||||
// This prevents the user from using TypeWithSize<N> with incorrect
|
||||
// values of N.
|
||||
typedef void UInt;
|
||||
};
|
||||
|
||||
// The specialization for size 4.
|
||||
template <>
|
||||
class TypeWithSize<4> {
|
||||
public:
|
||||
// unsigned int has size 4 in both gcc and MSVC.
|
||||
//
|
||||
// As base/basictypes.h doesn't compile on Windows, we cannot use
|
||||
// uint32, uint64, and etc here.
|
||||
typedef int Int;
|
||||
typedef unsigned int UInt;
|
||||
};
|
||||
|
||||
// The specialization for size 8.
|
||||
template <>
|
||||
class TypeWithSize<8> {
|
||||
public:
|
||||
#if GTEST_OS_WINDOWS
|
||||
typedef __int64 Int;
|
||||
typedef unsigned __int64 UInt;
|
||||
#else
|
||||
typedef long long Int; // NOLINT
|
||||
typedef unsigned long long UInt; // NOLINT
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
};
|
||||
|
||||
// This template class represents an IEEE floating-point number
|
||||
// (either single-precision or double-precision, depending on the
|
||||
// template parameters).
|
||||
//
|
||||
// The purpose of this class is to do more sophisticated number
|
||||
// comparison. (Due to round-off error, etc, it's very unlikely that
|
||||
// two floating-points will be equal exactly. Hence a naive
|
||||
// comparison by the == operation often doesn't work.)
|
||||
//
|
||||
// Format of IEEE floating-point:
|
||||
//
|
||||
// The most-significant bit being the leftmost, an IEEE
|
||||
// floating-point looks like
|
||||
//
|
||||
// sign_bit exponent_bits fraction_bits
|
||||
//
|
||||
// Here, sign_bit is a single bit that designates the sign of the
|
||||
// number.
|
||||
//
|
||||
// For float, there are 8 exponent bits and 23 fraction bits.
|
||||
//
|
||||
// For double, there are 11 exponent bits and 52 fraction bits.
|
||||
//
|
||||
// More details can be found at
|
||||
// http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
|
||||
//
|
||||
// Template parameter:
|
||||
//
|
||||
// RawType: the raw floating-point type (either float or double)
|
||||
template <typename RawType>
|
||||
class FloatingPoint {
|
||||
public:
|
||||
// Defines the unsigned integer type that has the same size as the
|
||||
// floating point number.
|
||||
typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
|
||||
|
||||
// Constants.
|
||||
|
||||
// # of bits in a number.
|
||||
static const size_t kBitCount = 8 * sizeof(RawType);
|
||||
|
||||
// # of fraction bits in a number.
|
||||
static const size_t kFractionBitCount = std::numeric_limits<RawType>::digits - 1;
|
||||
|
||||
// # of exponent bits in a number.
|
||||
static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
|
||||
|
||||
// The mask for the sign bit.
|
||||
static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
|
||||
|
||||
// The mask for the fraction bits.
|
||||
static const Bits kFractionBitMask = ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
|
||||
|
||||
// The mask for the exponent bits.
|
||||
static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
|
||||
|
||||
// How many ULP's (Units in the Last Place) we want to tolerate when
|
||||
// comparing two numbers. The larger the value, the more error we
|
||||
// allow. A 0 value means that two numbers must be exactly the same
|
||||
// to be considered equal.
|
||||
//
|
||||
// The maximum error of a single floating-point operation is 0.5
|
||||
// units in the last place. On Intel CPU's, all floating-point
|
||||
// calculations are done with 80-bit precision, while double has 64
|
||||
// bits. Therefore, 4 should be enough for ordinary use.
|
||||
//
|
||||
// See the following article for more details on ULP:
|
||||
// http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm.
|
||||
static const size_t kMaxUlps = 4;
|
||||
|
||||
// Constructs a FloatingPoint from a raw floating-point number.
|
||||
//
|
||||
// On an Intel CPU, passing a non-normalized NAN (Not a Number)
|
||||
// around may change its bits, although the new value is guaranteed
|
||||
// to be also a NAN. Therefore, don't expect this constructor to
|
||||
// preserve the bits in x when x is a NAN.
|
||||
explicit FloatingPoint(const RawType& x) : u_(x) {
|
||||
}
|
||||
|
||||
// Static methods
|
||||
|
||||
// Reinterprets a bit pattern as a floating-point number.
|
||||
//
|
||||
// This function is needed to test the AlmostEquals() method.
|
||||
static RawType ReinterpretBits(const Bits bits) {
|
||||
FloatingPoint fp(0);
|
||||
fp.u_.bits_ = bits;
|
||||
return fp.u_.value_;
|
||||
}
|
||||
|
||||
// Returns the floating-point number that represent positive infinity.
|
||||
static RawType Infinity() {
|
||||
return ReinterpretBits(kExponentBitMask);
|
||||
}
|
||||
|
||||
// Non-static methods
|
||||
|
||||
// Returns the bits that represents this number.
|
||||
const Bits& bits() const {
|
||||
return u_.bits_;
|
||||
}
|
||||
|
||||
// Returns the exponent bits of this number.
|
||||
Bits exponent_bits() const {
|
||||
return kExponentBitMask & u_.bits_;
|
||||
}
|
||||
|
||||
// Returns the fraction bits of this number.
|
||||
Bits fraction_bits() const {
|
||||
return kFractionBitMask & u_.bits_;
|
||||
}
|
||||
|
||||
// Returns the sign bit of this number.
|
||||
Bits sign_bit() const {
|
||||
return kSignBitMask & u_.bits_;
|
||||
}
|
||||
|
||||
// Returns true iff this is NAN (not a number).
|
||||
bool is_nan() const {
|
||||
// It's a NAN if the exponent bits are all ones and the fraction
|
||||
// bits are not entirely zeros.
|
||||
return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
|
||||
}
|
||||
|
||||
// Returns true iff this number is at most kMaxUlps ULP's away from
|
||||
// rhs. In particular, this function:
|
||||
//
|
||||
// - returns false if either number is (or both are) NAN.
|
||||
// - treats really large numbers as almost equal to infinity.
|
||||
// - thinks +0.0 and -0.0 are 0 DLP's apart.
|
||||
bool AlmostEquals(const FloatingPoint& rhs) const {
|
||||
// The IEEE standard says that any comparison operation involving
|
||||
// a NAN must return false.
|
||||
if (is_nan() || rhs.is_nan())
|
||||
return false;
|
||||
|
||||
return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) <= kMaxUlps;
|
||||
}
|
||||
|
||||
private:
|
||||
// The data type used to store the actual floating-point number.
|
||||
union FloatingPointUnion {
|
||||
explicit FloatingPointUnion(RawType val) : value_(val) {
|
||||
}
|
||||
RawType value_; // The raw floating-point number.
|
||||
Bits bits_; // The bits that represent the number.
|
||||
};
|
||||
|
||||
// Converts an integer from the sign-and-magnitude representation to
|
||||
// the biased representation. More precisely, let N be 2 to the
|
||||
// power of (kBitCount - 1), an integer x is represented by the
|
||||
// unsigned number x + N.
|
||||
//
|
||||
// For instance,
|
||||
//
|
||||
// -N + 1 (the most negative number representable using
|
||||
// sign-and-magnitude) is represented by 1;
|
||||
// 0 is represented by N; and
|
||||
// N - 1 (the biggest number representable using
|
||||
// sign-and-magnitude) is represented by 2N - 1.
|
||||
//
|
||||
// Read http://en.wikipedia.org/wiki/Signed_number_representations
|
||||
// for more details on signed number representations.
|
||||
static Bits SignAndMagnitudeToBiased(const Bits& sam) {
|
||||
if (kSignBitMask & sam) {
|
||||
// sam represents a negative number.
|
||||
return ~sam + 1;
|
||||
} else {
|
||||
// sam represents a positive number.
|
||||
return kSignBitMask | sam;
|
||||
}
|
||||
}
|
||||
|
||||
// Given two numbers in the sign-and-magnitude representation,
|
||||
// returns the distance between them as an unsigned number.
|
||||
static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits& sam1, const Bits& sam2) {
|
||||
const Bits biased1 = SignAndMagnitudeToBiased(sam1);
|
||||
const Bits biased2 = SignAndMagnitudeToBiased(sam2);
|
||||
return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
|
||||
}
|
||||
|
||||
FloatingPointUnion u_;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename It, class Compare, class MethodOnSwap>
|
||||
void bubble_sort(It begin, It end, Compare c, MethodOnSwap m) {
|
||||
if (begin == end) {
|
||||
return;
|
||||
}
|
||||
bool modified = false;
|
||||
auto last = end - 1;
|
||||
do {
|
||||
modified = false;
|
||||
for (auto itr = begin; itr != last; ++itr) {
|
||||
auto next = std::next(itr);
|
||||
if (!c(*itr, *next)) {
|
||||
m(*itr, *next);
|
||||
std::iter_swap(itr, next);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
} while (modified);
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/wagyu/build_edges.hpp>
|
||||
#include <mapbox/geometry/wagyu/config.hpp>
|
||||
#include <mapbox/geometry/wagyu/local_minimum.hpp>
|
||||
#include <mapbox/geometry/wagyu/local_minimum_util.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
bool add_linear_ring(mapbox::geometry::linear_ring<T2> const& path_geometry,
|
||||
local_minimum_list<T1>& minima_list,
|
||||
polygon_type p_type) {
|
||||
edge_list<T1> new_edges;
|
||||
new_edges.reserve(path_geometry.size());
|
||||
if (!build_edge_list<T1, T2>(path_geometry, new_edges) || new_edges.empty()) {
|
||||
return false;
|
||||
}
|
||||
add_ring_to_local_minima_list(new_edges, minima_list, p_type);
|
||||
return true;
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,68 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/wagyu/ring.hpp>
|
||||
#include <mapbox/geometry/wagyu/ring_util.hpp>
|
||||
|
||||
#include <mapbox/geometry/multi_polygon.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void push_ring_to_polygon(mapbox::geometry::polygon<T2>& poly, ring_ptr<T1> r, bool reverse_output) {
|
||||
mapbox::geometry::linear_ring<T2> lr;
|
||||
lr.reserve(r->size() + 1);
|
||||
auto firstPt = r->points;
|
||||
auto ptIt = r->points;
|
||||
if (reverse_output) {
|
||||
do {
|
||||
lr.emplace_back(static_cast<T2>(ptIt->x), static_cast<T2>(ptIt->y));
|
||||
ptIt = ptIt->next;
|
||||
} while (ptIt != firstPt);
|
||||
} else {
|
||||
do {
|
||||
lr.emplace_back(static_cast<T2>(ptIt->x), static_cast<T2>(ptIt->y));
|
||||
ptIt = ptIt->prev;
|
||||
} while (ptIt != firstPt);
|
||||
}
|
||||
lr.emplace_back(firstPt->x, firstPt->y); // close the ring
|
||||
poly.push_back(lr);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void build_result_polygons(mapbox::geometry::multi_polygon<T2>& solution,
|
||||
ring_vector<T1> const& rings,
|
||||
bool reverse_output) {
|
||||
for (auto r : rings) {
|
||||
if (r == nullptr) {
|
||||
continue;
|
||||
}
|
||||
assert(r->points);
|
||||
solution.emplace_back();
|
||||
push_ring_to_polygon(solution.back(), r, reverse_output);
|
||||
for (auto c : r->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
assert(c->points);
|
||||
push_ring_to_polygon(solution.back(), c, reverse_output);
|
||||
}
|
||||
for (auto c : r->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (!c->children.empty()) {
|
||||
build_result_polygons(solution, c->children, reverse_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void build_result(mapbox::geometry::multi_polygon<T2>& solution, ring_manager<T1> const& rings, bool reverse_output) {
|
||||
build_result_polygons(solution, rings.children, reverse_output);
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* To enable this by the program, define USE_WAGYU_INTERRUPT before including wagyu.hpp
|
||||
* To request an interruption, call `interrupt_request()`. As soon as Wagyu detects the request
|
||||
* it will raise an exception (`std::runtime_error`).
|
||||
*/
|
||||
|
||||
#ifdef USE_WAGYU_INTERRUPT
|
||||
|
||||
namespace {
|
||||
thread_local bool WAGYU_INTERRUPT_REQUESTED = false;
|
||||
}
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
static void interrupt_reset(void) {
|
||||
WAGYU_INTERRUPT_REQUESTED = false;
|
||||
}
|
||||
|
||||
static void interrupt_request(void) {
|
||||
WAGYU_INTERRUPT_REQUESTED = true;
|
||||
}
|
||||
|
||||
static void interrupt_check(void) {
|
||||
if (WAGYU_INTERRUPT_REQUESTED) {
|
||||
interrupt_reset();
|
||||
throw std::runtime_error("Wagyu interrupted");
|
||||
}
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
||||
|
||||
#else /* ! USE_WAGYU_INTERRUPT */
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
static void interrupt_check(void) {
|
||||
}
|
||||
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
||||
|
||||
#endif /* USE_WAGYU_INTERRUPT */
|
@ -1,139 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/box.hpp>
|
||||
#include <mapbox/geometry/multi_polygon.hpp>
|
||||
#include <mapbox/geometry/polygon.hpp>
|
||||
#include <mapbox/geometry/wagyu/wagyu.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
namespace quick_clip {
|
||||
|
||||
template <typename T>
|
||||
mapbox::geometry::point<T> intersect(mapbox::geometry::point<T> a,
|
||||
mapbox::geometry::point<T> b,
|
||||
size_t edge,
|
||||
mapbox::geometry::box<T> const& box) {
|
||||
switch (edge) {
|
||||
case 0:
|
||||
return mapbox::geometry::point<T>(
|
||||
mapbox::geometry::wagyu::wround<T>(static_cast<double>(a.x) + static_cast<double>(b.x - a.x) *
|
||||
static_cast<double>(box.min.y - a.y) /
|
||||
static_cast<double>(b.y - a.y)),
|
||||
box.min.y);
|
||||
|
||||
case 1:
|
||||
return mapbox::geometry::point<T>(
|
||||
box.max.x,
|
||||
mapbox::geometry::wagyu::wround<T>(static_cast<double>(a.y) + static_cast<double>(b.y - a.y) *
|
||||
static_cast<double>(box.max.x - a.x) /
|
||||
static_cast<double>(b.x - a.x)));
|
||||
|
||||
case 2:
|
||||
return mapbox::geometry::point<T>(
|
||||
mapbox::geometry::wagyu::wround<T>(static_cast<double>(a.x) + static_cast<double>(b.x - a.x) *
|
||||
static_cast<double>(box.max.y - a.y) /
|
||||
static_cast<double>(b.y - a.y)),
|
||||
box.max.y);
|
||||
|
||||
default: // case 3
|
||||
return mapbox::geometry::point<T>(
|
||||
box.min.x,
|
||||
mapbox::geometry::wagyu::wround<T>(static_cast<double>(a.y) + static_cast<double>(b.y - a.y) *
|
||||
static_cast<double>(box.min.x - a.x) /
|
||||
static_cast<double>(b.x - a.x)));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool inside(mapbox::geometry::point<T> p, size_t edge, mapbox::geometry::box<T> const& b) {
|
||||
switch (edge) {
|
||||
case 0:
|
||||
return p.y > b.min.y;
|
||||
|
||||
case 1:
|
||||
return p.x < b.max.x;
|
||||
|
||||
case 2:
|
||||
return p.y < b.max.y;
|
||||
|
||||
default: // case 3
|
||||
return p.x > b.min.x;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
mapbox::geometry::linear_ring<T> quick_lr_clip(mapbox::geometry::linear_ring<T> const& ring,
|
||||
mapbox::geometry::box<T> const& b) {
|
||||
mapbox::geometry::linear_ring<T> out = ring;
|
||||
|
||||
for (size_t edge = 0; edge < 4; edge++) {
|
||||
if (out.size() > 0) {
|
||||
mapbox::geometry::linear_ring<T> in = out;
|
||||
mapbox::geometry::point<T> S = in[in.size() - 1];
|
||||
out.resize(0);
|
||||
|
||||
for (size_t e = 0; e < in.size(); e++) {
|
||||
mapbox::geometry::point<T> E = in[e];
|
||||
|
||||
if (inside(E, edge, b)) {
|
||||
if (!inside(S, edge, b)) {
|
||||
out.push_back(intersect(S, E, edge, b));
|
||||
}
|
||||
out.push_back(E);
|
||||
} else if (inside(S, edge, b)) {
|
||||
out.push_back(intersect(S, E, edge, b));
|
||||
}
|
||||
|
||||
S = E;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (out.size() < 3) {
|
||||
out.clear();
|
||||
return out;
|
||||
}
|
||||
// Close the ring if the first/last point was outside
|
||||
if (out[0] != out[out.size() - 1]) {
|
||||
out.push_back(out[0]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // namespace quick_clip
|
||||
|
||||
template <typename T>
|
||||
mapbox::geometry::multi_polygon<T>
|
||||
clip(mapbox::geometry::polygon<T> const& poly, mapbox::geometry::box<T> const& b, fill_type subject_fill_type) {
|
||||
mapbox::geometry::multi_polygon<T> result;
|
||||
wagyu<T> clipper;
|
||||
for (auto const& lr : poly) {
|
||||
auto new_lr = quick_clip::quick_lr_clip(lr, b);
|
||||
if (!new_lr.empty()) {
|
||||
clipper.add_ring(new_lr, polygon_type_subject);
|
||||
}
|
||||
}
|
||||
clipper.execute(clip_type_union, result, subject_fill_type, fill_type_even_odd);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
mapbox::geometry::multi_polygon<T>
|
||||
clip(mapbox::geometry::multi_polygon<T> const& mp, mapbox::geometry::box<T> const& b, fill_type subject_fill_type) {
|
||||
mapbox::geometry::multi_polygon<T> result;
|
||||
wagyu<T> clipper;
|
||||
for (auto const& poly : mp) {
|
||||
for (auto const& lr : poly) {
|
||||
auto new_lr = quick_clip::quick_lr_clip(lr, b);
|
||||
if (!new_lr.empty()) {
|
||||
clipper.add_ring(new_lr, polygon_type_subject);
|
||||
}
|
||||
}
|
||||
}
|
||||
clipper.execute(clip_type_union, result, subject_fill_type, fill_type_even_odd);
|
||||
return result;
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,633 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mapbox/geometry/box.hpp>
|
||||
#include <mapbox/geometry/wagyu/point.hpp>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <execinfo.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
//
|
||||
// void* callstack[128];
|
||||
// int i, frames = backtrace(callstack, 128);
|
||||
// char** strs = backtrace_symbols(callstack, frames);
|
||||
// for (i = 0; i < frames; ++i) {
|
||||
// printf("%s\n", strs[i]);
|
||||
// }
|
||||
// free(strs);
|
||||
#endif
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T>
|
||||
double area_from_point(point_ptr<T> op, std::size_t& size, mapbox::geometry::box<T>& bbox) {
|
||||
point_ptr<T> startOp = op;
|
||||
size = 0;
|
||||
double a = 0.0;
|
||||
T min_x = op->x;
|
||||
T max_x = op->x;
|
||||
T min_y = op->y;
|
||||
T max_y = op->y;
|
||||
do {
|
||||
++size;
|
||||
if (op->x > max_x) {
|
||||
max_x = op->x;
|
||||
} else if (op->x < min_x) {
|
||||
min_x = op->x;
|
||||
}
|
||||
if (op->y > max_y) {
|
||||
max_y = op->y;
|
||||
} else if (op->y < min_y) {
|
||||
min_y = op->y;
|
||||
}
|
||||
a += static_cast<double>(op->prev->x + op->x) * static_cast<double>(op->prev->y - op->y);
|
||||
op = op->next;
|
||||
} while (op != startOp);
|
||||
bbox.min.x = min_x;
|
||||
bbox.max.x = max_x;
|
||||
bbox.min.y = min_y;
|
||||
bbox.max.y = max_y;
|
||||
return a * 0.5;
|
||||
}
|
||||
|
||||
// NOTE: ring and ring_ptr are forward declared in wagyu/point.hpp
|
||||
|
||||
template <typename T>
|
||||
using ring_vector = std::vector<ring_ptr<T>>;
|
||||
|
||||
template <typename T>
|
||||
struct ring {
|
||||
std::size_t ring_index; // To support unset 0 is undefined and indexes offset by 1
|
||||
|
||||
std::size_t size_; // number of points in the ring
|
||||
double area_; // area of the ring
|
||||
mapbox::geometry::box<T> bbox; // bounding box of the ring
|
||||
|
||||
ring_ptr<T> parent;
|
||||
ring_vector<T> children;
|
||||
|
||||
point_ptr<T> points;
|
||||
point_ptr<T> bottom_point;
|
||||
bool is_hole_;
|
||||
bool corrected;
|
||||
|
||||
ring(ring const&) = delete;
|
||||
ring& operator=(ring const&) = delete;
|
||||
|
||||
ring()
|
||||
: ring_index(0),
|
||||
size_(0),
|
||||
area_(std::numeric_limits<double>::quiet_NaN()),
|
||||
bbox({ 0, 0 }, { 0, 0 }),
|
||||
parent(nullptr),
|
||||
children(),
|
||||
points(nullptr),
|
||||
bottom_point(nullptr),
|
||||
is_hole_(false),
|
||||
corrected(false) {
|
||||
}
|
||||
|
||||
void reset_stats() {
|
||||
area_ = std::numeric_limits<double>::quiet_NaN();
|
||||
is_hole_ = false;
|
||||
bbox.min.x = 0;
|
||||
bbox.min.y = 0;
|
||||
bbox.max.x = 0;
|
||||
bbox.max.y = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void recalculate_stats() {
|
||||
if (points != nullptr) {
|
||||
area_ = area_from_point(points, size_, bbox);
|
||||
is_hole_ = !(area_ > 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void set_stats(double a, std::size_t s, mapbox::geometry::box<T> const& b) {
|
||||
bbox = b;
|
||||
area_ = a;
|
||||
size_ = s;
|
||||
is_hole_ = !(area_ > 0.0);
|
||||
}
|
||||
|
||||
double area() {
|
||||
if (std::isnan(area_)) {
|
||||
recalculate_stats();
|
||||
}
|
||||
return area_;
|
||||
}
|
||||
|
||||
bool is_hole() {
|
||||
if (std::isnan(area_)) {
|
||||
recalculate_stats();
|
||||
}
|
||||
return is_hole_;
|
||||
}
|
||||
|
||||
std::size_t size() {
|
||||
if (std::isnan(area_)) {
|
||||
recalculate_stats();
|
||||
}
|
||||
return size_;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using hot_pixel_vector = std::vector<mapbox::geometry::point<T>>;
|
||||
|
||||
template <typename T>
|
||||
using hot_pixel_itr = typename hot_pixel_vector<T>::iterator;
|
||||
|
||||
template <typename T>
|
||||
using hot_pixel_rev_itr = typename hot_pixel_vector<T>::reverse_iterator;
|
||||
|
||||
template <typename T>
|
||||
struct ring_manager {
|
||||
|
||||
ring_vector<T> children;
|
||||
point_vector<T> all_points;
|
||||
hot_pixel_vector<T> hot_pixels;
|
||||
hot_pixel_itr<T> current_hp_itr;
|
||||
std::deque<point<T>> points;
|
||||
std::deque<ring<T>> rings;
|
||||
std::vector<point<T>> storage;
|
||||
std::size_t index;
|
||||
|
||||
ring_manager(ring_manager const&) = delete;
|
||||
ring_manager& operator=(ring_manager const&) = delete;
|
||||
|
||||
ring_manager()
|
||||
: children(),
|
||||
all_points(),
|
||||
hot_pixels(),
|
||||
current_hp_itr(hot_pixels.end()),
|
||||
points(),
|
||||
rings(),
|
||||
storage(),
|
||||
index(0) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void preallocate_point_memory(ring_manager<T>& rings, std::size_t size) {
|
||||
rings.storage.reserve(size);
|
||||
rings.all_points.reserve(size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ring_ptr<T> create_new_ring(ring_manager<T>& manager) {
|
||||
manager.rings.emplace_back();
|
||||
ring_ptr<T> result = &manager.rings.back();
|
||||
result->ring_index = manager.index++;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
point_ptr<T> create_new_point(ring_ptr<T> r, mapbox::geometry::point<T> const& pt, ring_manager<T>& rings) {
|
||||
point_ptr<T> point;
|
||||
if (rings.storage.size() < rings.storage.capacity()) {
|
||||
rings.storage.emplace_back(r, pt);
|
||||
point = &rings.storage.back();
|
||||
} else {
|
||||
rings.points.emplace_back(r, pt);
|
||||
point = &rings.points.back();
|
||||
}
|
||||
rings.all_points.push_back(point);
|
||||
return point;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
point_ptr<T> create_new_point(ring_ptr<T> r,
|
||||
mapbox::geometry::point<T> const& pt,
|
||||
point_ptr<T> before_this_point,
|
||||
ring_manager<T>& rings) {
|
||||
point_ptr<T> point;
|
||||
if (rings.storage.size() < rings.storage.capacity()) {
|
||||
rings.storage.emplace_back(r, pt, before_this_point);
|
||||
point = &rings.storage.back();
|
||||
} else {
|
||||
rings.points.emplace_back(r, pt, before_this_point);
|
||||
point = &rings.points.back();
|
||||
}
|
||||
rings.all_points.push_back(point);
|
||||
return point;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void set_to_children(ring_ptr<T> r, ring_vector<T>& children) {
|
||||
for (auto& c : children) {
|
||||
if (c == nullptr) {
|
||||
c = r;
|
||||
return;
|
||||
}
|
||||
}
|
||||
children.push_back(r);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void remove_from_children(ring_ptr<T> r, ring_vector<T>& children) {
|
||||
for (auto& c : children) {
|
||||
if (c == r) {
|
||||
c = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void assign_as_child(ring_ptr<T> new_ring, ring_ptr<T> parent, ring_manager<T>& manager) {
|
||||
// Assigning as a child assumes that this is
|
||||
// a brand new ring. Therefore it does
|
||||
// not have any existing relationships
|
||||
if ((parent == nullptr && new_ring->is_hole()) || (parent != nullptr && new_ring->is_hole() == parent->is_hole())) {
|
||||
throw std::runtime_error("Trying to assign a child that is the same orientation as the parent");
|
||||
}
|
||||
auto& children = parent == nullptr ? manager.children : parent->children;
|
||||
set_to_children(new_ring, children);
|
||||
new_ring->parent = parent;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void reassign_as_child(ring_ptr<T> ring, ring_ptr<T> parent, ring_manager<T>& manager) {
|
||||
// Reassigning a ring assumes it already
|
||||
// has an existing parent
|
||||
if ((parent == nullptr && ring->is_hole()) || (parent != nullptr && ring->is_hole() == parent->is_hole())) {
|
||||
throw std::runtime_error("Trying to re-assign a child that is the same orientation as the parent");
|
||||
}
|
||||
|
||||
// Remove the old child relationship
|
||||
auto& old_children = ring->parent == nullptr ? manager.children : ring->parent->children;
|
||||
remove_from_children(ring, old_children);
|
||||
|
||||
// Add new child relationship
|
||||
auto& children = parent == nullptr ? manager.children : parent->children;
|
||||
set_to_children(ring, children);
|
||||
ring->parent = parent;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void assign_as_sibling(ring_ptr<T> new_ring, ring_ptr<T> sibling, ring_manager<T>& manager) {
|
||||
// Assigning as a sibling assumes that this is
|
||||
// a brand new ring. Therefore it does
|
||||
// not have any existing relationships
|
||||
if (new_ring->is_hole() != sibling->is_hole()) {
|
||||
throw std::runtime_error("Trying to assign to be a sibling that is not the same orientation as the sibling");
|
||||
}
|
||||
auto& children = sibling->parent == nullptr ? manager.children : sibling->parent->children;
|
||||
set_to_children(new_ring, children);
|
||||
new_ring->parent = sibling->parent;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void reassign_as_sibling(ring_ptr<T> ring, ring_ptr<T> sibling, ring_manager<T>& manager) {
|
||||
if (ring->parent == sibling->parent) {
|
||||
return;
|
||||
}
|
||||
// Assigning as a sibling assumes that this is
|
||||
// a brand new ring. Therefore it does
|
||||
// not have any existing relationships
|
||||
if (ring->is_hole() != sibling->is_hole()) {
|
||||
throw std::runtime_error("Trying to assign to be a sibling that is not the same orientation as the sibling");
|
||||
}
|
||||
// Remove the old child relationship
|
||||
auto& old_children = ring->parent == nullptr ? manager.children : ring->parent->children;
|
||||
remove_from_children(ring, old_children);
|
||||
// Add new relationship
|
||||
auto& children = sibling->parent == nullptr ? manager.children : sibling->parent->children;
|
||||
set_to_children(ring, children);
|
||||
ring->parent = sibling->parent;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ring1_replaces_ring2(ring_ptr<T> ring1, ring_ptr<T> ring2, ring_manager<T>& manager) {
|
||||
assert(ring1 != ring2);
|
||||
auto& ring1_children = ring1 == nullptr ? manager.children : ring1->children;
|
||||
for (auto& c : ring2->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
c->parent = ring1;
|
||||
set_to_children(c, ring1_children);
|
||||
c = nullptr;
|
||||
}
|
||||
// Remove the old child relationship
|
||||
auto& old_children = ring2->parent == nullptr ? manager.children : ring2->parent->children;
|
||||
remove_from_children(ring2, old_children);
|
||||
ring2->points = nullptr;
|
||||
ring2->reset_stats();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void remove_points(point_ptr<T> pt) {
|
||||
if (pt != nullptr) {
|
||||
pt->prev->next = nullptr;
|
||||
while (pt != nullptr) {
|
||||
point_ptr<T> tmp = pt;
|
||||
pt = pt->next;
|
||||
tmp->next = nullptr;
|
||||
tmp->prev = nullptr;
|
||||
tmp->ring = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void remove_ring_and_points(ring_ptr<T> r,
|
||||
ring_manager<T>& manager,
|
||||
bool remove_children = true,
|
||||
bool remove_from_parent = true) {
|
||||
// Removes a ring and any children that might be
|
||||
// under that ring.
|
||||
for (auto& c : r->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (remove_children) {
|
||||
remove_ring_and_points(c, manager, true, false);
|
||||
}
|
||||
c = nullptr;
|
||||
}
|
||||
if (remove_from_parent) {
|
||||
// Remove the old child relationship
|
||||
auto& old_children = r->parent == nullptr ? manager.children : r->parent->children;
|
||||
remove_from_children(r, old_children);
|
||||
}
|
||||
point_ptr<T> pt = r->points;
|
||||
if (pt != nullptr) {
|
||||
pt->prev->next = nullptr;
|
||||
while (pt != nullptr) {
|
||||
point_ptr<T> tmp = pt;
|
||||
pt = pt->next;
|
||||
tmp->next = nullptr;
|
||||
tmp->prev = nullptr;
|
||||
tmp->ring = nullptr;
|
||||
}
|
||||
}
|
||||
r->points = nullptr;
|
||||
r->reset_stats();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void remove_ring(ring_ptr<T> r, ring_manager<T>& manager, bool remove_children = true, bool remove_from_parent = true) {
|
||||
// Removes a ring and any children that might be
|
||||
// under that ring.
|
||||
for (auto& c : r->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (remove_children) {
|
||||
remove_ring(c, manager, true, false);
|
||||
}
|
||||
c = nullptr;
|
||||
}
|
||||
if (remove_from_parent) {
|
||||
// Remove the old child relationship
|
||||
auto& old_children = r->parent == nullptr ? manager.children : r->parent->children;
|
||||
remove_from_children(r, old_children);
|
||||
}
|
||||
r->points = nullptr;
|
||||
r->reset_stats();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::size_t ring_depth(ring_ptr<T> r) {
|
||||
std::size_t depth = 0;
|
||||
if (!r) {
|
||||
return depth;
|
||||
}
|
||||
while (r->parent) {
|
||||
depth++;
|
||||
r = r->parent;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool ring_is_hole(ring_ptr<T> r) {
|
||||
// This is different then the "normal" way of determing if
|
||||
// a ring is a hole or not because it uses the depth of the
|
||||
// the ring to determine if it is a hole or not. This is only done
|
||||
// intially when rings are output from Vatti.
|
||||
return ring_depth(r) & 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void set_next(const_point_ptr<T>& node, const const_point_ptr<T>& next_node) {
|
||||
node->next = next_node;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
point_ptr<T> get_next(const_point_ptr<T>& node) {
|
||||
return node->next;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
point_ptr<T> get_prev(const_point_ptr<T>& node) {
|
||||
return node->prev;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void set_prev(const_point_ptr<T>& node, const const_point_ptr<T>& prev_node) {
|
||||
node->prev = prev_node;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void init(const_point_ptr<T>& node) {
|
||||
set_next(node, node);
|
||||
set_prev(node, node);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void link_before(point_ptr<T>& node, point_ptr<T>& new_node) {
|
||||
point_ptr<T> prev_node = get_prev(node);
|
||||
set_prev(new_node, prev_node);
|
||||
set_next(new_node, node);
|
||||
set_prev(node, new_node);
|
||||
set_next(prev_node, new_node);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void link_after(point_ptr<T>& node, point_ptr<T>& new_node) {
|
||||
point_ptr<T> next_node = get_next(node);
|
||||
set_prev(new_node, node);
|
||||
set_next(new_node, next_node);
|
||||
set_next(node, new_node);
|
||||
set_prev(next_node, new_node);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void transfer_point(point_ptr<T>& p, point_ptr<T>& b, point_ptr<T>& e) {
|
||||
if (b != e) {
|
||||
point_ptr<T> prev_p = get_prev(p);
|
||||
point_ptr<T> prev_b = get_prev(b);
|
||||
point_ptr<T> prev_e = get_prev(e);
|
||||
set_next(prev_e, p);
|
||||
set_prev(p, prev_e);
|
||||
set_next(prev_b, e);
|
||||
set_prev(e, prev_b);
|
||||
set_next(prev_p, b);
|
||||
set_prev(b, prev_p);
|
||||
} else {
|
||||
link_before(p, b);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void reverse_ring(point_ptr<T> pp) {
|
||||
if (!pp) {
|
||||
return;
|
||||
}
|
||||
point_ptr<T> pp1;
|
||||
point_ptr<T> pp2;
|
||||
pp1 = pp;
|
||||
do {
|
||||
pp2 = pp1->next;
|
||||
pp1->next = pp1->prev;
|
||||
pp1->prev = pp2;
|
||||
pp1 = pp2;
|
||||
} while (pp1 != pp);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
template <class charT, class traits, typename T>
|
||||
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, ring<T>& r) {
|
||||
out << " ring_index: " << r.ring_index << std::endl;
|
||||
if (!r.parent) {
|
||||
// out << " parent_ring ptr: nullptr" << std::endl;
|
||||
out << " parent_index: -----" << std::endl;
|
||||
} else {
|
||||
// out << " parent_ring ptr: " << r.parent << std::endl;
|
||||
out << " parent_ring idx: " << r.parent->ring_index << std::endl;
|
||||
}
|
||||
ring_ptr<T> n = const_cast<ring_ptr<T>>(&r);
|
||||
if (ring_is_hole(n)) {
|
||||
out << " is_hole: true " << std::endl;
|
||||
} else {
|
||||
out << " is_hole: false " << std::endl;
|
||||
}
|
||||
auto pt_itr = r.points;
|
||||
if (pt_itr) {
|
||||
out << " area: " << r.area() << std::endl;
|
||||
out << " points:" << std::endl;
|
||||
out << " [[[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
while (pt_itr != r.points) {
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
}
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "]]]" << std::endl;
|
||||
} else {
|
||||
out << " area: NONE" << std::endl;
|
||||
out << " points: NONE" << std::endl;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string debug_ring_addresses(ring_ptr<T> r) {
|
||||
std::ostringstream out;
|
||||
out << "Ring: " << r->ring_index << std::endl;
|
||||
if (r->points == nullptr) {
|
||||
out << " Ring has no points" << std::endl;
|
||||
return out.str();
|
||||
}
|
||||
auto pt_itr = r->points;
|
||||
do {
|
||||
out << " [" << pt_itr->x << "," << pt_itr->y << "] - " << pt_itr << std::endl;
|
||||
pt_itr = pt_itr->next;
|
||||
} while (pt_itr != r->points);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string output_as_polygon(ring_ptr<T> r) {
|
||||
std::ostringstream out;
|
||||
|
||||
auto pt_itr = r->points;
|
||||
if (pt_itr) {
|
||||
out << "[";
|
||||
out << "[[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
while (pt_itr != r->points) {
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
}
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "]]";
|
||||
for (auto const& c : r->children) {
|
||||
if (c == nullptr) {
|
||||
continue;
|
||||
}
|
||||
pt_itr = c->points;
|
||||
if (pt_itr) {
|
||||
out << ",[[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
while (pt_itr != c->points) {
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "],";
|
||||
pt_itr = pt_itr->next;
|
||||
}
|
||||
out << "[" << pt_itr->x << "," << pt_itr->y << "]]";
|
||||
}
|
||||
}
|
||||
out << "]" << std::endl;
|
||||
} else {
|
||||
out << "[]" << std::endl;
|
||||
}
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
template <class charT, class traits, typename T>
|
||||
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out, ring_vector<T>& rings) {
|
||||
out << "START RING VECTOR" << std::endl;
|
||||
for (auto& r : rings) {
|
||||
if (r == nullptr || !r->points) {
|
||||
continue;
|
||||
}
|
||||
out << " ring: " << r->ring_index << " - " << r << std::endl;
|
||||
out << *r;
|
||||
}
|
||||
out << "END RING VECTOR" << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
template <class charT, class traits, typename T>
|
||||
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
|
||||
std::deque<ring<T>>& rings) {
|
||||
out << "START RING VECTOR" << std::endl;
|
||||
for (auto& r : rings) {
|
||||
if (!r.points) {
|
||||
continue;
|
||||
}
|
||||
out << " ring: " << r.ring_index << std::endl;
|
||||
out << r;
|
||||
}
|
||||
out << "END RING VECTOR" << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
template <class charT, class traits, typename T>
|
||||
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
|
||||
hot_pixel_vector<T>& hp_vec) {
|
||||
out << "Hot Pixels: " << std::endl;
|
||||
for (auto& hp : hp_vec) {
|
||||
out << hp << std::endl;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/wagyu/config.hpp>
|
||||
#include <mapbox/geometry/wagyu/local_minimum.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T>
|
||||
using scanbeam_list = std::vector<T>;
|
||||
|
||||
template <typename T>
|
||||
void insert_sorted_scanbeam(scanbeam_list<T>& scanbeam, T& t) {
|
||||
typename scanbeam_list<T>::iterator i = std::lower_bound(scanbeam.begin(), scanbeam.end(), t);
|
||||
if (i == scanbeam.end() || t < *i) {
|
||||
scanbeam.insert(i, t);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool pop_from_scanbeam(T& Y, scanbeam_list<T>& scanbeam) {
|
||||
if (scanbeam.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Y = scanbeam.back();
|
||||
scanbeam.pop_back();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void setup_scanbeam(local_minimum_list<T>& minima_list, scanbeam_list<T>& scanbeam) {
|
||||
|
||||
scanbeam.reserve(minima_list.size());
|
||||
for (auto lm = minima_list.begin(); lm != minima_list.end(); ++lm) {
|
||||
scanbeam.push_back(lm->y);
|
||||
}
|
||||
std::sort(scanbeam.begin(), scanbeam.end());
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
@ -1,191 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/wagyu/active_bound_list.hpp>
|
||||
#include <mapbox/geometry/wagyu/bound.hpp>
|
||||
#include <mapbox/geometry/wagyu/bubble_sort.hpp>
|
||||
#include <mapbox/geometry/wagyu/config.hpp>
|
||||
#include <mapbox/geometry/wagyu/edge.hpp>
|
||||
#include <mapbox/geometry/wagyu/intersect.hpp>
|
||||
#include <mapbox/geometry/wagyu/intersect_util.hpp>
|
||||
#include <mapbox/geometry/wagyu/ring.hpp>
|
||||
#include <mapbox/geometry/wagyu/ring_util.hpp>
|
||||
#include <mapbox/geometry/wagyu/util.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geometry {
|
||||
namespace wagyu {
|
||||
|
||||
template <typename T>
|
||||
struct hp_intersection_swap {
|
||||
|
||||
ring_manager<T>& manager;
|
||||
|
||||
hp_intersection_swap(ring_manager<T>& m) : manager(m) {
|
||||
}
|
||||
|
||||
void operator()(bound_ptr<T> const& b1, bound_ptr<T> const& b2) {
|
||||
mapbox::geometry::point<double> pt;
|
||||
if (!get_edge_intersection<T, double>(*(b1->current_edge), *(b2->current_edge), pt)) {
|
||||
// LCOV_EXCL_START
|
||||
throw std::runtime_error("Trying to find intersection of lines that do not intersect");
|
||||
// LCOV_EXCL_END
|
||||
}
|
||||
add_to_hot_pixels(round_point<T>(pt), manager);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void process_hot_pixel_intersections(T top_y, active_bound_list<T>& active_bounds, ring_manager<T>& manager) {
|
||||
if (active_bounds.empty()) {
|
||||
return;
|
||||
}
|
||||
update_current_x(active_bounds, top_y);
|
||||
bubble_sort(active_bounds.begin(), active_bounds.end(), intersection_compare<T>(),
|
||||
hp_intersection_swap<T>(manager));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool horizontals_at_top_scanbeam(T top_y,
|
||||
active_bound_list_itr<T>& bnd_curr,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& manager) {
|
||||
bool shifted = false;
|
||||
auto& current_edge = (*bnd_curr)->current_edge;
|
||||
(*bnd_curr)->current_x = static_cast<double>(current_edge->top.x);
|
||||
if (current_edge->bot.x < current_edge->top.x) {
|
||||
// left to right
|
||||
auto bnd_next = std::next(bnd_curr);
|
||||
while (bnd_next != active_bounds.end() &&
|
||||
(*bnd_next == nullptr || (*bnd_next)->current_x < (*bnd_curr)->current_x)) {
|
||||
if (*bnd_next != nullptr && (*bnd_next)->current_edge->top.y != top_y &&
|
||||
(*bnd_next)->current_edge->bot.y != top_y) {
|
||||
mapbox::geometry::point<T> pt(wround<T>((*bnd_next)->current_x), top_y);
|
||||
add_to_hot_pixels(pt, manager);
|
||||
}
|
||||
std::iter_swap(bnd_curr, bnd_next);
|
||||
++bnd_curr;
|
||||
++bnd_next;
|
||||
shifted = true;
|
||||
}
|
||||
} else {
|
||||
// right to left
|
||||
if (bnd_curr != active_bounds.begin()) {
|
||||
auto bnd_prev = std::prev(bnd_curr);
|
||||
while (bnd_curr != active_bounds.begin() &&
|
||||
(*bnd_prev == nullptr || (*bnd_prev)->current_x > (*bnd_curr)->current_x)) {
|
||||
if (*bnd_prev != nullptr && (*bnd_prev)->current_edge->top.y != top_y &&
|
||||
(*bnd_prev)->current_edge->bot.y != top_y) {
|
||||
mapbox::geometry::point<T> pt(wround<T>((*bnd_prev)->current_x), top_y);
|
||||
add_to_hot_pixels(pt, manager);
|
||||
}
|
||||
std::iter_swap(bnd_curr, bnd_prev);
|
||||
--bnd_curr;
|
||||
if (bnd_curr != active_bounds.begin()) {
|
||||
--bnd_prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return shifted;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void process_hot_pixel_edges_at_top_of_scanbeam(T top_y,
|
||||
scanbeam_list<T>& scanbeam,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& manager) {
|
||||
for (auto bnd = active_bounds.begin(); bnd != active_bounds.end();) {
|
||||
if (*bnd == nullptr) {
|
||||
++bnd;
|
||||
continue;
|
||||
}
|
||||
bound<T>& current_bound = *(*bnd);
|
||||
auto bnd_curr = bnd;
|
||||
bool shifted = false;
|
||||
auto& current_edge = current_bound.current_edge;
|
||||
while (current_edge != current_bound.edges.end() && current_edge->top.y == top_y) {
|
||||
add_to_hot_pixels(current_edge->top, manager);
|
||||
if (is_horizontal(*current_edge)) {
|
||||
if (horizontals_at_top_scanbeam(top_y, bnd_curr, active_bounds, manager)) {
|
||||
shifted = true;
|
||||
}
|
||||
}
|
||||
next_edge_in_bound(current_bound, scanbeam);
|
||||
}
|
||||
if (current_edge == current_bound.edges.end()) {
|
||||
*bnd_curr = nullptr;
|
||||
}
|
||||
if (!shifted) {
|
||||
++bnd;
|
||||
}
|
||||
}
|
||||
active_bounds.erase(std::remove(active_bounds.begin(), active_bounds.end(), nullptr), active_bounds.end());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void insert_local_minima_into_ABL_hot_pixel(T top_y,
|
||||
local_minimum_ptr_list<T>& minima_sorted,
|
||||
local_minimum_ptr_list_itr<T>& lm,
|
||||
active_bound_list<T>& active_bounds,
|
||||
ring_manager<T>& manager,
|
||||
scanbeam_list<T>& scanbeam) {
|
||||
while (lm != minima_sorted.end() && (*lm)->y == top_y) {
|
||||
add_to_hot_pixels((*lm)->left_bound.edges.front().bot, manager);
|
||||
auto& left_bound = (*lm)->left_bound;
|
||||
auto& right_bound = (*lm)->right_bound;
|
||||
left_bound.current_edge = left_bound.edges.begin();
|
||||
left_bound.next_edge = std::next(left_bound.current_edge);
|
||||
left_bound.current_x = static_cast<double>(left_bound.current_edge->bot.x);
|
||||
right_bound.current_edge = right_bound.edges.begin();
|
||||
right_bound.next_edge = std::next(right_bound.current_edge);
|
||||
right_bound.current_x = static_cast<double>(right_bound.current_edge->bot.x);
|
||||
auto lb_abl_itr = insert_bound_into_ABL(left_bound, right_bound, active_bounds);
|
||||
if (!current_edge_is_horizontal<T>(lb_abl_itr)) {
|
||||
insert_sorted_scanbeam(scanbeam, (*lb_abl_itr)->current_edge->top.y);
|
||||
}
|
||||
auto rb_abl_itr = std::next(lb_abl_itr);
|
||||
if (!current_edge_is_horizontal<T>(rb_abl_itr)) {
|
||||
insert_sorted_scanbeam(scanbeam, (*rb_abl_itr)->current_edge->top.y);
|
||||
}
|
||||
++lm;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void build_hot_pixels(local_minimum_list<T>& minima_list, ring_manager<T>& manager) {
|
||||
active_bound_list<T> active_bounds;
|
||||
scanbeam_list<T> scanbeam;
|
||||
T scanline_y = std::numeric_limits<T>::max();
|
||||
|
||||
local_minimum_ptr_list<T> minima_sorted;
|
||||
minima_sorted.reserve(minima_list.size());
|
||||
for (auto& lm : minima_list) {
|
||||
minima_sorted.push_back(&lm);
|
||||
}
|
||||
std::stable_sort(minima_sorted.begin(), minima_sorted.end(), local_minimum_sorter<T>());
|
||||
local_minimum_ptr_list_itr<T> current_lm = minima_sorted.begin();
|
||||
|
||||
setup_scanbeam(minima_list, scanbeam);
|
||||
|
||||
// Estimate size for reserving hot pixels
|
||||
std::size_t reserve = 0;
|
||||
for (auto& lm : minima_list) {
|
||||
reserve += lm.left_bound.edges.size() + 2;
|
||||
reserve += lm.right_bound.edges.size() + 2;
|
||||
}
|
||||
manager.hot_pixels.reserve(reserve);
|
||||
|
||||
while (pop_from_scanbeam(scanline_y, scanbeam) || current_lm != minima_sorted.end()) {
|
||||
|
||||
process_hot_pixel_intersections(scanline_y, active_bounds, manager);
|
||||
|
||||
insert_local_minima_into_ABL_hot_pixel(scanline_y, minima_sorted, current_lm, active_bounds, manager, scanbeam);
|
||||
|
||||
process_hot_pixel_edges_at_top_of_scanbeam(scanline_y, scanbeam, active_bounds, manager);
|
||||
}
|
||||
preallocate_point_memory(manager, manager.hot_pixels.size());
|
||||
sort_hot_pixels(manager);
|
||||
}
|
||||
} // namespace wagyu
|
||||
} // namespace geometry
|
||||
} // namespace mapbox
|
File diff suppressed because it is too large
Load Diff
@ -1,38 +0,0 @@
|
||||
#ifndef MAPBOX_UTIL_VARIANT_VISITOR_HPP
|
||||
#define MAPBOX_UTIL_VARIANT_VISITOR_HPP
|
||||
|
||||
namespace mapbox {
|
||||
namespace util {
|
||||
|
||||
template <typename... Fns>
|
||||
struct visitor;
|
||||
|
||||
template <typename Fn>
|
||||
struct visitor<Fn> : Fn
|
||||
{
|
||||
using type = Fn;
|
||||
using Fn::operator();
|
||||
|
||||
visitor(Fn fn) : Fn(fn) {}
|
||||
};
|
||||
|
||||
template <typename Fn, typename... Fns>
|
||||
struct visitor<Fn, Fns...> : Fn, visitor<Fns...>
|
||||
{
|
||||
using type = visitor;
|
||||
using Fn::operator();
|
||||
using visitor<Fns...>::operator();
|
||||
|
||||
visitor(Fn fn, Fns... fns) : Fn(fn), visitor<Fns...>(fns...) {}
|
||||
};
|
||||
|
||||
template <typename... Fns>
|
||||
visitor<Fns...> make_visitor(Fns... fns)
|
||||
{
|
||||
return visitor<Fns...>(fns...);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mapbox
|
||||
|
||||
#endif // MAPBOX_UTIL_VARIANT_VISITOR_HPP
|
563
mbtiles.cpp
563
mbtiles.cpp
@ -11,17 +11,10 @@
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <sys/stat.h>
|
||||
#include "mvt.hpp"
|
||||
#include "main.hpp"
|
||||
#include "pool.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
#include "text.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "write_json.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
size_t max_tilestats_attributes = 1000;
|
||||
size_t max_tilestats_sample_values = 1000;
|
||||
size_t max_tilestats_values = 100;
|
||||
#include "geometry.hpp"
|
||||
|
||||
sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable) {
|
||||
sqlite3 *outdb;
|
||||
@ -45,8 +38,7 @@ sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(outdb, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", argv[0], dbname);
|
||||
fprintf(stderr, "%s: %s\n", argv[0], err);
|
||||
fprintf(stderr, "%s: create metadata table: %s\n", argv[0], err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@ -94,6 +86,43 @@ void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data,
|
||||
}
|
||||
}
|
||||
|
||||
static void quote(std::string *buf, const char *s) {
|
||||
char tmp[strlen(s) * 8 + 1];
|
||||
char *out = tmp;
|
||||
|
||||
for (; *s != '\0'; s++) {
|
||||
unsigned char ch = (unsigned char) *s;
|
||||
|
||||
if (ch == '\\' || ch == '\"') {
|
||||
*out++ = '\\';
|
||||
*out++ = ch;
|
||||
} else if (ch < ' ') {
|
||||
sprintf(out, "\\u%04x", ch);
|
||||
out = out + strlen(out);
|
||||
} else {
|
||||
*out++ = ch;
|
||||
}
|
||||
}
|
||||
|
||||
*out = '\0';
|
||||
buf->append(tmp, strlen(tmp));
|
||||
}
|
||||
|
||||
void aprintf(std::string *buf, const char *format, ...) {
|
||||
va_list ap;
|
||||
char *tmp;
|
||||
|
||||
va_start(ap, format);
|
||||
if (vasprintf(&tmp, format, ap) < 0) {
|
||||
fprintf(stderr, "memory allocation failure\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
buf->append(tmp, strlen(tmp));
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
bool type_and_string::operator<(const type_and_string &o) const {
|
||||
if (string < o.string) {
|
||||
return true;
|
||||
@ -104,186 +133,11 @@ bool type_and_string::operator<(const type_and_string &o) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool type_and_string::operator!=(const type_and_string &o) const {
|
||||
if (type != o.type) {
|
||||
return true;
|
||||
}
|
||||
if (string != o.string) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void tilestats(std::map<std::string, layermap_entry> const &layermap1, size_t elements, json_writer &state) {
|
||||
// Consolidate layers/attributes whose names are truncated
|
||||
std::vector<std::map<std::string, layermap_entry>> lmv;
|
||||
lmv.push_back(layermap1);
|
||||
std::map<std::string, layermap_entry> layermap = merge_layermaps(lmv, true);
|
||||
|
||||
state.json_write_hash();
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("layerCount");
|
||||
state.json_write_unsigned(layermap.size());
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("layers");
|
||||
state.json_write_array();
|
||||
|
||||
for (auto layer : layermap) {
|
||||
state.nospace = true;
|
||||
state.json_write_hash();
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("layer");
|
||||
state.json_write_string(layer.first);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("count");
|
||||
state.json_write_unsigned(layer.second.points + layer.second.lines + layer.second.polygons);
|
||||
|
||||
std::string geomtype = "Polygon";
|
||||
if (layer.second.points >= layer.second.lines && layer.second.points >= layer.second.polygons) {
|
||||
geomtype = "Point";
|
||||
} else if (layer.second.lines >= layer.second.polygons && layer.second.lines >= layer.second.points) {
|
||||
geomtype = "LineString";
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("geometry");
|
||||
state.json_write_string(geomtype);
|
||||
|
||||
size_t attrib_count = layer.second.file_keys.size();
|
||||
if (attrib_count > max_tilestats_attributes) {
|
||||
attrib_count = max_tilestats_attributes;
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("attributeCount");
|
||||
state.json_write_unsigned(attrib_count);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("attributes");
|
||||
state.nospace = true;
|
||||
state.json_write_array();
|
||||
|
||||
size_t attrs = 0;
|
||||
for (auto attribute : layer.second.file_keys) {
|
||||
if (attrs == elements) {
|
||||
break;
|
||||
}
|
||||
attrs++;
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_hash();
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("attribute");
|
||||
state.json_write_string(attribute.first);
|
||||
|
||||
size_t val_count = attribute.second.sample_values.size();
|
||||
if (val_count > max_tilestats_sample_values) {
|
||||
val_count = max_tilestats_sample_values;
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("count");
|
||||
state.json_write_unsigned(val_count);
|
||||
|
||||
int type = 0;
|
||||
for (auto s : attribute.second.sample_values) {
|
||||
type |= (1 << s.type);
|
||||
}
|
||||
|
||||
std::string type_str;
|
||||
// No "null" because null attributes are dropped
|
||||
if (type == (1 << mvt_double)) {
|
||||
type_str = "number";
|
||||
} else if (type == (1 << mvt_bool)) {
|
||||
type_str = "boolean";
|
||||
} else if (type == (1 << mvt_string)) {
|
||||
type_str = "string";
|
||||
} else {
|
||||
type_str = "mixed";
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("type");
|
||||
state.json_write_string(type_str);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("values");
|
||||
state.json_write_array();
|
||||
|
||||
size_t vals = 0;
|
||||
for (auto value : attribute.second.sample_values) {
|
||||
if (vals == elements) {
|
||||
break;
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
|
||||
if (value.type == mvt_double || value.type == mvt_bool) {
|
||||
vals++;
|
||||
|
||||
state.json_write_stringified(value.string);
|
||||
} else {
|
||||
std::string trunc = truncate16(value.string, 256);
|
||||
|
||||
if (trunc.size() == value.string.size()) {
|
||||
vals++;
|
||||
|
||||
state.json_write_string(value.string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_array();
|
||||
|
||||
if ((type & (1 << mvt_double)) != 0) {
|
||||
state.nospace = true;
|
||||
state.json_write_string("min");
|
||||
state.json_write_number(attribute.second.min);
|
||||
|
||||
state.nospace = true;
|
||||
state.json_write_string("max");
|
||||
state.json_write_number(attribute.second.max);
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_array();
|
||||
state.nospace = true;
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_array();
|
||||
state.nospace = true;
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fname, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap, bool vector, const char *description, bool do_tilestats, std::map<std::string, std::string> const &attribute_descriptions, std::string const &program, std::string const &commandline) {
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap) {
|
||||
char *sql, *err;
|
||||
|
||||
sqlite3 *db = outdb;
|
||||
if (outdb == NULL) {
|
||||
if (sqlite3_open("", &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "Temporary db: %s\n", sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_exec(db, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "Create metadata table: %s\n", err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('name', %Q);", fname);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set name in metadata: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -291,8 +145,8 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('description', %Q);", description != NULL ? description : fname);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('description', %Q);", fname);
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set description in metadata: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -301,7 +155,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('version', %d);", 2);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set version : %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -310,7 +164,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('minzoom', %d);", minzoom);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set minzoom: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -319,7 +173,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('maxzoom', %d);", maxzoom);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set maxzoom: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -328,7 +182,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('center', '%f,%f,%d');", midlon, midlat, maxzoom);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set center: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -337,7 +191,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('bounds', '%f,%f,%f,%f');", minlon, minlat, maxlon, maxlat);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set bounds: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -346,7 +200,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('type', %Q);", "overlay");
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set type: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -356,7 +210,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
|
||||
if (attribution != NULL) {
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('attribution', %Q);", attribution);
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set type: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -365,8 +219,8 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
sqlite3_free(sql);
|
||||
}
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('format', %Q);", vector ? "pbf" : "png");
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('format', %Q);", "pbf");
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set format: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
@ -374,247 +228,93 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
|
||||
std::string version = program + " " + VERSION;
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('generator', %Q);", version.c_str());
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set version: %s\n", err);
|
||||
std::string buf("{");
|
||||
aprintf(&buf, "\"vector_layers\": [ ");
|
||||
|
||||
std::vector<std::string> lnames;
|
||||
for (auto ai = layermap.begin(); ai != layermap.end(); ++ai) {
|
||||
lnames.push_back(ai->first);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lnames.size(); i++) {
|
||||
if (i != 0) {
|
||||
aprintf(&buf, ", ");
|
||||
}
|
||||
|
||||
auto fk = layermap.find(lnames[i]);
|
||||
aprintf(&buf, "{ \"id\": \"");
|
||||
quote(&buf, lnames[i].c_str());
|
||||
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", fk->second.minzoom, fk->second.maxzoom);
|
||||
|
||||
std::set<type_and_string>::iterator j;
|
||||
bool first = true;
|
||||
for (j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
aprintf(&buf, ", ");
|
||||
}
|
||||
|
||||
aprintf(&buf, "\"");
|
||||
quote(&buf, j->string.c_str());
|
||||
|
||||
if (j->type == VT_NUMBER) {
|
||||
aprintf(&buf, "\": \"Number\"");
|
||||
} else if (j->type == VT_BOOLEAN) {
|
||||
aprintf(&buf, "\": \"Boolean\"");
|
||||
} else {
|
||||
aprintf(&buf, "\": \"String\"");
|
||||
}
|
||||
}
|
||||
|
||||
aprintf(&buf, "} }");
|
||||
}
|
||||
|
||||
aprintf(&buf, " ] }");
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('json', %Q);", buf.c_str());
|
||||
if (sqlite3_exec(outdb, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set json: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('generator_options', %Q);", commandline.c_str());
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set commandline: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
|
||||
if (vector) {
|
||||
size_t elements = max_tilestats_values;
|
||||
std::string buf;
|
||||
|
||||
{
|
||||
json_writer state(&buf);
|
||||
|
||||
state.json_write_hash();
|
||||
state.nospace = true;
|
||||
|
||||
state.json_write_string("vector_layers");
|
||||
state.json_write_array();
|
||||
|
||||
std::vector<std::string> lnames;
|
||||
for (auto ai = layermap.begin(); ai != layermap.end(); ++ai) {
|
||||
lnames.push_back(ai->first);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lnames.size(); i++) {
|
||||
auto fk = layermap.find(lnames[i]);
|
||||
state.json_write_hash();
|
||||
|
||||
state.json_write_string("id");
|
||||
state.json_write_string(lnames[i]);
|
||||
|
||||
state.json_write_string("description");
|
||||
state.json_write_string(fk->second.description);
|
||||
|
||||
state.json_write_string("minzoom");
|
||||
state.json_write_signed(fk->second.minzoom);
|
||||
|
||||
state.json_write_string("maxzoom");
|
||||
state.json_write_signed(fk->second.maxzoom);
|
||||
|
||||
state.json_write_string("fields");
|
||||
state.json_write_hash();
|
||||
state.nospace = true;
|
||||
|
||||
bool first = true;
|
||||
for (auto j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
|
||||
state.json_write_string(j->first);
|
||||
|
||||
auto f = attribute_descriptions.find(j->first);
|
||||
if (f == attribute_descriptions.end()) {
|
||||
int type = 0;
|
||||
for (auto s : j->second.sample_values) {
|
||||
type |= (1 << s.type);
|
||||
}
|
||||
|
||||
if (type == (1 << mvt_double)) {
|
||||
state.json_write_string("Number");
|
||||
} else if (type == (1 << mvt_bool)) {
|
||||
state.json_write_string("Boolean");
|
||||
} else if (type == (1 << mvt_string)) {
|
||||
state.json_write_string("String");
|
||||
} else {
|
||||
state.json_write_string("Mixed");
|
||||
}
|
||||
} else {
|
||||
state.json_write_string(f->second);
|
||||
}
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_hash();
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
state.json_end_array();
|
||||
|
||||
if (do_tilestats && elements > 0) {
|
||||
state.nospace = true;
|
||||
state.json_write_string("tilestats");
|
||||
tilestats(layermap, elements, state);
|
||||
}
|
||||
|
||||
state.nospace = true;
|
||||
state.json_end_hash();
|
||||
}
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('json', %Q);", buf.c_str());
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "set json: %s\n", err);
|
||||
if (!forcetable) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
sqlite3_free(sql);
|
||||
}
|
||||
|
||||
if (outdir != NULL) {
|
||||
std::string metadata = std::string(outdir) + "/metadata.json";
|
||||
|
||||
struct stat st;
|
||||
if (stat(metadata.c_str(), &st) == 0) {
|
||||
// Leave existing metadata in place with --allow-existing
|
||||
} else {
|
||||
FILE *fp = fopen(metadata.c_str(), "w");
|
||||
if (fp == NULL) {
|
||||
perror(metadata.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_writer state(fp);
|
||||
|
||||
state.json_write_hash();
|
||||
state.json_write_newline();
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
if (sqlite3_prepare_v2(db, "SELECT name, value from metadata;", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
std::string key, value;
|
||||
|
||||
const char *k = (const char *) sqlite3_column_text(stmt, 0);
|
||||
const char *v = (const char *) sqlite3_column_text(stmt, 1);
|
||||
if (k == NULL || v == NULL) {
|
||||
fprintf(stderr, "Corrupt mbtiles file: null metadata\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
state.json_comma_newline();
|
||||
state.json_write_string(k);
|
||||
state.json_write_string(v);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
state.json_write_newline();
|
||||
state.json_end_hash();
|
||||
state.json_write_newline();
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (outdb == NULL) {
|
||||
if (sqlite3_close(db) != SQLITE_OK) {
|
||||
fprintf(stderr, "Could not close temp database: %s\n", sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mbtiles_close(sqlite3 *outdb, const char *pgm) {
|
||||
void mbtiles_close(sqlite3 *outdb, char **argv) {
|
||||
char *err;
|
||||
|
||||
if (sqlite3_exec(outdb, "ANALYZE;", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: ANALYZE failed: %s\n", pgm, err);
|
||||
fprintf(stderr, "%s: ANALYZE failed: %s\n", argv[0], err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (sqlite3_close(outdb) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: could not close database: %s\n", pgm, sqlite3_errmsg(outdb));
|
||||
fprintf(stderr, "%s: could not close database: %s\n", argv[0], sqlite3_errmsg(outdb));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry>> const &maps) {
|
||||
return merge_layermaps(maps, false);
|
||||
}
|
||||
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry>> const &maps, bool trunc) {
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps) {
|
||||
std::map<std::string, layermap_entry> out;
|
||||
|
||||
for (size_t i = 0; i < maps.size(); i++) {
|
||||
for (auto map = maps[i].begin(); map != maps[i].end(); ++map) {
|
||||
if (map->second.points + map->second.lines + map->second.polygons + map->second.retain == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string layername = map->first;
|
||||
if (trunc) {
|
||||
layername = truncate16(layername, 256);
|
||||
}
|
||||
|
||||
if (out.count(layername) == 0) {
|
||||
out.insert(std::pair<std::string, layermap_entry>(layername, layermap_entry(out.size())));
|
||||
auto out_entry = out.find(layername);
|
||||
if (out.count(map->first) == 0) {
|
||||
out.insert(std::pair<std::string, layermap_entry>(map->first, layermap_entry(out.size())));
|
||||
auto out_entry = out.find(map->first);
|
||||
out_entry->second.minzoom = map->second.minzoom;
|
||||
out_entry->second.maxzoom = map->second.maxzoom;
|
||||
out_entry->second.description = map->second.description;
|
||||
}
|
||||
|
||||
auto out_entry = out.find(layername);
|
||||
auto out_entry = out.find(map->first);
|
||||
if (out_entry == out.end()) {
|
||||
fprintf(stderr, "Internal error merging layers\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (auto fk = map->second.file_keys.begin(); fk != map->second.file_keys.end(); ++fk) {
|
||||
std::string attribname = fk->first;
|
||||
if (trunc) {
|
||||
attribname = truncate16(attribname, 256);
|
||||
}
|
||||
|
||||
auto fk2 = out_entry->second.file_keys.find(attribname);
|
||||
|
||||
if (fk2 == out_entry->second.file_keys.end()) {
|
||||
out_entry->second.file_keys.insert(std::pair<std::string, type_and_string_stats>(attribname, fk->second));
|
||||
} else {
|
||||
for (auto val : fk->second.sample_values) {
|
||||
auto pt = std::lower_bound(fk2->second.sample_values.begin(), fk2->second.sample_values.end(), val);
|
||||
if (pt == fk2->second.sample_values.end() || *pt != val) { // not found
|
||||
fk2->second.sample_values.insert(pt, val);
|
||||
|
||||
if (fk2->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
fk2->second.sample_values.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fk2->second.type |= fk->second.type;
|
||||
|
||||
if (fk->second.min < fk2->second.min) {
|
||||
fk2->second.min = fk->second.min;
|
||||
}
|
||||
if (fk->second.max > fk2->second.max) {
|
||||
fk2->second.max = fk->second.max;
|
||||
}
|
||||
}
|
||||
out_entry->second.file_keys.insert(*fk);
|
||||
}
|
||||
|
||||
if (map->second.minzoom < out_entry->second.minzoom) {
|
||||
@ -623,51 +323,8 @@ std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
if (map->second.maxzoom > out_entry->second.maxzoom) {
|
||||
out_entry->second.maxzoom = map->second.maxzoom;
|
||||
}
|
||||
|
||||
out_entry->second.points += map->second.points;
|
||||
out_entry->second.lines += map->second.lines;
|
||||
out_entry->second.polygons += map->second.polygons;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &attrib, type_and_string const &val) {
|
||||
if (val.type == mvt_null) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto fka = file_keys.find(attrib);
|
||||
if (fka == file_keys.end()) {
|
||||
file_keys.insert(std::pair<std::string, type_and_string_stats>(attrib, type_and_string_stats()));
|
||||
fka = file_keys.find(attrib);
|
||||
}
|
||||
|
||||
if (fka == file_keys.end()) {
|
||||
fprintf(stderr, "Can't happen (tilestats)\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (val.type == mvt_double) {
|
||||
double d = atof(val.string.c_str());
|
||||
|
||||
if (d < fka->second.min) {
|
||||
fka->second.min = d;
|
||||
}
|
||||
if (d > fka->second.max) {
|
||||
fka->second.max = d;
|
||||
}
|
||||
}
|
||||
|
||||
auto pt = std::lower_bound(fka->second.sample_values.begin(), fka->second.sample_values.end(), val);
|
||||
if (pt == fka->second.sample_values.end() || *pt != val) { // not found
|
||||
fka->second.sample_values.insert(pt, val);
|
||||
|
||||
if (fka->second.sample_values.size() > max_tilestats_sample_values) {
|
||||
fka->second.sample_values.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
fka->second.type |= (1 << val.type);
|
||||
}
|
||||
|
48
mbtiles.hpp
48
mbtiles.hpp
@ -1,40 +1,15 @@
|
||||
#ifndef MBTILES_HPP
|
||||
#define MBTILES_HPP
|
||||
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include "mvt.hpp"
|
||||
|
||||
extern size_t max_tilestats_attributes;
|
||||
extern size_t max_tilestats_sample_values;
|
||||
extern size_t max_tilestats_values;
|
||||
|
||||
struct type_and_string {
|
||||
int type = 0;
|
||||
std::string string = "";
|
||||
int type;
|
||||
std::string string;
|
||||
|
||||
bool operator<(const type_and_string &o) const;
|
||||
bool operator!=(const type_and_string &o) const;
|
||||
};
|
||||
|
||||
struct type_and_string_stats {
|
||||
std::vector<type_and_string> sample_values = std::vector<type_and_string>(); // sorted
|
||||
double min = INFINITY;
|
||||
double max = -INFINITY;
|
||||
int type = 0;
|
||||
};
|
||||
|
||||
struct layermap_entry {
|
||||
size_t id = 0;
|
||||
std::map<std::string, type_and_string_stats> file_keys{};
|
||||
int minzoom = 0;
|
||||
int maxzoom = 0;
|
||||
std::string description = "";
|
||||
|
||||
size_t points = 0;
|
||||
size_t lines = 0;
|
||||
size_t polygons = 0;
|
||||
size_t retain = 0; // keep for tilestats, even if no features directly here
|
||||
size_t id;
|
||||
std::set<type_and_string> file_keys;
|
||||
int minzoom;
|
||||
int maxzoom;
|
||||
|
||||
layermap_entry(size_t _id) {
|
||||
id = _id;
|
||||
@ -45,13 +20,10 @@ sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable);
|
||||
|
||||
void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, int size);
|
||||
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fname, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap, bool vector, const char *description, bool do_tilestats, std::map<std::string, std::string> const &attribute_descriptions, std::string const &program, std::string const &commandline);
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap);
|
||||
|
||||
void mbtiles_close(sqlite3 *outdb, const char *pgm);
|
||||
void mbtiles_close(sqlite3 *outdb, char **argv);
|
||||
|
||||
void aprintf(std::string *buf, const char *format, ...);
|
||||
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps);
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps, bool trunc);
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &layername, type_and_string const &val);
|
||||
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ int memfile_write(struct memfile *file, void *s, long long len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->len += (len + INCREMENT + 1) / INCREMENT * INCREMENT;
|
||||
file->len += INCREMENT;
|
||||
|
||||
if (ftruncate(file->fd, file->len) != 0) {
|
||||
return -1;
|
||||
|
21
memfile.hpp
21
memfile.hpp
@ -1,22 +1,11 @@
|
||||
#ifndef MEMFILE_HPP
|
||||
#define MEMFILE_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
struct memfile {
|
||||
int fd = 0;
|
||||
char *map = NULL;
|
||||
std::atomic<long long> len;
|
||||
long long off = 0;
|
||||
unsigned long tree = 0;
|
||||
|
||||
memfile()
|
||||
: len(0) {
|
||||
}
|
||||
int fd;
|
||||
char *map;
|
||||
long long len;
|
||||
long long off;
|
||||
long long tree;
|
||||
};
|
||||
|
||||
struct memfile *memfile_open(int fd);
|
||||
int memfile_close(struct memfile *file);
|
||||
int memfile_write(struct memfile *file, void *s, long long len);
|
||||
|
||||
#endif
|
||||
|
@ -1,19 +0,0 @@
|
||||
Copyright (C) 2014 Milo Yip
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
415
milo/dtoa_milo.h
415
milo/dtoa_milo.h
@ -1,415 +0,0 @@
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "msinttypes/stdint.h"
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
namespace milo {
|
||||
|
||||
#define UINT64_C2(h, l) ((static_cast<uint64_t>(h) << 32) | static_cast<uint64_t>(l))
|
||||
|
||||
struct DiyFp {
|
||||
DiyFp() {}
|
||||
|
||||
DiyFp(uint64_t ff, int ee) : f(ff), e(ee) {}
|
||||
|
||||
DiyFp(double d) {
|
||||
union {
|
||||
double d;
|
||||
uint64_t u64;
|
||||
} u = { d };
|
||||
|
||||
int biased_e = (u.u64 & kDpExponentMask) >> kDpSignificandSize;
|
||||
uint64_t significand = (u.u64 & kDpSignificandMask);
|
||||
if (biased_e != 0) {
|
||||
f = significand + kDpHiddenBit;
|
||||
e = biased_e - kDpExponentBias;
|
||||
}
|
||||
else {
|
||||
f = significand;
|
||||
e = kDpMinExponent + 1;
|
||||
}
|
||||
}
|
||||
|
||||
DiyFp operator-(const DiyFp& rhs) const {
|
||||
assert(e == rhs.e);
|
||||
assert(f >= rhs.f);
|
||||
return DiyFp(f - rhs.f, e);
|
||||
}
|
||||
|
||||
DiyFp operator*(const DiyFp& rhs) const {
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
uint64_t h;
|
||||
uint64_t l = _umul128(f, rhs.f, &h);
|
||||
if (l & (uint64_t(1) << 63)) // rounding
|
||||
h++;
|
||||
return DiyFp(h, e + rhs.e + 64);
|
||||
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
|
||||
unsigned __int128 p = static_cast<unsigned __int128>(f) * static_cast<unsigned __int128>(rhs.f);
|
||||
uint64_t h = p >> 64;
|
||||
uint64_t l = static_cast<uint64_t>(p);
|
||||
if (l & (uint64_t(1) << 63)) // rounding
|
||||
h++;
|
||||
return DiyFp(h, e + rhs.e + 64);
|
||||
#else
|
||||
const uint64_t M32 = 0xFFFFFFFF;
|
||||
const uint64_t a = f >> 32;
|
||||
const uint64_t b = f & M32;
|
||||
const uint64_t c = rhs.f >> 32;
|
||||
const uint64_t d = rhs.f & M32;
|
||||
const uint64_t ac = a * c;
|
||||
const uint64_t bc = b * c;
|
||||
const uint64_t ad = a * d;
|
||||
const uint64_t bd = b * d;
|
||||
uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
|
||||
tmp += 1U << 31; /// mult_round
|
||||
return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
|
||||
#endif
|
||||
}
|
||||
|
||||
DiyFp Normalize() const {
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
unsigned long index;
|
||||
_BitScanReverse64(&index, f);
|
||||
return DiyFp(f << (63 - index), e - (63 - index));
|
||||
#elif defined(__GNUC__)
|
||||
int s = __builtin_clzll(f);
|
||||
return DiyFp(f << s, e - s);
|
||||
#else
|
||||
DiyFp res = *this;
|
||||
while (!(res.f & kDpHiddenBit)) {
|
||||
res.f <<= 1;
|
||||
res.e--;
|
||||
}
|
||||
res.f <<= (kDiySignificandSize - kDpSignificandSize - 1);
|
||||
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 1);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
DiyFp NormalizeBoundary() const {
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
unsigned long index;
|
||||
_BitScanReverse64(&index, f);
|
||||
return DiyFp (f << (63 - index), e - (63 - index));
|
||||
#else
|
||||
DiyFp res = *this;
|
||||
while (!(res.f & (kDpHiddenBit << 1))) {
|
||||
res.f <<= 1;
|
||||
res.e--;
|
||||
}
|
||||
res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
|
||||
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const {
|
||||
DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
|
||||
DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
|
||||
mi.f <<= mi.e - pl.e;
|
||||
mi.e = pl.e;
|
||||
*plus = pl;
|
||||
*minus = mi;
|
||||
}
|
||||
|
||||
static const int kDiySignificandSize = 64;
|
||||
static const int kDpSignificandSize = 52;
|
||||
static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
|
||||
static const int kDpMinExponent = -kDpExponentBias;
|
||||
static const uint64_t kDpExponentMask = UINT64_C2(0x7FF00000, 0x00000000);
|
||||
static const uint64_t kDpSignificandMask = UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
|
||||
static const uint64_t kDpHiddenBit = UINT64_C2(0x00100000, 0x00000000);
|
||||
|
||||
uint64_t f;
|
||||
int e;
|
||||
};
|
||||
|
||||
inline DiyFp GetCachedPower(int e, int* K) {
|
||||
// 10^-348, 10^-340, ..., 10^340
|
||||
static const uint64_t kCachedPowers_F[] = {
|
||||
UINT64_C2(0xfa8fd5a0, 0x081c0288), UINT64_C2(0xbaaee17f, 0xa23ebf76),
|
||||
UINT64_C2(0x8b16fb20, 0x3055ac76), UINT64_C2(0xcf42894a, 0x5dce35ea),
|
||||
UINT64_C2(0x9a6bb0aa, 0x55653b2d), UINT64_C2(0xe61acf03, 0x3d1a45df),
|
||||
UINT64_C2(0xab70fe17, 0xc79ac6ca), UINT64_C2(0xff77b1fc, 0xbebcdc4f),
|
||||
UINT64_C2(0xbe5691ef, 0x416bd60c), UINT64_C2(0x8dd01fad, 0x907ffc3c),
|
||||
UINT64_C2(0xd3515c28, 0x31559a83), UINT64_C2(0x9d71ac8f, 0xada6c9b5),
|
||||
UINT64_C2(0xea9c2277, 0x23ee8bcb), UINT64_C2(0xaecc4991, 0x4078536d),
|
||||
UINT64_C2(0x823c1279, 0x5db6ce57), UINT64_C2(0xc2109436, 0x4dfb5637),
|
||||
UINT64_C2(0x9096ea6f, 0x3848984f), UINT64_C2(0xd77485cb, 0x25823ac7),
|
||||
UINT64_C2(0xa086cfcd, 0x97bf97f4), UINT64_C2(0xef340a98, 0x172aace5),
|
||||
UINT64_C2(0xb23867fb, 0x2a35b28e), UINT64_C2(0x84c8d4df, 0xd2c63f3b),
|
||||
UINT64_C2(0xc5dd4427, 0x1ad3cdba), UINT64_C2(0x936b9fce, 0xbb25c996),
|
||||
UINT64_C2(0xdbac6c24, 0x7d62a584), UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
|
||||
UINT64_C2(0xf3e2f893, 0xdec3f126), UINT64_C2(0xb5b5ada8, 0xaaff80b8),
|
||||
UINT64_C2(0x87625f05, 0x6c7c4a8b), UINT64_C2(0xc9bcff60, 0x34c13053),
|
||||
UINT64_C2(0x964e858c, 0x91ba2655), UINT64_C2(0xdff97724, 0x70297ebd),
|
||||
UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), UINT64_C2(0xf8a95fcf, 0x88747d94),
|
||||
UINT64_C2(0xb9447093, 0x8fa89bcf), UINT64_C2(0x8a08f0f8, 0xbf0f156b),
|
||||
UINT64_C2(0xcdb02555, 0x653131b6), UINT64_C2(0x993fe2c6, 0xd07b7fac),
|
||||
UINT64_C2(0xe45c10c4, 0x2a2b3b06), UINT64_C2(0xaa242499, 0x697392d3),
|
||||
UINT64_C2(0xfd87b5f2, 0x8300ca0e), UINT64_C2(0xbce50864, 0x92111aeb),
|
||||
UINT64_C2(0x8cbccc09, 0x6f5088cc), UINT64_C2(0xd1b71758, 0xe219652c),
|
||||
UINT64_C2(0x9c400000, 0x00000000), UINT64_C2(0xe8d4a510, 0x00000000),
|
||||
UINT64_C2(0xad78ebc5, 0xac620000), UINT64_C2(0x813f3978, 0xf8940984),
|
||||
UINT64_C2(0xc097ce7b, 0xc90715b3), UINT64_C2(0x8f7e32ce, 0x7bea5c70),
|
||||
UINT64_C2(0xd5d238a4, 0xabe98068), UINT64_C2(0x9f4f2726, 0x179a2245),
|
||||
UINT64_C2(0xed63a231, 0xd4c4fb27), UINT64_C2(0xb0de6538, 0x8cc8ada8),
|
||||
UINT64_C2(0x83c7088e, 0x1aab65db), UINT64_C2(0xc45d1df9, 0x42711d9a),
|
||||
UINT64_C2(0x924d692c, 0xa61be758), UINT64_C2(0xda01ee64, 0x1a708dea),
|
||||
UINT64_C2(0xa26da399, 0x9aef774a), UINT64_C2(0xf209787b, 0xb47d6b85),
|
||||
UINT64_C2(0xb454e4a1, 0x79dd1877), UINT64_C2(0x865b8692, 0x5b9bc5c2),
|
||||
UINT64_C2(0xc83553c5, 0xc8965d3d), UINT64_C2(0x952ab45c, 0xfa97a0b3),
|
||||
UINT64_C2(0xde469fbd, 0x99a05fe3), UINT64_C2(0xa59bc234, 0xdb398c25),
|
||||
UINT64_C2(0xf6c69a72, 0xa3989f5c), UINT64_C2(0xb7dcbf53, 0x54e9bece),
|
||||
UINT64_C2(0x88fcf317, 0xf22241e2), UINT64_C2(0xcc20ce9b, 0xd35c78a5),
|
||||
UINT64_C2(0x98165af3, 0x7b2153df), UINT64_C2(0xe2a0b5dc, 0x971f303a),
|
||||
UINT64_C2(0xa8d9d153, 0x5ce3b396), UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
|
||||
UINT64_C2(0xbb764c4c, 0xa7a44410), UINT64_C2(0x8bab8eef, 0xb6409c1a),
|
||||
UINT64_C2(0xd01fef10, 0xa657842c), UINT64_C2(0x9b10a4e5, 0xe9913129),
|
||||
UINT64_C2(0xe7109bfb, 0xa19c0c9d), UINT64_C2(0xac2820d9, 0x623bf429),
|
||||
UINT64_C2(0x80444b5e, 0x7aa7cf85), UINT64_C2(0xbf21e440, 0x03acdd2d),
|
||||
UINT64_C2(0x8e679c2f, 0x5e44ff8f), UINT64_C2(0xd433179d, 0x9c8cb841),
|
||||
UINT64_C2(0x9e19db92, 0xb4e31ba9), UINT64_C2(0xeb96bf6e, 0xbadf77d9),
|
||||
UINT64_C2(0xaf87023b, 0x9bf0ee6b)
|
||||
};
|
||||
static const int16_t kCachedPowers_E[] = {
|
||||
-1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
|
||||
-954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
|
||||
-688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
|
||||
-422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
|
||||
-157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
|
||||
109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
|
||||
375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
|
||||
641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
|
||||
907, 933, 960, 986, 1013, 1039, 1066
|
||||
};
|
||||
|
||||
//int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
|
||||
double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
|
||||
int k = static_cast<int>(dk);
|
||||
if (k != dk)
|
||||
k++;
|
||||
|
||||
unsigned index = static_cast<unsigned>((k >> 3) + 1);
|
||||
*K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
|
||||
|
||||
assert(index < sizeof(kCachedPowers_F) / sizeof(kCachedPowers_F[0]));
|
||||
return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
|
||||
}
|
||||
|
||||
inline void GrisuRound(std::string &buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
|
||||
while (rest < wp_w && delta - rest >= ten_kappa &&
|
||||
(rest + ten_kappa < wp_w || /// closer
|
||||
wp_w - rest > rest + ten_kappa - wp_w)) {
|
||||
buffer[len - 1]--;
|
||||
rest += ten_kappa;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned CountDecimalDigit32(uint32_t n) {
|
||||
// Simple pure C++ implementation was faster than __builtin_clz version in this situation.
|
||||
if (n < 10) return 1;
|
||||
if (n < 100) return 2;
|
||||
if (n < 1000) return 3;
|
||||
if (n < 10000) return 4;
|
||||
if (n < 100000) return 5;
|
||||
if (n < 1000000) return 6;
|
||||
if (n < 10000000) return 7;
|
||||
if (n < 100000000) return 8;
|
||||
if (n < 1000000000) return 9;
|
||||
return 10;
|
||||
}
|
||||
|
||||
inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, std::string &buffer, int* len, int* K) {
|
||||
static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
|
||||
const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
|
||||
const DiyFp wp_w = Mp - W;
|
||||
uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
|
||||
uint64_t p2 = Mp.f & (one.f - 1);
|
||||
int kappa = static_cast<int>(CountDecimalDigit32(p1));
|
||||
*len = 0;
|
||||
|
||||
while (kappa > 0) {
|
||||
uint32_t d;
|
||||
switch (kappa) {
|
||||
case 10: d = p1 / 1000000000; p1 %= 1000000000; break;
|
||||
case 9: d = p1 / 100000000; p1 %= 100000000; break;
|
||||
case 8: d = p1 / 10000000; p1 %= 10000000; break;
|
||||
case 7: d = p1 / 1000000; p1 %= 1000000; break;
|
||||
case 6: d = p1 / 100000; p1 %= 100000; break;
|
||||
case 5: d = p1 / 10000; p1 %= 10000; break;
|
||||
case 4: d = p1 / 1000; p1 %= 1000; break;
|
||||
case 3: d = p1 / 100; p1 %= 100; break;
|
||||
case 2: d = p1 / 10; p1 %= 10; break;
|
||||
case 1: d = p1; p1 = 0; break;
|
||||
default:
|
||||
#if defined(_MSC_VER)
|
||||
__assume(0);
|
||||
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
d = 0;
|
||||
#endif
|
||||
}
|
||||
if (d || *len) {
|
||||
buffer.push_back('0' + static_cast<char>(d));
|
||||
(*len)++;
|
||||
}
|
||||
kappa--;
|
||||
uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
|
||||
if (tmp <= delta) {
|
||||
*K += kappa;
|
||||
GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// kappa = 0
|
||||
for (;;) {
|
||||
p2 *= 10;
|
||||
delta *= 10;
|
||||
char d = static_cast<char>(p2 >> -one.e);
|
||||
if (d || *len) {
|
||||
buffer.push_back('0' + d);
|
||||
(*len)++;
|
||||
}
|
||||
p2 &= one.f - 1;
|
||||
kappa--;
|
||||
if (p2 < delta) {
|
||||
*K += kappa;
|
||||
int index = -static_cast<int>(kappa);
|
||||
GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[-static_cast<int>(kappa)] : 0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void Grisu2(double value, std::string &buffer, int* length, int* K) {
|
||||
const DiyFp v(value);
|
||||
DiyFp w_m, w_p;
|
||||
v.NormalizedBoundaries(&w_m, &w_p);
|
||||
|
||||
const DiyFp c_mk = GetCachedPower(w_p.e, K);
|
||||
const DiyFp W = v.Normalize() * c_mk;
|
||||
DiyFp Wp = w_p * c_mk;
|
||||
DiyFp Wm = w_m * c_mk;
|
||||
Wm.f++;
|
||||
Wp.f--;
|
||||
DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
|
||||
}
|
||||
|
||||
inline const char* GetDigitsLut() {
|
||||
static const char cDigitsLut[200] = {
|
||||
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
|
||||
'1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
|
||||
'2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
|
||||
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
|
||||
'4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
|
||||
'5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
|
||||
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
|
||||
'7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
|
||||
'8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
|
||||
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
|
||||
};
|
||||
return cDigitsLut;
|
||||
}
|
||||
|
||||
inline void WriteExponent(int K, std::string &buffer) {
|
||||
if (K < 0) {
|
||||
buffer.push_back('-');
|
||||
K = -K;
|
||||
} else {
|
||||
buffer.push_back('+');
|
||||
}
|
||||
|
||||
if (K >= 100) {
|
||||
buffer.push_back('0' + static_cast<char>(K / 100));
|
||||
K %= 100;
|
||||
const char* d = GetDigitsLut() + K * 2;
|
||||
buffer.push_back(d[0]);
|
||||
buffer.push_back(d[1]);
|
||||
}
|
||||
else if (K >= 10) {
|
||||
const char* d = GetDigitsLut() + K * 2;
|
||||
buffer.push_back(d[0]);
|
||||
buffer.push_back(d[1]);
|
||||
}
|
||||
else
|
||||
buffer.push_back('0' + static_cast<char>(K));
|
||||
}
|
||||
|
||||
inline void Prettify(std::string &buffer, int length, int k) {
|
||||
const int kk = length + k; // 10^(kk-1) <= v < 10^kk
|
||||
|
||||
if (length <= kk && kk <= 21) {
|
||||
// 1234e7 -> 12340000000
|
||||
for (int i = length; i < kk; i++)
|
||||
buffer.push_back('0');
|
||||
}
|
||||
else if (0 < kk && kk <= 21) {
|
||||
// 1234e-2 -> 12.34
|
||||
buffer.insert(buffer.begin() + kk, '.');
|
||||
}
|
||||
else if (-6 < kk && kk <= 0) {
|
||||
// 1234e-6 -> 0.001234
|
||||
const int offset = 2 - kk;
|
||||
buffer.insert(buffer.begin(), '0');
|
||||
buffer.insert(buffer.begin() + 1, '.');
|
||||
for (int i = 2; i < offset; i++)
|
||||
buffer.insert(buffer.begin() + 2, '0');
|
||||
}
|
||||
else if (length == 1) {
|
||||
// 1e30
|
||||
buffer.push_back('e');
|
||||
WriteExponent(kk - 1, buffer);
|
||||
}
|
||||
else {
|
||||
// 1234e30 -> 1.234e33
|
||||
buffer.insert(buffer.begin() + 1, '.');
|
||||
buffer.push_back('e');
|
||||
WriteExponent(kk - 1, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string dtoa_milo(double value) {
|
||||
std::string buffer;
|
||||
|
||||
if (std::isnan(value)) {
|
||||
return "nan";
|
||||
}
|
||||
if (std::isinf(value)) {
|
||||
if (value < 0) {
|
||||
return "-inf";
|
||||
} else {
|
||||
return "inf";
|
||||
}
|
||||
}
|
||||
|
||||
if (value == 0) {
|
||||
buffer = "0";
|
||||
}
|
||||
else {
|
||||
bool minus = false;
|
||||
if (value < 0) {
|
||||
minus = true;
|
||||
value = -value;
|
||||
}
|
||||
int length, K;
|
||||
Grisu2(value, buffer, &length, &K);
|
||||
Prettify(buffer, length, K);
|
||||
if (minus) {
|
||||
buffer.insert(buffer.begin(), '-');
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
269
mvt.cpp
269
mvt.cpp
@ -4,15 +4,10 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <zlib.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include "mvt.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "protozero/varint.hpp"
|
||||
#include "protozero/pbf_reader.hpp"
|
||||
#include "protozero/pbf_writer.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
|
||||
mvt_geometry::mvt_geometry(int nop, long long nx, long long ny) {
|
||||
this->op = nop;
|
||||
@ -34,49 +29,25 @@ int decompress(std::string const &input, std::string &output) {
|
||||
inflate_s.avail_in = 0;
|
||||
inflate_s.next_in = Z_NULL;
|
||||
if (inflateInit2(&inflate_s, 32 + 15) != Z_OK) {
|
||||
fprintf(stderr, "Decompression error: %s\n", inflate_s.msg);
|
||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||
}
|
||||
inflate_s.next_in = (Bytef *) input.data();
|
||||
inflate_s.avail_in = input.size();
|
||||
inflate_s.next_out = (Bytef *) output.data();
|
||||
inflate_s.avail_out = output.size();
|
||||
|
||||
while (true) {
|
||||
size_t existing_output = inflate_s.next_out - (Bytef *) output.data();
|
||||
|
||||
output.resize(existing_output + 2 * inflate_s.avail_in + 100);
|
||||
inflate_s.next_out = (Bytef *) output.data() + existing_output;
|
||||
inflate_s.avail_out = output.size() - existing_output;
|
||||
|
||||
int ret = inflate(&inflate_s, 0);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Decompression error: ");
|
||||
if (ret == Z_DATA_ERROR) {
|
||||
fprintf(stderr, "data error");
|
||||
}
|
||||
if (ret == Z_STREAM_ERROR) {
|
||||
fprintf(stderr, "stream error");
|
||||
}
|
||||
if (ret == Z_MEM_ERROR) {
|
||||
fprintf(stderr, "out of memory");
|
||||
}
|
||||
if (ret == Z_BUF_ERROR) {
|
||||
fprintf(stderr, "no data in buffer");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
size_t length = 0;
|
||||
do {
|
||||
output.resize(length + 2 * input.size());
|
||||
inflate_s.avail_out = 2 * input.size();
|
||||
inflate_s.next_out = (Bytef *) (output.data() + length);
|
||||
int ret = inflate(&inflate_s, Z_FINISH);
|
||||
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
|
||||
fprintf(stderr, "error: %s\n", inflate_s.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ret == Z_STREAM_END) {
|
||||
break;
|
||||
}
|
||||
|
||||
// ret must be Z_OK or Z_NEED_DICT;
|
||||
// continue decompresing
|
||||
}
|
||||
|
||||
output.resize(inflate_s.next_out - (Bytef *) output.data());
|
||||
length += (2 * input.size() - inflate_s.avail_out);
|
||||
} while (inflate_s.avail_out == 0);
|
||||
inflateEnd(&inflate_s);
|
||||
output.resize(length);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -108,20 +79,16 @@ int compress(std::string const &input, std::string &output) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool mvt_tile::decode(std::string &message, bool &was_compressed) {
|
||||
bool mvt_tile::decode(std::string &message) {
|
||||
layers.clear();
|
||||
std::string src;
|
||||
|
||||
if (is_compressed(message)) {
|
||||
std::string uncompressed;
|
||||
if (decompress(message, uncompressed) == 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
decompress(message, uncompressed);
|
||||
src = uncompressed;
|
||||
was_compressed = true;
|
||||
} else {
|
||||
src = message;
|
||||
was_compressed = false;
|
||||
}
|
||||
|
||||
protozero::pbf_reader reader(src);
|
||||
@ -148,9 +115,6 @@ bool mvt_tile::decode(std::string &message, bool &was_compressed) {
|
||||
protozero::pbf_reader value_reader(layer_reader.get_message());
|
||||
mvt_value value;
|
||||
|
||||
value.type = mvt_null;
|
||||
value.numeric_value.null_value = 0;
|
||||
|
||||
while (value_reader.next()) {
|
||||
switch (value_reader.tag()) {
|
||||
case 1: /* string */
|
||||
@ -332,12 +296,6 @@ std::string mvt_tile::encode() {
|
||||
value_writer.add_sint64(6, pbv.numeric_value.sint_value);
|
||||
} else if (pbv.type == mvt_bool) {
|
||||
value_writer.add_bool(7, pbv.numeric_value.bool_value);
|
||||
} else if (pbv.type == mvt_null) {
|
||||
fprintf(stderr, "Internal error: trying to write null attribute to tile\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
fprintf(stderr, "Internal error: trying to write undefined attribute type to tile\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
layer_writer.add_message(4, value_string);
|
||||
@ -356,7 +314,7 @@ std::string mvt_tile::encode() {
|
||||
|
||||
std::vector<uint32_t> geometry;
|
||||
|
||||
long long px = 0, py = 0;
|
||||
int px = 0, py = 0;
|
||||
int cmd_idx = -1;
|
||||
int cmd = -1;
|
||||
int length = 0;
|
||||
@ -381,13 +339,8 @@ std::string mvt_tile::encode() {
|
||||
long long wwx = geom[g].x;
|
||||
long long wwy = geom[g].y;
|
||||
|
||||
long long dx = wwx - px;
|
||||
long long dy = wwy - py;
|
||||
|
||||
if (dx < INT_MIN || dx > INT_MAX || dy < INT_MIN || dy > INT_MAX) {
|
||||
fprintf(stderr, "Internal error: Geometry delta is too big: %lld,%lld\n", dx, dy);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
int dx = wwx - px;
|
||||
int dy = wwy - py;
|
||||
|
||||
geometry.push_back(protozero::encode_zigzag32(dx));
|
||||
geometry.push_back(protozero::encode_zigzag32(dy));
|
||||
@ -414,7 +367,10 @@ std::string mvt_tile::encode() {
|
||||
writer.add_message(3, layer_string);
|
||||
}
|
||||
|
||||
return data;
|
||||
std::string compressed;
|
||||
compress(data, compressed);
|
||||
|
||||
return compressed;
|
||||
}
|
||||
|
||||
bool mvt_value::operator<(const mvt_value &o) const {
|
||||
@ -428,8 +384,7 @@ bool mvt_value::operator<(const mvt_value &o) const {
|
||||
(type == mvt_int && numeric_value.int_value < o.numeric_value.int_value) ||
|
||||
(type == mvt_uint && numeric_value.uint_value < o.numeric_value.uint_value) ||
|
||||
(type == mvt_sint && numeric_value.sint_value < o.numeric_value.sint_value) ||
|
||||
(type == mvt_bool && numeric_value.bool_value < o.numeric_value.bool_value) ||
|
||||
(type == mvt_null && numeric_value.null_value < o.numeric_value.null_value)) {
|
||||
(type == mvt_bool && numeric_value.bool_value < o.numeric_value.bool_value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -437,59 +392,6 @@ bool mvt_value::operator<(const mvt_value &o) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string quote(std::string const &s) {
|
||||
std::string buf;
|
||||
|
||||
for (size_t i = 0; i < s.size(); i++) {
|
||||
unsigned char ch = s[i];
|
||||
|
||||
if (ch == '\\' || ch == '\"') {
|
||||
buf.push_back('\\');
|
||||
buf.push_back(ch);
|
||||
} else if (ch < ' ') {
|
||||
char tmp[7];
|
||||
sprintf(tmp, "\\u%04x", ch);
|
||||
buf.append(std::string(tmp));
|
||||
} else {
|
||||
buf.push_back(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string mvt_value::toString() {
|
||||
if (type == mvt_string) {
|
||||
return quote(string_value);
|
||||
} else if (type == mvt_int) {
|
||||
return std::to_string(numeric_value.int_value);
|
||||
} else if (type == mvt_double) {
|
||||
double v = numeric_value.double_value;
|
||||
if (v == (long long) v) {
|
||||
return std::to_string((long long) v);
|
||||
} else {
|
||||
return milo::dtoa_milo(v);
|
||||
}
|
||||
} else if (type == mvt_float) {
|
||||
double v = numeric_value.float_value;
|
||||
if (v == (long long) v) {
|
||||
return std::to_string((long long) v);
|
||||
} else {
|
||||
return milo::dtoa_milo(v);
|
||||
}
|
||||
} else if (type == mvt_sint) {
|
||||
return std::to_string(numeric_value.sint_value);
|
||||
} else if (type == mvt_uint) {
|
||||
return std::to_string(numeric_value.uint_value);
|
||||
} else if (type == mvt_bool) {
|
||||
return numeric_value.bool_value ? "true" : "false";
|
||||
} else if (type == mvt_null) {
|
||||
return "null";
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void mvt_layer::tag(mvt_feature &feature, std::string key, mvt_value value) {
|
||||
size_t ko, vo;
|
||||
|
||||
@ -515,130 +417,3 @@ void mvt_layer::tag(mvt_feature &feature, std::string key, mvt_value value) {
|
||||
feature.tags.push_back(ko);
|
||||
feature.tags.push_back(vo);
|
||||
}
|
||||
|
||||
bool is_integer(const char *s, long long *v) {
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
|
||||
*v = strtoll(s, &endptr, 0);
|
||||
if (*v == 0 && errno != 0) {
|
||||
return 0;
|
||||
}
|
||||
if ((*v == LLONG_MIN || *v == LLONG_MAX) && (errno == ERANGE || errno == EINVAL)) {
|
||||
return 0;
|
||||
}
|
||||
if (*endptr != '\0') {
|
||||
// Special case: If it is an integer followed by .0000 or similar,
|
||||
// it is still an integer
|
||||
|
||||
if (*endptr != '.') {
|
||||
return 0;
|
||||
}
|
||||
endptr++;
|
||||
for (; *endptr != '\0'; endptr++) {
|
||||
if (*endptr != '0') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool is_unsigned_integer(const char *s, unsigned long long *v) {
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
|
||||
// Special check because MacOS stroull() returns 1
|
||||
// for -18446744073709551615
|
||||
while (isspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
if (*s == '-') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*v = strtoull(s, &endptr, 0);
|
||||
if (*v == 0 && errno != 0) {
|
||||
return 0;
|
||||
}
|
||||
if ((*v == ULLONG_MAX) && (errno == ERANGE || errno == EINVAL)) {
|
||||
return 0;
|
||||
}
|
||||
if (*endptr != '\0') {
|
||||
// Special case: If it is an integer followed by .0000 or similar,
|
||||
// it is still an integer
|
||||
|
||||
if (*endptr != '.') {
|
||||
return 0;
|
||||
}
|
||||
endptr++;
|
||||
for (; *endptr != '\0'; endptr++) {
|
||||
if (*endptr != '0') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
mvt_value stringified_to_mvt_value(int type, const char *s) {
|
||||
mvt_value tv;
|
||||
|
||||
if (type == mvt_double) {
|
||||
long long v;
|
||||
unsigned long long uv;
|
||||
if (is_unsigned_integer(s, &uv)) {
|
||||
if (uv <= LLONG_MAX) {
|
||||
tv.type = mvt_int;
|
||||
tv.numeric_value.int_value = uv;
|
||||
} else {
|
||||
tv.type = mvt_uint;
|
||||
tv.numeric_value.uint_value = uv;
|
||||
}
|
||||
} else if (is_integer(s, &v)) {
|
||||
tv.type = mvt_sint;
|
||||
tv.numeric_value.sint_value = v;
|
||||
} else {
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
|
||||
float f = strtof(s, &endptr);
|
||||
|
||||
if (endptr == s || ((f == HUGE_VAL || f == HUGE_VALF || f == HUGE_VALL) && errno == ERANGE)) {
|
||||
double d = strtod(s, &endptr);
|
||||
if (endptr == s || ((d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL) && errno == ERANGE)) {
|
||||
fprintf(stderr, "Warning: numeric value %s could not be represented\n", s);
|
||||
}
|
||||
tv.type = mvt_double;
|
||||
tv.numeric_value.double_value = d;
|
||||
} else {
|
||||
double d = atof(s);
|
||||
if (f == d) {
|
||||
tv.type = mvt_float;
|
||||
tv.numeric_value.float_value = f;
|
||||
} else {
|
||||
// Conversion succeeded, but lost precision, so use double
|
||||
tv.type = mvt_double;
|
||||
tv.numeric_value.double_value = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (type == mvt_bool) {
|
||||
tv.type = mvt_bool;
|
||||
tv.numeric_value.bool_value = (s[0] == 't');
|
||||
} else if (type == mvt_null) {
|
||||
tv.type = mvt_null;
|
||||
tv.numeric_value.null_value = 0;
|
||||
} else {
|
||||
tv.type = mvt_string;
|
||||
tv.string_value = s;
|
||||
}
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
75
mvt.hpp
75
mvt.hpp
@ -1,12 +1,3 @@
|
||||
#ifndef MVT_HPP
|
||||
#define MVT_HPP
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
struct mvt_value;
|
||||
struct mvt_layer;
|
||||
|
||||
@ -17,23 +8,11 @@ enum mvt_operation {
|
||||
};
|
||||
|
||||
struct mvt_geometry {
|
||||
long long x = 0;
|
||||
long long y = 0;
|
||||
int /* mvt_operation */ op = 0;
|
||||
int x;
|
||||
int y;
|
||||
int /* mvt_operation */ op;
|
||||
|
||||
mvt_geometry(int op, long long x, long long y);
|
||||
|
||||
bool operator<(mvt_geometry const &s) const {
|
||||
if (y < s.y || (y == s.y && x < s.x)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(mvt_geometry const &s) const {
|
||||
return y == s.y && x == s.x;
|
||||
}
|
||||
};
|
||||
|
||||
enum mvt_geometry_type {
|
||||
@ -43,12 +22,11 @@ enum mvt_geometry_type {
|
||||
};
|
||||
|
||||
struct mvt_feature {
|
||||
std::vector<unsigned> tags{};
|
||||
std::vector<mvt_geometry> geometry{};
|
||||
int /* mvt_geometry_type */ type = 0;
|
||||
unsigned long long id = 0;
|
||||
bool has_id = false;
|
||||
bool dropped = false;
|
||||
std::vector<unsigned> tags;
|
||||
std::vector<mvt_geometry> geometry;
|
||||
int /* mvt_geometry_type */ type;
|
||||
unsigned long long id;
|
||||
bool has_id;
|
||||
|
||||
mvt_feature() {
|
||||
has_id = false;
|
||||
@ -63,8 +41,7 @@ enum mvt_value_type {
|
||||
mvt_int,
|
||||
mvt_uint,
|
||||
mvt_sint,
|
||||
mvt_bool,
|
||||
mvt_null,
|
||||
mvt_bool
|
||||
};
|
||||
|
||||
struct mvt_value {
|
||||
@ -77,49 +54,35 @@ struct mvt_value {
|
||||
unsigned long long uint_value;
|
||||
long long sint_value;
|
||||
bool bool_value;
|
||||
int null_value;
|
||||
} numeric_value;
|
||||
|
||||
bool operator<(const mvt_value &o) const;
|
||||
std::string toString();
|
||||
|
||||
mvt_value() {
|
||||
this->type = mvt_double;
|
||||
this->string_value = "";
|
||||
this->numeric_value.double_value = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct mvt_layer {
|
||||
int version = 0;
|
||||
std::string name = "";
|
||||
std::vector<mvt_feature> features{};
|
||||
std::vector<std::string> keys{};
|
||||
std::vector<mvt_value> values{};
|
||||
long long extent = 0;
|
||||
int version;
|
||||
std::string name;
|
||||
std::vector<mvt_feature> features;
|
||||
std::vector<std::string> keys;
|
||||
std::vector<mvt_value> values;
|
||||
int extent;
|
||||
|
||||
// Add a key-value pair to a feature, using this layer's constant pool
|
||||
void tag(mvt_feature &feature, std::string key, mvt_value value);
|
||||
|
||||
// For tracking the key-value constants already used in this layer
|
||||
std::map<std::string, size_t> key_map{};
|
||||
std::map<mvt_value, size_t> value_map{};
|
||||
std::map<std::string, size_t> key_map;
|
||||
std::map<mvt_value, size_t> value_map;
|
||||
};
|
||||
|
||||
struct mvt_tile {
|
||||
std::vector<mvt_layer> layers{};
|
||||
std::vector<mvt_layer> layers;
|
||||
|
||||
std::string encode();
|
||||
bool decode(std::string &message, bool &was_compressed);
|
||||
bool decode(std::string &message);
|
||||
};
|
||||
|
||||
bool is_compressed(std::string const &data);
|
||||
int decompress(std::string const &input, std::string &output);
|
||||
int compress(std::string const &input, std::string &output);
|
||||
int dezig(unsigned n);
|
||||
|
||||
mvt_value stringified_to_mvt_value(int type, const char *s);
|
||||
|
||||
bool is_integer(const char *s, long long *v);
|
||||
bool is_unsigned_integer(const char *s, unsigned long long *v);
|
||||
#endif
|
||||
|
23
options.hpp
23
options.hpp
@ -1,11 +1,8 @@
|
||||
#ifndef OPTIONS_HPP
|
||||
#define OPTIONS_HPP
|
||||
|
||||
#define A_COALESCE ((int) 'c')
|
||||
#define A_REVERSE ((int) 'r')
|
||||
#define A_REORDER ((int) 'o')
|
||||
#define A_LINE_DROP ((int) 'l')
|
||||
#define A_DEBUG_POLYGON ((int) '@')
|
||||
#define A_DEBUG_POLYGON ((int) 'D')
|
||||
#define A_POLYGON_DROP ((int) 'p')
|
||||
#define A_DETECT_SHARED_BORDERS ((int) 'b')
|
||||
#define A_PREFER_RADIX_SORT ((int) 'R')
|
||||
@ -15,20 +12,9 @@
|
||||
#define A_DROP_DENSEST_AS_NEEDED ((int) 's')
|
||||
#define A_DROP_FRACTION_AS_NEEDED ((int) 'd')
|
||||
#define A_DROP_SMALLEST_AS_NEEDED ((int) 'n')
|
||||
#define A_COALESCE_DENSEST_AS_NEEDED ((int) 'S')
|
||||
#define A_COALESCE_SMALLEST_AS_NEEDED ((int) 'N')
|
||||
#define A_COALESCE_FRACTION_AS_NEEDED ((int) 'D')
|
||||
#define A_GRID_LOW_ZOOMS ((int) 'L')
|
||||
#define A_DETECT_WRAPAROUND ((int) 'w')
|
||||
#define A_EXTEND_ZOOMS ((int) 'e')
|
||||
#define A_CLUSTER_DENSEST_AS_NEEDED ((int) 'C')
|
||||
#define A_GENERATE_IDS ((int) 'i')
|
||||
#define A_CONVERT_NUMERIC_IDS ((int) 'I')
|
||||
#define A_HILBERT ((int) 'h')
|
||||
|
||||
#define P_SIMPLIFY ((int) 's')
|
||||
#define P_SIMPLIFY_LOW ((int) 'S')
|
||||
#define P_SIMPLIFY_SHARED_NODES ((int) 'n')
|
||||
#define P_FEATURE_LIMIT ((int) 'f')
|
||||
#define P_KILOBYTE_LIMIT ((int) 'k')
|
||||
#define P_DYNAMIC_DROP ((int) 'd')
|
||||
@ -37,13 +23,6 @@
|
||||
#define P_CLIPPING ((int) 'c')
|
||||
#define P_DUPLICATION ((int) 'D')
|
||||
#define P_TINY_POLYGON_REDUCTION ((int) 't')
|
||||
#define P_TILE_COMPRESSION ((int) 'C')
|
||||
#define P_TILE_STATS ((int) 'g')
|
||||
#define P_USE_SOURCE_POLYGON_WINDING ((int) 'w')
|
||||
#define P_REVERSE_SOURCE_POLYGON_WINDING ((int) 'W')
|
||||
#define P_EMPTY_CSV_COLUMNS ((int) 'e')
|
||||
|
||||
extern int prevent[256];
|
||||
extern int additional[256];
|
||||
|
||||
#endif
|
||||
|
660
plugin.cpp
660
plugin.cpp
@ -1,660 +0,0 @@
|
||||
#ifdef __APPLE__
|
||||
#define _DARWIN_UNLIMITED_STREAMS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <cmath>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sqlite3.h>
|
||||
#include <limits.h>
|
||||
#include "main.hpp"
|
||||
#include "mvt.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "jsonpull/jsonpull.h"
|
||||
}
|
||||
|
||||
#include "plugin.hpp"
|
||||
#include "write_json.hpp"
|
||||
#include "read_json.hpp"
|
||||
|
||||
struct writer_arg {
|
||||
int write_to;
|
||||
std::vector<mvt_layer> *layers;
|
||||
unsigned z;
|
||||
unsigned x;
|
||||
unsigned y;
|
||||
int extent;
|
||||
};
|
||||
|
||||
void *run_writer(void *a) {
|
||||
writer_arg *wa = (writer_arg *) a;
|
||||
|
||||
FILE *fp = fdopen(wa->write_to, "w");
|
||||
if (fp == NULL) {
|
||||
perror("fdopen (pipe writer)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
if (errno == EPIPE) {
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: broken pipe in postfilter\n");
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
perror("fclose output to filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// XXX deduplicate
|
||||
static std::vector<mvt_geometry> to_feature(drawvec &geom) {
|
||||
std::vector<mvt_geometry> out;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
out.push_back(mvt_geometry(geom[i].op, geom[i].x, geom[i].y));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// Reads from the postfilter
|
||||
std::vector<mvt_layer> parse_layers(int fd, 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, int extent) {
|
||||
std::map<std::string, mvt_layer> ret;
|
||||
|
||||
FILE *f = fdopen(fd, "r");
|
||||
if (f == NULL) {
|
||||
perror("fdopen filter output");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
json_pull *jp = json_begin_file(f);
|
||||
|
||||
while (1) {
|
||||
json_object *j = json_read(jp);
|
||||
if (j == NULL) {
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "Filter output:%d: %s\n", jp->line, jp->error);
|
||||
if (jp->root != NULL) {
|
||||
json_context(jp->root);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_free(jp->root);
|
||||
break;
|
||||
}
|
||||
|
||||
json_object *type = json_hash_get(j, "type");
|
||||
if (type == NULL || type->type != JSON_STRING) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(type->string, "Feature") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: filtered feature with no geometry\n", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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\n", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: null geometry (additional not reported)\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (geometry_type->type != JSON_STRING) {
|
||||
fprintf(stderr, "Filter output:%d: geometry type is not a string\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "Filter output:%d: feature without coordinates array\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int t;
|
||||
for (t = 0; t < GEOM_TYPES; t++) {
|
||||
if (strcmp(geometry_type->string, geometry_names[t]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= GEOM_TYPES) {
|
||||
fprintf(stderr, "Filter output:%d: Can't handle geometry type %s\n", jp->line, geometry_type->string);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string layername = "unknown";
|
||||
json_object *tippecanoe = json_hash_get(j, "tippecanoe");
|
||||
json_object *layer = NULL;
|
||||
if (tippecanoe != NULL) {
|
||||
layer = json_hash_get(tippecanoe, "layer");
|
||||
if (layer != NULL && layer->type == JSON_STRING) {
|
||||
layername = std::string(layer->string);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.count(layername) == 0) {
|
||||
mvt_layer l;
|
||||
l.name = layername;
|
||||
l.version = 2;
|
||||
l.extent = extent;
|
||||
|
||||
ret.insert(std::pair<std::string, mvt_layer>(layername, l));
|
||||
}
|
||||
auto l = ret.find(layername);
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv);
|
||||
}
|
||||
|
||||
// Scale and offset geometry from global to tile
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
long long scale = 1LL << (32 - z);
|
||||
dv[i].x = std::round((dv[i].x - scale * x) * extent / (double) scale);
|
||||
dv[i].y = std::round((dv[i].y - scale * y) * extent / (double) scale);
|
||||
}
|
||||
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = clean_or_clip_poly(dv, 0, 0, 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);
|
||||
}
|
||||
|
||||
if (dv.size() > 0) {
|
||||
mvt_feature feature;
|
||||
feature.type = mb_geometry[t];
|
||||
feature.geometry = to_feature(dv);
|
||||
|
||||
json_object *id = json_hash_get(j, "id");
|
||||
if (id != NULL) {
|
||||
feature.id = atoll(id->string);
|
||||
feature.has_id = true;
|
||||
}
|
||||
|
||||
std::map<std::string, layermap_entry> &layermap = (*layermaps)[tiling_seg];
|
||||
if (layermap.count(layername) == 0) {
|
||||
layermap_entry lme = layermap_entry(layermap.size());
|
||||
lme.minzoom = z;
|
||||
lme.maxzoom = z;
|
||||
|
||||
layermap.insert(std::pair<std::string, layermap_entry>(layername, lme));
|
||||
|
||||
if (lme.id >= (*layer_unmaps)[tiling_seg].size()) {
|
||||
(*layer_unmaps)[tiling_seg].resize(lme.id + 1);
|
||||
(*layer_unmaps)[tiling_seg][lme.id] = layername;
|
||||
}
|
||||
}
|
||||
|
||||
auto fk = layermap.find(layername);
|
||||
if (fk == layermap.end()) {
|
||||
fprintf(stderr, "Internal error: layer %s not found\n", layername.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (z < fk->second.minzoom) {
|
||||
fk->second.minzoom = z;
|
||||
}
|
||||
if (z > fk->second.maxzoom) {
|
||||
fk->second.maxzoom = z;
|
||||
}
|
||||
|
||||
if (feature.type == mvt_point) {
|
||||
fk->second.points++;
|
||||
} else if (feature.type == mvt_linestring) {
|
||||
fk->second.lines++;
|
||||
} else if (feature.type == mvt_polygon) {
|
||||
fk->second.polygons++;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < properties->length; i++) {
|
||||
int tp = -1;
|
||||
std::string s;
|
||||
|
||||
stringify_value(properties->values[i], tp, s, "Filter output", jp->line, j);
|
||||
|
||||
// Nulls can be excluded here because this is the postfilter
|
||||
// and it is nearly time to create the vector representation
|
||||
|
||||
if (tp >= 0 && tp != mvt_null) {
|
||||
mvt_value v = stringified_to_mvt_value(tp, s.c_str());
|
||||
l->second.tag(feature, std::string(properties->keys[i]->string), v);
|
||||
|
||||
type_and_string attrib;
|
||||
attrib.type = tp;
|
||||
attrib.string = s;
|
||||
|
||||
add_to_file_keys(fk->second.file_keys, std::string(properties->keys[i]->string), attrib);
|
||||
}
|
||||
}
|
||||
|
||||
l->second.features.push_back(feature);
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
}
|
||||
|
||||
json_end(jp);
|
||||
if (fclose(f) != 0) {
|
||||
perror("fclose postfilter output");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::vector<mvt_layer> final;
|
||||
for (auto a : ret) {
|
||||
final.push_back(a.second);
|
||||
}
|
||||
return final;
|
||||
}
|
||||
|
||||
// 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 sf;
|
||||
|
||||
while (1) {
|
||||
json_object *j = json_read(jp);
|
||||
if (j == NULL) {
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "Filter output:%d: %s\n", jp->line, jp->error);
|
||||
if (jp->root != NULL) {
|
||||
json_context(jp->root);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_free(jp->root);
|
||||
sf.t = -1;
|
||||
return sf;
|
||||
}
|
||||
|
||||
json_object *type = json_hash_get(j, "type");
|
||||
if (type == NULL || type->type != JSON_STRING) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(type->string, "Feature") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: filtered feature with no geometry\n", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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\n", jp->line);
|
||||
json_context(j);
|
||||
json_free(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: null geometry (additional not reported)\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (geometry_type->type != JSON_STRING) {
|
||||
fprintf(stderr, "Filter output:%d: geometry type is not a string\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "Filter output:%d: feature without coordinates array\n", jp->line);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int t;
|
||||
for (t = 0; t < GEOM_TYPES; t++) {
|
||||
if (strcmp(geometry_type->string, geometry_names[t]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= GEOM_TYPES) {
|
||||
fprintf(stderr, "Filter output:%d: Can't handle geometry type %s\n", jp->line, geometry_type->string);
|
||||
json_context(j);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
drawvec dv;
|
||||
parse_geometry(t, coordinates, dv, VT_MOVETO, "Filter output", jp->line, j);
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = fix_polygon(dv);
|
||||
}
|
||||
|
||||
// Scale and offset geometry from global to tile
|
||||
double scale = 1LL << geometry_scale;
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
unsigned sx = 0, sy = 0;
|
||||
if (z != 0) {
|
||||
sx = x << (32 - z);
|
||||
sy = y << (32 - z);
|
||||
}
|
||||
dv[i].x = std::round(dv[i].x / scale) * scale - sx;
|
||||
dv[i].y = std::round(dv[i].y / scale) * scale - sy;
|
||||
}
|
||||
|
||||
if (dv.size() > 0) {
|
||||
sf.t = mb_geometry[t];
|
||||
sf.segment = tiling_seg;
|
||||
sf.geometry = dv;
|
||||
sf.seq = 0;
|
||||
sf.index = 0;
|
||||
sf.bbox[0] = sf.bbox[1] = LLONG_MAX;
|
||||
sf.bbox[2] = sf.bbox[3] = LLONG_MIN;
|
||||
sf.extent = 0;
|
||||
sf.metapos = 0;
|
||||
sf.has_id = false;
|
||||
|
||||
std::string layername = "unknown";
|
||||
json_object *tippecanoe = json_hash_get(j, "tippecanoe");
|
||||
if (tippecanoe != NULL) {
|
||||
json_object *layer = json_hash_get(tippecanoe, "layer");
|
||||
if (layer != NULL && layer->type == JSON_STRING) {
|
||||
layername = std::string(layer->string);
|
||||
}
|
||||
|
||||
json_object *index = json_hash_get(tippecanoe, "index");
|
||||
if (index != NULL && index->type == JSON_NUMBER) {
|
||||
sf.index = index->number;
|
||||
}
|
||||
|
||||
json_object *sequence = json_hash_get(tippecanoe, "sequence");
|
||||
if (sequence != NULL && sequence->type == JSON_NUMBER) {
|
||||
sf.seq = sequence->number;
|
||||
}
|
||||
|
||||
json_object *extent = json_hash_get(tippecanoe, "extent");
|
||||
if (extent != NULL && extent->type == JSON_NUMBER) {
|
||||
sf.extent = extent->number;
|
||||
}
|
||||
|
||||
json_object *dropped = json_hash_get(tippecanoe, "dropped");
|
||||
if (dropped != NULL && dropped->type == JSON_TRUE) {
|
||||
sf.dropped = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
if (dv[i].op == VT_MOVETO || dv[i].op == VT_LINETO) {
|
||||
if (dv[i].x < sf.bbox[0]) {
|
||||
sf.bbox[0] = dv[i].x;
|
||||
}
|
||||
if (dv[i].y < sf.bbox[1]) {
|
||||
sf.bbox[1] = dv[i].y;
|
||||
}
|
||||
if (dv[i].x > sf.bbox[2]) {
|
||||
sf.bbox[2] = dv[i].x;
|
||||
}
|
||||
if (dv[i].y > sf.bbox[3]) {
|
||||
sf.bbox[3] = dv[i].y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_object *id = json_hash_get(j, "id");
|
||||
if (id != NULL) {
|
||||
sf.id = atoll(id->string);
|
||||
sf.has_id = true;
|
||||
}
|
||||
|
||||
std::map<std::string, layermap_entry> &layermap = (*layermaps)[tiling_seg];
|
||||
|
||||
if (layermap.count(layername) == 0) {
|
||||
layermap_entry lme = layermap_entry(layermap.size());
|
||||
lme.minzoom = z;
|
||||
lme.maxzoom = z;
|
||||
|
||||
layermap.insert(std::pair<std::string, layermap_entry>(layername, lme));
|
||||
|
||||
if (lme.id >= (*layer_unmaps)[tiling_seg].size()) {
|
||||
(*layer_unmaps)[tiling_seg].resize(lme.id + 1);
|
||||
(*layer_unmaps)[tiling_seg][lme.id] = layername;
|
||||
}
|
||||
}
|
||||
|
||||
auto fk = layermap.find(layername);
|
||||
if (fk == layermap.end()) {
|
||||
fprintf(stderr, "Internal error: layer %s not found\n", layername.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sf.layer = fk->second.id;
|
||||
|
||||
if (z < fk->second.minzoom) {
|
||||
fk->second.minzoom = z;
|
||||
}
|
||||
if (z > fk->second.maxzoom) {
|
||||
fk->second.maxzoom = z;
|
||||
}
|
||||
|
||||
if (!postfilter) {
|
||||
if (sf.t == mvt_point) {
|
||||
fk->second.points++;
|
||||
} else if (sf.t == mvt_linestring) {
|
||||
fk->second.lines++;
|
||||
} else if (sf.t == mvt_polygon) {
|
||||
fk->second.polygons++;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < properties->length; i++) {
|
||||
serial_val v;
|
||||
v.type = -1;
|
||||
|
||||
stringify_value(properties->values[i], v.type, v.s, "Filter output", jp->line, j);
|
||||
|
||||
// Nulls can be excluded here because the expression evaluation filter
|
||||
// would have already run before prefiltering
|
||||
|
||||
if (v.type >= 0 && v.type != mvt_null) {
|
||||
sf.full_keys.push_back(std::string(properties->keys[i]->string));
|
||||
sf.full_values.push_back(v);
|
||||
|
||||
type_and_string attrib;
|
||||
attrib.string = v.s;
|
||||
attrib.type = v.type;
|
||||
|
||||
if (!postfilter) {
|
||||
add_to_file_keys(fk->second.file_keys, std::string(properties->keys[i]->string), attrib);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
return sf;
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
}
|
||||
}
|
||||
|
||||
static pthread_mutex_t pipe_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void setup_filter(const char *filter, int *write_to, int *read_from, pid_t *pid, unsigned z, unsigned x, unsigned y) {
|
||||
// This will create two pipes, a new thread, and a new process.
|
||||
//
|
||||
// The new process will read from one pipe and write to the other, and execute the filter.
|
||||
// The new thread will write the GeoJSON to the pipe that leads to the filter.
|
||||
// The original thread will read the GeoJSON from the filter and convert it back into vector tiles.
|
||||
|
||||
if (pthread_mutex_lock(&pipe_lock) != 0) {
|
||||
perror("pthread_mutex_lock (pipe)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int pipe_orig[2], pipe_filtered[2];
|
||||
if (pipe(pipe_orig) < 0) {
|
||||
perror("pipe (original features)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (pipe(pipe_filtered) < 0) {
|
||||
perror("pipe (filtered features)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string z_str = std::to_string(z);
|
||||
std::string x_str = std::to_string(x);
|
||||
std::string y_str = std::to_string(y);
|
||||
|
||||
*pid = fork();
|
||||
if (*pid < 0) {
|
||||
perror("fork");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (*pid == 0) {
|
||||
// child
|
||||
|
||||
if (dup2(pipe_orig[0], 0) < 0) {
|
||||
perror("dup child stdin");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (dup2(pipe_filtered[1], 1) < 0) {
|
||||
perror("dup child stdout");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(pipe_orig[1]) != 0) {
|
||||
perror("close output to filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(pipe_filtered[0]) != 0) {
|
||||
perror("close input from filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(pipe_orig[0]) != 0) {
|
||||
perror("close dup input of filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(pipe_filtered[1]) != 0) {
|
||||
perror("close dup output of filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// XXX close other fds?
|
||||
|
||||
if (execlp("sh", "sh", "-c", filter, "sh", z_str.c_str(), x_str.c_str(), y_str.c_str(), NULL) != 0) {
|
||||
perror("exec");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
// parent
|
||||
|
||||
if (close(pipe_orig[0]) != 0) {
|
||||
perror("close filter-side reader");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(pipe_filtered[1]) != 0) {
|
||||
perror("close filter-side writer");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fcntl(pipe_orig[1], F_SETFD, FD_CLOEXEC) != 0) {
|
||||
perror("cloxec output to filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fcntl(pipe_filtered[0], F_SETFD, FD_CLOEXEC) != 0) {
|
||||
perror("cloxec input from filter");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pthread_mutex_unlock(&pipe_lock) != 0) {
|
||||
perror("pthread_mutex_unlock (pipe_lock)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
*write_to = pipe_orig[1];
|
||||
*read_from = pipe_filtered[0];
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<mvt_layer> filter_layers(const char *filter, std::vector<mvt_layer> &layers, 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) {
|
||||
int write_to, read_from;
|
||||
pid_t pid;
|
||||
setup_filter(filter, &write_to, &read_from, &pid, z, x, y);
|
||||
|
||||
writer_arg wa;
|
||||
wa.write_to = write_to;
|
||||
wa.layers = &layers;
|
||||
wa.z = z;
|
||||
wa.x = x;
|
||||
wa.y = y;
|
||||
wa.extent = extent;
|
||||
|
||||
pthread_t writer;
|
||||
if (pthread_create(&writer, NULL, run_writer, &wa) != 0) {
|
||||
perror("pthread_create (filter writer)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::vector<mvt_layer> nlayers = parse_layers(read_from, z, x, y, layermaps, tiling_seg, layer_unmaps, extent);
|
||||
|
||||
while (1) {
|
||||
int stat_loc;
|
||||
if (waitpid(pid, &stat_loc, 0) < 0) {
|
||||
perror("waitpid for filter\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void *ret;
|
||||
if (pthread_join(writer, &ret) != 0) {
|
||||
perror("pthread_join filter writer");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return nlayers;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
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);
|
85
pool.cpp
85
pool.cpp
@ -2,43 +2,47 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "memfile.hpp"
|
||||
#include "pool.hpp"
|
||||
|
||||
static unsigned char swizzle[256] = {
|
||||
0x00, 0xBF, 0x18, 0xDE, 0x93, 0xC9, 0xB1, 0x5E, 0xDF, 0xBE, 0x72, 0x5A, 0xBB, 0x42, 0x64, 0xC6,
|
||||
0xD8, 0xB7, 0x15, 0x74, 0x1C, 0x8B, 0x91, 0xF5, 0x29, 0x46, 0xEC, 0x6F, 0xCA, 0x20, 0xF0, 0x06,
|
||||
0x27, 0x61, 0x87, 0xE0, 0x6E, 0x43, 0x50, 0xC5, 0x1B, 0xB4, 0x37, 0xC3, 0x69, 0xA6, 0xEE, 0x80,
|
||||
0xAF, 0x9B, 0xA1, 0x76, 0x23, 0x24, 0x53, 0xF3, 0x5B, 0x65, 0x19, 0xF4, 0xFC, 0xDD, 0x26, 0xE8,
|
||||
0x10, 0xF7, 0xCE, 0x92, 0x48, 0xF6, 0x94, 0x60, 0x07, 0xC4, 0xB9, 0x97, 0x6D, 0xA4, 0x11, 0x0D,
|
||||
0x1F, 0x4D, 0x13, 0xB0, 0x5D, 0xBA, 0x31, 0xD5, 0x8D, 0x51, 0x36, 0x96, 0x7A, 0x03, 0x7F, 0xDA,
|
||||
0x17, 0xDB, 0xD4, 0x83, 0xE2, 0x79, 0x6A, 0xE1, 0x95, 0x38, 0xFF, 0x28, 0xB2, 0xB3, 0xA7, 0xAE,
|
||||
0xF8, 0x54, 0xCC, 0xDC, 0x9A, 0x6B, 0xFB, 0x3F, 0xD7, 0xBC, 0x21, 0xC8, 0x71, 0x09, 0x16, 0xAC,
|
||||
0x3C, 0x8A, 0x62, 0x05, 0xC2, 0x8C, 0x32, 0x4E, 0x35, 0x9C, 0x5F, 0x75, 0xCD, 0x2E, 0xA2, 0x3E,
|
||||
0x1A, 0xC1, 0x8E, 0x14, 0xA0, 0xD3, 0x7D, 0xD9, 0xEB, 0x5C, 0x70, 0xE6, 0x9E, 0x12, 0x3B, 0xEF,
|
||||
0x1E, 0x49, 0xD2, 0x98, 0x39, 0x7E, 0x44, 0x4B, 0x6C, 0x88, 0x02, 0x2C, 0xAD, 0xE5, 0x9F, 0x40,
|
||||
0x7B, 0x4A, 0x3D, 0xA9, 0xAB, 0x0B, 0xD6, 0x2F, 0x90, 0x2A, 0xB6, 0x1D, 0xC7, 0x22, 0x55, 0x34,
|
||||
0x0A, 0xD0, 0xB5, 0x68, 0xE3, 0x59, 0xFD, 0xFA, 0x57, 0x77, 0x25, 0xA3, 0x04, 0xB8, 0x33, 0x89,
|
||||
0x78, 0x82, 0xE4, 0xC0, 0x0E, 0x8F, 0x85, 0xD1, 0x84, 0x08, 0x67, 0x47, 0x9D, 0xCB, 0x58, 0x4C,
|
||||
0xAA, 0xED, 0x52, 0xF2, 0x4F, 0xF1, 0x66, 0xCF, 0xA5, 0x56, 0xEA, 0x7C, 0xE9, 0x63, 0xE7, 0x01,
|
||||
0xF9, 0xFE, 0x0C, 0x99, 0x2D, 0x0F, 0x3A, 0x41, 0x45, 0xA8, 0x30, 0x2B, 0x73, 0xBD, 0x86, 0x81,
|
||||
};
|
||||
|
||||
int swizzlecmp(const char *a, const char *b) {
|
||||
ssize_t alen = strlen(a);
|
||||
ssize_t blen = strlen(b);
|
||||
while (*a || *b) {
|
||||
int aa = swizzle[(unsigned char) *a];
|
||||
int bb = swizzle[(unsigned char) *b];
|
||||
|
||||
if (strcmp(a, b) == 0) {
|
||||
return 0;
|
||||
int cmp = aa - bb;
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
long long hash1 = 0, hash2 = 0;
|
||||
for (ssize_t i = alen - 1; i >= 0; i--) {
|
||||
hash1 = (hash1 * 37 + a[i]) & INT_MAX;
|
||||
}
|
||||
for (ssize_t i = blen - 1; i >= 0; i--) {
|
||||
hash2 = (hash2 * 37 + b[i]) & INT_MAX;
|
||||
}
|
||||
|
||||
int h1 = hash1, h2 = hash2;
|
||||
if (h1 == h2) {
|
||||
return strcmp(a, b);
|
||||
}
|
||||
|
||||
return h1 - h2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type) {
|
||||
unsigned long *sp = &treefile->tree;
|
||||
size_t depth = 0;
|
||||
|
||||
// In typical data, traversal depth generally stays under 2.5x
|
||||
size_t max = 3 * log(treefile->off / sizeof(struct stringpool)) / log(2);
|
||||
if (max < 30) {
|
||||
max = 30;
|
||||
}
|
||||
long long *sp = &treefile->tree;
|
||||
|
||||
while (*sp != 0) {
|
||||
int cmp = swizzlecmp(s, poolfile->map + ((struct stringpool *) (treefile->map + *sp))->off + 1);
|
||||
@ -54,23 +58,6 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
|
||||
} else {
|
||||
return ((struct stringpool *) (treefile->map + *sp))->off;
|
||||
}
|
||||
|
||||
depth++;
|
||||
if (depth > max) {
|
||||
// Search is very deep, so string is probably unique.
|
||||
// Add it to the pool without adding it to the search tree.
|
||||
|
||||
long long off = poolfile->off;
|
||||
if (memfile_write(poolfile, &type, 1) < 0) {
|
||||
perror("memfile write");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
|
||||
perror("memfile write");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return off;
|
||||
}
|
||||
}
|
||||
|
||||
// *sp is probably in the memory-mapped file, and will move if the file grows.
|
||||
@ -91,16 +78,6 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (off >= LONG_MAX || treefile->off >= LONG_MAX) {
|
||||
// Tree or pool is bigger than 2GB
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: string pool is very large.\n");
|
||||
warned = true;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
struct stringpool tsp;
|
||||
tsp.left = 0;
|
||||
tsp.right = 0;
|
||||
|
11
pool.hpp
11
pool.hpp
@ -1,12 +1,7 @@
|
||||
#ifndef POOL_HPP
|
||||
#define POOL_HPP
|
||||
|
||||
struct stringpool {
|
||||
unsigned long left = 0;
|
||||
unsigned long right = 0;
|
||||
unsigned long off = 0;
|
||||
long long left;
|
||||
long long right;
|
||||
long long off;
|
||||
};
|
||||
|
||||
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type);
|
||||
|
||||
#endif
|
||||
|
123
projection.cpp
123
projection.cpp
@ -2,39 +2,18 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <atomic>
|
||||
#include "projection.hpp"
|
||||
|
||||
unsigned long long (*encode_index)(unsigned int wx, unsigned int wy) = NULL;
|
||||
void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy) = NULL;
|
||||
|
||||
struct projection projections[] = {
|
||||
{"EPSG:4326", lonlat2tile, tile2lonlat, "urn:ogc:def:crs:OGC:1.3:CRS84"},
|
||||
{"EPSG:3857", epsg3857totile, tiletoepsg3857, "urn:ogc:def:crs:EPSG::3857"},
|
||||
{NULL, NULL, NULL, NULL},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
struct projection *projection = &projections[0];
|
||||
|
||||
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
||||
void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y) {
|
||||
// Place infinite and NaN coordinates off the edge of the Mercator plane
|
||||
|
||||
int lat_class = fpclassify(lat);
|
||||
int lon_class = fpclassify(lon);
|
||||
bool bad_lon = false;
|
||||
|
||||
if (lat_class == FP_INFINITE || lat_class == FP_NAN) {
|
||||
lat = 89.9;
|
||||
}
|
||||
if (lon_class == FP_INFINITE || lon_class == FP_NAN) {
|
||||
// Keep these far enough from the plane that they don't get
|
||||
// moved back into it by 360-degree offsetting
|
||||
|
||||
lon = 720;
|
||||
bad_lon = true;
|
||||
}
|
||||
|
||||
// Must limit latitude somewhere to prevent overflow.
|
||||
// 89.9 degrees latitude is 0.621 worlds beyond the edge of the flat earth,
|
||||
// hopefully far enough out that there are few expectations about the shape.
|
||||
@ -45,10 +24,10 @@ void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y) {
|
||||
lat = 89.9;
|
||||
}
|
||||
|
||||
if (lon < -360 && !bad_lon) {
|
||||
if (lon < -360) {
|
||||
lon = -360;
|
||||
}
|
||||
if (lon > 360 && !bad_lon) {
|
||||
if (lon > 360) {
|
||||
lon = 360;
|
||||
}
|
||||
|
||||
@ -70,18 +49,6 @@ void tile2lonlat(long long x, long long y, int zoom, double *lon, double *lat) {
|
||||
}
|
||||
|
||||
void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y) {
|
||||
// Place infinite and NaN coordinates off the edge of the Mercator plane
|
||||
|
||||
int iy_class = fpclassify(iy);
|
||||
int ix_class = fpclassify(ix);
|
||||
|
||||
if (iy_class == FP_INFINITE || iy_class == FP_NAN) {
|
||||
iy = 40000000.0;
|
||||
}
|
||||
if (ix_class == FP_INFINITE || ix_class == FP_NAN) {
|
||||
ix = 40000000.0;
|
||||
}
|
||||
|
||||
*x = ix * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31);
|
||||
*y = ((1LL << 32) - 1) - (iy * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31));
|
||||
|
||||
@ -101,60 +68,7 @@ void tiletoepsg3857(long long ix, long long iy, int zoom, double *ox, double *oy
|
||||
*oy = ((1LL << 32) - 1 - iy - (1LL << 31)) * M_PI * 6378137.0 / (1LL << 31);
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Hilbert_curve
|
||||
|
||||
void hilbert_rot(unsigned long long n, unsigned *x, unsigned *y, unsigned long long rx, unsigned long long ry) {
|
||||
if (ry == 0) {
|
||||
if (rx == 1) {
|
||||
*x = n - 1 - *x;
|
||||
*y = n - 1 - *y;
|
||||
}
|
||||
|
||||
unsigned t = *x;
|
||||
*x = *y;
|
||||
*y = t;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long hilbert_xy2d(unsigned long long n, unsigned x, unsigned y) {
|
||||
unsigned long long d = 0;
|
||||
unsigned long long rx, ry;
|
||||
|
||||
for (unsigned long long s = n / 2; s > 0; s /= 2) {
|
||||
rx = (x & s) != 0;
|
||||
ry = (y & s) != 0;
|
||||
|
||||
d += s * s * ((3 * rx) ^ ry);
|
||||
hilbert_rot(s, &x, &y, rx, ry);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void hilbert_d2xy(unsigned long long n, unsigned long long d, unsigned *x, unsigned *y) {
|
||||
unsigned long long rx, ry;
|
||||
unsigned long long t = d;
|
||||
|
||||
*x = *y = 0;
|
||||
for (unsigned long long s = 1; s < n; s *= 2) {
|
||||
rx = 1 & (t / 2);
|
||||
ry = 1 & (t ^ rx);
|
||||
hilbert_rot(s, x, y, rx, ry);
|
||||
*x += s * rx;
|
||||
*y += s * ry;
|
||||
t /= 4;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long encode_hilbert(unsigned int wx, unsigned int wy) {
|
||||
return hilbert_xy2d(1LL << 32, wx, wy);
|
||||
}
|
||||
|
||||
void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy) {
|
||||
hilbert_d2xy(1LL << 32, index, wx, wy);
|
||||
}
|
||||
|
||||
unsigned long long encode_quadkey(unsigned int wx, unsigned int wy) {
|
||||
unsigned long long encode(unsigned int wx, unsigned int wy) {
|
||||
unsigned long long out = 0;
|
||||
|
||||
int i;
|
||||
@ -169,32 +83,13 @@ unsigned long long encode_quadkey(unsigned int wx, unsigned int wy) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::atomic<unsigned char> decodex[256];
|
||||
static std::atomic<unsigned char> decodey[256];
|
||||
|
||||
void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy) {
|
||||
static std::atomic<int> initialized(0);
|
||||
if (!initialized) {
|
||||
for (size_t ix = 0; ix < 256; ix++) {
|
||||
size_t xx = 0, yy = 0;
|
||||
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
xx |= ((ix >> (64 - 2 * (i + 1) + 1)) & 1) << (32 - (i + 1));
|
||||
yy |= ((ix >> (64 - 2 * (i + 1) + 0)) & 1) << (32 - (i + 1));
|
||||
}
|
||||
|
||||
decodex[ix] = xx;
|
||||
decodey[ix] = yy;
|
||||
}
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
void decode(unsigned long long index, unsigned *wx, unsigned *wy) {
|
||||
*wx = *wy = 0;
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
*wx |= ((unsigned) decodex[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
||||
*wy |= ((unsigned) decodey[(index >> (8 * i)) & 0xFF]) << (4 * i);
|
||||
int i;
|
||||
for (i = 0; i < 32; i++) {
|
||||
*wx |= ((index >> (64 - 2 * (i + 1) + 1)) & 1) << (32 - (i + 1));
|
||||
*wy |= ((index >> (64 - 2 * (i + 1) + 0)) & 1) << (32 - (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
#ifndef PROJECTION_HPP
|
||||
#define PROJECTION_HPP
|
||||
|
||||
void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y);
|
||||
void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y);
|
||||
void tile2lonlat(long long x, long long y, int zoom, double *lon, double *lat);
|
||||
void tiletoepsg3857(long long x, long long y, int zoom, double *ox, double *oy);
|
||||
unsigned long long encode(unsigned int wx, unsigned int wy);
|
||||
void decode(unsigned long long index, unsigned *wx, unsigned *wy);
|
||||
void set_projection_or_exit(const char *optarg);
|
||||
|
||||
struct projection {
|
||||
@ -16,14 +15,3 @@ struct projection {
|
||||
|
||||
extern struct projection *projection;
|
||||
extern struct projection projections[];
|
||||
|
||||
extern unsigned long long (*encode_index)(unsigned int wx, unsigned int wy);
|
||||
extern void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy);
|
||||
|
||||
unsigned long long encode_quadkey(unsigned int wx, unsigned int wy);
|
||||
void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy);
|
||||
|
||||
unsigned long long encode_hilbert(unsigned int wx, unsigned int wy);
|
||||
void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy);
|
||||
|
||||
#endif
|
||||
|
@ -16,69 +16,56 @@ documentation.
|
||||
* @brief Contains functions to swap bytes in values (for different endianness).
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
|
||||
#include <protozero/config.hpp>
|
||||
|
||||
namespace protozero {
|
||||
namespace detail {
|
||||
|
||||
inline uint32_t byteswap_impl(uint32_t value) noexcept {
|
||||
/**
|
||||
* Swap N byte value between endianness formats. This template function must
|
||||
* be specialized to actually work.
|
||||
*/
|
||||
template <int N>
|
||||
inline void byteswap(const char* /*data*/, char* /*result*/) {
|
||||
static_assert(N == 1, "Can only swap 4 or 8 byte values");
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap 4 byte value (int32_t, uint32_t, float) between endianness formats.
|
||||
*/
|
||||
template <>
|
||||
inline void byteswap<4>(const char* data, char* result) {
|
||||
#ifdef PROTOZERO_USE_BUILTIN_BSWAP
|
||||
return __builtin_bswap32(value);
|
||||
*reinterpret_cast<uint32_t*>(result) = __builtin_bswap32(*reinterpret_cast<const uint32_t*>(data));
|
||||
#else
|
||||
return ((value & 0xff000000) >> 24) |
|
||||
((value & 0x00ff0000) >> 8) |
|
||||
((value & 0x0000ff00) << 8) |
|
||||
((value & 0x000000ff) << 24);
|
||||
result[3] = data[0];
|
||||
result[2] = data[1];
|
||||
result[1] = data[2];
|
||||
result[0] = data[3];
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint64_t byteswap_impl(uint64_t value) noexcept {
|
||||
/**
|
||||
* Swap 8 byte value (int64_t, uint64_t, double) between endianness formats.
|
||||
*/
|
||||
template <>
|
||||
inline void byteswap<8>(const char* data, char* result) {
|
||||
#ifdef PROTOZERO_USE_BUILTIN_BSWAP
|
||||
return __builtin_bswap64(value);
|
||||
*reinterpret_cast<uint64_t*>(result) = __builtin_bswap64(*reinterpret_cast<const uint64_t*>(data));
|
||||
#else
|
||||
return ((value & 0xff00000000000000ULL) >> 56) |
|
||||
((value & 0x00ff000000000000ULL) >> 40) |
|
||||
((value & 0x0000ff0000000000ULL) >> 24) |
|
||||
((value & 0x000000ff00000000ULL) >> 8) |
|
||||
((value & 0x00000000ff000000ULL) << 8) |
|
||||
((value & 0x0000000000ff0000ULL) << 24) |
|
||||
((value & 0x000000000000ff00ULL) << 40) |
|
||||
((value & 0x00000000000000ffULL) << 56);
|
||||
result[7] = data[0];
|
||||
result[6] = data[1];
|
||||
result[5] = data[2];
|
||||
result[4] = data[3];
|
||||
result[3] = data[4];
|
||||
result[2] = data[5];
|
||||
result[1] = data[6];
|
||||
result[0] = data[7];
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(uint32_t* ptr) noexcept {
|
||||
*ptr = byteswap_impl(*ptr);
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(uint64_t* ptr) noexcept {
|
||||
*ptr = byteswap_impl(*ptr);
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(int32_t* ptr) noexcept {
|
||||
auto bptr = reinterpret_cast<uint32_t*>(ptr);
|
||||
*bptr = byteswap_impl(*bptr);
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(int64_t* ptr) noexcept {
|
||||
auto bptr = reinterpret_cast<uint64_t*>(ptr);
|
||||
*bptr = byteswap_impl(*bptr);
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(float* ptr) noexcept {
|
||||
auto bptr = reinterpret_cast<uint32_t*>(ptr);
|
||||
*bptr = byteswap_impl(*bptr);
|
||||
}
|
||||
|
||||
inline void byteswap_inplace(double* ptr) noexcept {
|
||||
auto bptr = reinterpret_cast<uint64_t*>(ptr);
|
||||
*bptr = byteswap_impl(*bptr);
|
||||
}
|
||||
|
||||
} // end namespace detail
|
||||
} // end namespace protozero
|
||||
|
||||
#endif // PROTOZERO_BYTESWAP_HPP
|
||||
|
@ -35,6 +35,17 @@ documentation.
|
||||
# define PROTOZERO_BYTE_ORDER PROTOZERO_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
// On some ARM machines and depending on compiler settings access to unaligned
|
||||
// floating point values will result in a SIGBUS. Do not use the bare pointers
|
||||
// in this case.
|
||||
#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
|
||||
# if !defined(__arm__) && !defined(_M_ARM)
|
||||
# ifndef PROTOZERO_DO_NOT_USE_BARE_POINTER
|
||||
# define PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Check whether __builtin_bswap is available
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define PROTOZERO_USE_BUILTIN_BSWAP
|
||||
|
@ -29,7 +29,7 @@ namespace protozero {
|
||||
*/
|
||||
struct exception : std::exception {
|
||||
/// Returns the explanatory string.
|
||||
const char* what() const noexcept override { return "pbf exception"; }
|
||||
const char *what() const noexcept override { return "pbf exception"; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -38,7 +38,7 @@ struct exception : std::exception {
|
||||
*/
|
||||
struct varint_too_long_exception : exception {
|
||||
/// Returns the explanatory string.
|
||||
const char* what() const noexcept override { return "varint too long exception"; }
|
||||
const char *what() const noexcept override { return "varint too long exception"; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@ struct varint_too_long_exception : exception {
|
||||
*/
|
||||
struct unknown_pbf_wire_type_exception : exception {
|
||||
/// Returns the explanatory string.
|
||||
const char* what() const noexcept override { return "unknown pbf field type exception"; }
|
||||
const char *what() const noexcept override { return "unknown pbf field type exception"; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -60,7 +60,7 @@ struct unknown_pbf_wire_type_exception : exception {
|
||||
*/
|
||||
struct end_of_buffer_exception : exception {
|
||||
/// Returns the explanatory string.
|
||||
const char* what() const noexcept override { return "end of buffer exception"; }
|
||||
const char *what() const noexcept override { return "end of buffer exception"; }
|
||||
};
|
||||
|
||||
} // end namespace protozero
|
||||
|
@ -1,328 +0,0 @@
|
||||
#ifndef PROTOZERO_ITERATORS_HPP
|
||||
#define PROTOZERO_ITERATORS_HPP
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
protozero - Minimalistic protocol buffer decoder and encoder in C++.
|
||||
|
||||
This file is from https://github.com/mapbox/protozero where you can find more
|
||||
documentation.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file iterators.hpp
|
||||
*
|
||||
* @brief Contains the iterators for access to packed repeated fields.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
#include <protozero/config.hpp>
|
||||
#include <protozero/varint.hpp>
|
||||
|
||||
#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
|
||||
# include <protozero/byteswap.hpp>
|
||||
#endif
|
||||
|
||||
namespace protozero {
|
||||
|
||||
/**
|
||||
* A range of iterators based on std::pair. Created from beginning and
|
||||
* end iterators. Used as a return type from some pbf_reader methods
|
||||
* that is easy to use with range-based for loops.
|
||||
*/
|
||||
template <typename T, typename P = std::pair<T, T>>
|
||||
class iterator_range :
|
||||
#ifdef PROTOZERO_STRICT_API
|
||||
protected
|
||||
#else
|
||||
public
|
||||
#endif
|
||||
P {
|
||||
|
||||
public:
|
||||
|
||||
/// The type of the iterators in this range.
|
||||
using iterator = T;
|
||||
|
||||
/// The value type of the underlying iterator.
|
||||
using value_type = typename std::iterator_traits<T>::value_type;
|
||||
|
||||
/**
|
||||
* Default constructor. Create empty iterator_range.
|
||||
*/
|
||||
constexpr iterator_range() :
|
||||
P(iterator{}, iterator{}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create iterator range from two iterators.
|
||||
*
|
||||
* @param first_iterator Iterator to beginning or range.
|
||||
* @param last_iterator Iterator to end or range.
|
||||
*/
|
||||
constexpr iterator_range(iterator&& first_iterator, iterator&& last_iterator) :
|
||||
P(std::forward<iterator>(first_iterator),
|
||||
std::forward<iterator>(last_iterator)) {
|
||||
}
|
||||
|
||||
/// Return iterator to beginning of range.
|
||||
constexpr iterator begin() const noexcept {
|
||||
return this->first;
|
||||
}
|
||||
|
||||
/// Return iterator to end of range.
|
||||
constexpr iterator end() const noexcept {
|
||||
return this->second;
|
||||
}
|
||||
|
||||
/// Return iterator to beginning of range.
|
||||
constexpr iterator cbegin() const noexcept {
|
||||
return this->first;
|
||||
}
|
||||
|
||||
/// Return iterator to end of range.
|
||||
constexpr iterator cend() const noexcept {
|
||||
return this->second;
|
||||
}
|
||||
|
||||
/// Return true if this range is empty.
|
||||
constexpr std::size_t empty() const noexcept {
|
||||
return begin() == end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element at the beginning of the range.
|
||||
*
|
||||
* @pre Range must not be empty.
|
||||
*/
|
||||
value_type front() const {
|
||||
protozero_assert(!empty());
|
||||
return *(this->first);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance beginning of range by one.
|
||||
*
|
||||
* @pre Range must not be empty.
|
||||
*/
|
||||
void drop_front() {
|
||||
protozero_assert(!empty());
|
||||
++this->first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the contents of this range with the other.
|
||||
*
|
||||
* @param other Other range to swap data with.
|
||||
*/
|
||||
void swap(iterator_range& other) noexcept {
|
||||
using std::swap;
|
||||
swap(this->first, other.first);
|
||||
swap(this->second, other.second);
|
||||
}
|
||||
|
||||
}; // struct iterator_range
|
||||
|
||||
/**
|
||||
* Swap two iterator_ranges.
|
||||
*
|
||||
* @param lhs First range.
|
||||
* @param rhs Second range.
|
||||
*/
|
||||
template <typename T>
|
||||
inline void swap(iterator_range<T>& lhs, iterator_range<T>& rhs) noexcept {
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* A forward iterator used for accessing packed repeated fields of fixed
|
||||
* length (fixed32, sfixed32, float, double).
|
||||
*/
|
||||
template <typename T>
|
||||
class const_fixed_iterator {
|
||||
|
||||
/// Pointer to current iterator position
|
||||
const char* m_data;
|
||||
|
||||
/// Pointer to end iterator position
|
||||
const char* m_end;
|
||||
|
||||
public:
|
||||
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_fixed_iterator() noexcept :
|
||||
m_data(nullptr),
|
||||
m_end(nullptr) {
|
||||
}
|
||||
|
||||
const_fixed_iterator(const char* data, const char* end) noexcept :
|
||||
m_data(data),
|
||||
m_end(end) {
|
||||
}
|
||||
|
||||
const_fixed_iterator(const const_fixed_iterator&) noexcept = default;
|
||||
const_fixed_iterator(const_fixed_iterator&&) noexcept = default;
|
||||
|
||||
const_fixed_iterator& operator=(const const_fixed_iterator&) noexcept = default;
|
||||
const_fixed_iterator& operator=(const_fixed_iterator&&) noexcept = default;
|
||||
|
||||
~const_fixed_iterator() noexcept = default;
|
||||
|
||||
value_type operator*() const {
|
||||
value_type result;
|
||||
std::memcpy(&result, m_data, sizeof(value_type));
|
||||
#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
|
||||
detail::byteswap_inplace(&result);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
const_fixed_iterator& operator++() {
|
||||
m_data += sizeof(value_type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_fixed_iterator operator++(int) {
|
||||
const const_fixed_iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator==(const const_fixed_iterator& rhs) const noexcept {
|
||||
return m_data == rhs.m_data && m_end == rhs.m_end;
|
||||
}
|
||||
|
||||
bool operator!=(const const_fixed_iterator& rhs) const noexcept {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
}; // class const_fixed_iterator
|
||||
|
||||
/**
|
||||
* A forward iterator used for accessing packed repeated varint fields
|
||||
* (int32, uint32, int64, uint64, bool, enum).
|
||||
*/
|
||||
template <typename T>
|
||||
class const_varint_iterator {
|
||||
|
||||
protected:
|
||||
|
||||
/// Pointer to current iterator position
|
||||
const char* m_data;
|
||||
|
||||
/// Pointer to end iterator position
|
||||
const char* m_end;
|
||||
|
||||
public:
|
||||
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_varint_iterator() noexcept :
|
||||
m_data(nullptr),
|
||||
m_end(nullptr) {
|
||||
}
|
||||
|
||||
const_varint_iterator(const char* data, const char* end) noexcept :
|
||||
m_data(data),
|
||||
m_end(end) {
|
||||
}
|
||||
|
||||
const_varint_iterator(const const_varint_iterator&) noexcept = default;
|
||||
const_varint_iterator(const_varint_iterator&&) noexcept = default;
|
||||
|
||||
const_varint_iterator& operator=(const const_varint_iterator&) noexcept = default;
|
||||
const_varint_iterator& operator=(const_varint_iterator&&) noexcept = default;
|
||||
|
||||
~const_varint_iterator() noexcept = default;
|
||||
|
||||
value_type operator*() const {
|
||||
const char* d = m_data; // will be thrown away
|
||||
return static_cast<value_type>(decode_varint(&d, m_end));
|
||||
}
|
||||
|
||||
const_varint_iterator& operator++() {
|
||||
skip_varint(&m_data, m_end);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_varint_iterator operator++(int) {
|
||||
const const_varint_iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator==(const const_varint_iterator& rhs) const noexcept {
|
||||
return m_data == rhs.m_data && m_end == rhs.m_end;
|
||||
}
|
||||
|
||||
bool operator!=(const const_varint_iterator& rhs) const noexcept {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
}; // class const_varint_iterator
|
||||
|
||||
/**
|
||||
* A forward iterator used for accessing packed repeated svarint fields
|
||||
* (sint32, sint64).
|
||||
*/
|
||||
template <typename T>
|
||||
class const_svarint_iterator : public const_varint_iterator<T> {
|
||||
|
||||
public:
|
||||
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_svarint_iterator() noexcept :
|
||||
const_varint_iterator<T>() {
|
||||
}
|
||||
|
||||
const_svarint_iterator(const char* data, const char* end) noexcept :
|
||||
const_varint_iterator<T>(data, end) {
|
||||
}
|
||||
|
||||
const_svarint_iterator(const const_svarint_iterator&) = default;
|
||||
const_svarint_iterator(const_svarint_iterator&&) = default;
|
||||
|
||||
const_svarint_iterator& operator=(const const_svarint_iterator&) = default;
|
||||
const_svarint_iterator& operator=(const_svarint_iterator&&) = default;
|
||||
|
||||
~const_svarint_iterator() = default;
|
||||
|
||||
value_type operator*() const {
|
||||
const char* d = this->m_data; // will be thrown away
|
||||
return static_cast<value_type>(decode_zigzag64(decode_varint(&d, this->m_end)));
|
||||
}
|
||||
|
||||
const_svarint_iterator& operator++() {
|
||||
skip_varint(&this->m_data, this->m_end);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_svarint_iterator operator++(int) {
|
||||
const const_svarint_iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
}; // class const_svarint_iterator
|
||||
|
||||
} // end namespace protozero
|
||||
|
||||
#endif // PROTOZERO_ITERATORS_HPP
|
@ -18,8 +18,8 @@ documentation.
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <protozero/pbf_writer.hpp>
|
||||
#include <protozero/types.hpp>
|
||||
#include <protozero/pbf_writer.hpp>
|
||||
|
||||
namespace protozero {
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
|
||||
using enum_type = T;
|
||||
|
||||
explicit pbf_builder(std::string& data) noexcept :
|
||||
pbf_builder(std::string& data) noexcept :
|
||||
pbf_writer(data) {
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public:
|
||||
|
||||
/// @cond INTERNAL
|
||||
#define PROTOZERO_WRITER_WRAP_ADD_SCALAR(name, type) \
|
||||
void add_##name(T tag, type value) { \
|
||||
inline void add_##name(T tag, type value) { \
|
||||
pbf_writer::add_##name(pbf_tag_type(tag), value); \
|
||||
}
|
||||
|
||||
@ -79,59 +79,38 @@ public:
|
||||
#undef PROTOZERO_WRITER_WRAP_ADD_SCALAR
|
||||
/// @endcond
|
||||
|
||||
void add_bytes(T tag, const char* value, std::size_t size) {
|
||||
inline void add_bytes(T tag, const char* value, std::size_t size) {
|
||||
pbf_writer::add_bytes(pbf_tag_type(tag), value, size);
|
||||
}
|
||||
|
||||
void add_bytes(T tag, const data_view& value) {
|
||||
inline void add_bytes(T tag, const std::string& value) {
|
||||
pbf_writer::add_bytes(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_bytes(T tag, const std::string& value) {
|
||||
pbf_writer::add_bytes(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_bytes(T tag, const char* value) {
|
||||
pbf_writer::add_bytes(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void add_bytes_vectored(T tag, Ts&&... values) {
|
||||
pbf_writer::add_bytes_vectored(pbf_tag_type(tag), std::forward<Ts>(values)...);
|
||||
}
|
||||
|
||||
void add_string(T tag, const char* value, std::size_t size) {
|
||||
inline void add_string(T tag, const char* value, std::size_t size) {
|
||||
pbf_writer::add_string(pbf_tag_type(tag), value, size);
|
||||
}
|
||||
|
||||
void add_string(T tag, const data_view& value) {
|
||||
inline void add_string(T tag, const std::string& value) {
|
||||
pbf_writer::add_string(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_string(T tag, const std::string& value) {
|
||||
inline void add_string(T tag, const char* value) {
|
||||
pbf_writer::add_string(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_string(T tag, const char* value) {
|
||||
pbf_writer::add_string(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_message(T tag, const char* value, std::size_t size) {
|
||||
inline void add_message(T tag, const char* value, std::size_t size) {
|
||||
pbf_writer::add_message(pbf_tag_type(tag), value, size);
|
||||
}
|
||||
|
||||
void add_message(T tag, const data_view& value) {
|
||||
pbf_writer::add_message(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
void add_message(T tag, const std::string& value) {
|
||||
inline void add_message(T tag, const std::string& value) {
|
||||
pbf_writer::add_message(pbf_tag_type(tag), value);
|
||||
}
|
||||
|
||||
/// @cond INTERNAL
|
||||
#define PROTOZERO_WRITER_WRAP_ADD_PACKED(name) \
|
||||
template <typename InputIterator> \
|
||||
void add_packed_##name(T tag, InputIterator first, InputIterator last) { \
|
||||
inline void add_packed_##name(T tag, InputIterator first, InputIterator last) { \
|
||||
pbf_writer::add_packed_##name(pbf_tag_type(tag), first, last); \
|
||||
}
|
||||
|
||||
@ -153,7 +132,7 @@ public:
|
||||
#undef PROTOZERO_WRITER_WRAP_ADD_PACKED
|
||||
/// @endcond
|
||||
|
||||
}; // class pbf_builder
|
||||
};
|
||||
|
||||
} // end namespace protozero
|
||||
|
||||
|
@ -13,7 +13,7 @@ documentation.
|
||||
/**
|
||||
* @file pbf_message.hpp
|
||||
*
|
||||
* @brief Contains the pbf_message template class.
|
||||
* @brief Contains the pbf_message class.
|
||||
*/
|
||||
|
||||
#include <type_traits>
|
||||
@ -75,23 +75,19 @@ public:
|
||||
pbf_reader(std::forward<Args>(args)...) {
|
||||
}
|
||||
|
||||
bool next() {
|
||||
inline bool next() {
|
||||
return pbf_reader::next();
|
||||
}
|
||||
|
||||
bool next(T next_tag) {
|
||||
return pbf_reader::next(pbf_tag_type(next_tag));
|
||||
inline bool next(T tag) {
|
||||
return pbf_reader::next(pbf_tag_type(tag));
|
||||
}
|
||||
|
||||
bool next(T next_tag, pbf_wire_type type) {
|
||||
return pbf_reader::next(pbf_tag_type(next_tag), type);
|
||||
}
|
||||
|
||||
T tag() const noexcept {
|
||||
inline T tag() const noexcept {
|
||||
return T(pbf_reader::tag());
|
||||
}
|
||||
|
||||
}; // class pbf_message
|
||||
};
|
||||
|
||||
} // end namespace protozero
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,6 @@ documentation.
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <protozero/config.hpp>
|
||||
#include <protozero/types.hpp>
|
||||
@ -69,35 +68,38 @@ class pbf_writer {
|
||||
// parent to the position where the data of the submessage is written to.
|
||||
std::size_t m_pos = 0;
|
||||
|
||||
void add_varint(uint64_t value) {
|
||||
inline void add_varint(uint64_t value) {
|
||||
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
|
||||
protozero_assert(m_data);
|
||||
write_varint(std::back_inserter(*m_data), value);
|
||||
}
|
||||
|
||||
void add_field(pbf_tag_type tag, pbf_wire_type type) {
|
||||
inline void add_field(pbf_tag_type tag, pbf_wire_type type) {
|
||||
protozero_assert(((tag > 0 && tag < 19000) || (tag > 19999 && tag <= ((1 << 29) - 1))) && "tag out of range");
|
||||
const uint32_t b = (tag << 3) | uint32_t(type);
|
||||
uint32_t b = (tag << 3) | uint32_t(type);
|
||||
add_varint(b);
|
||||
}
|
||||
|
||||
void add_tagged_varint(pbf_tag_type tag, uint64_t value) {
|
||||
inline void add_tagged_varint(pbf_tag_type tag, uint64_t value) {
|
||||
add_field(tag, pbf_wire_type::varint);
|
||||
add_varint(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_fixed(T value) {
|
||||
inline void add_fixed(T value) {
|
||||
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
|
||||
protozero_assert(m_data);
|
||||
#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
|
||||
detail::byteswap_inplace(&value);
|
||||
#endif
|
||||
#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
|
||||
m_data->append(reinterpret_cast<const char*>(&value), sizeof(T));
|
||||
#else
|
||||
auto size = m_data->size();
|
||||
m_data->resize(size + sizeof(T));
|
||||
byteswap<sizeof(T)>(reinterpret_cast<const char*>(&value), const_cast<char*>(m_data->data() + size));
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T, typename It>
|
||||
void add_packed_fixed(pbf_tag_type tag, It first, It last, std::input_iterator_tag) {
|
||||
inline void add_packed_fixed(pbf_tag_type tag, It first, It last, std::input_iterator_tag) {
|
||||
if (first == last) {
|
||||
return;
|
||||
}
|
||||
@ -110,12 +112,12 @@ class pbf_writer {
|
||||
}
|
||||
|
||||
template <typename T, typename It>
|
||||
void add_packed_fixed(pbf_tag_type tag, It first, It last, std::forward_iterator_tag) {
|
||||
inline void add_packed_fixed(pbf_tag_type tag, It first, It last, std::forward_iterator_tag) {
|
||||
if (first == last) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto length = std::distance(first, last);
|
||||
auto length = std::distance(first, last);
|
||||
add_length_varint(tag, sizeof(T) * pbf_length_type(length));
|
||||
reserve(sizeof(T) * std::size_t(length));
|
||||
|
||||
@ -125,7 +127,7 @@ class pbf_writer {
|
||||
}
|
||||
|
||||
template <typename It>
|
||||
void add_packed_varint(pbf_tag_type tag, It first, It last) {
|
||||
inline void add_packed_varint(pbf_tag_type tag, It first, It last) {
|
||||
if (first == last) {
|
||||
return;
|
||||
}
|
||||
@ -138,7 +140,7 @@ class pbf_writer {
|
||||
}
|
||||
|
||||
template <typename It>
|
||||
void add_packed_svarint(pbf_tag_type tag, It first, It last) {
|
||||
inline void add_packed_svarint(pbf_tag_type tag, It first, It last) {
|
||||
if (first == last) {
|
||||
return;
|
||||
}
|
||||
@ -153,18 +155,14 @@ class pbf_writer {
|
||||
// The number of bytes to reserve for the varint holding the length of
|
||||
// a length-delimited field. The length has to fit into pbf_length_type,
|
||||
// and a varint needs 8 bit for every 7 bit.
|
||||
enum constant_reserve_bytes : int {
|
||||
reserve_bytes = sizeof(pbf_length_type) * 8 / 7 + 1
|
||||
};
|
||||
static const int reserve_bytes = sizeof(pbf_length_type) * 8 / 7 + 1;
|
||||
|
||||
// If m_rollpack_pos is set to this special value, it means that when
|
||||
// the submessage is closed, nothing needs to be done, because the length
|
||||
// of the submessage has already been written correctly.
|
||||
enum constant_size_is_known : std::size_t {
|
||||
size_is_known = std::numeric_limits<std::size_t>::max()
|
||||
};
|
||||
static const std::size_t size_is_known = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
void open_submessage(pbf_tag_type tag, std::size_t size) {
|
||||
inline void open_submessage(pbf_tag_type tag, std::size_t size) {
|
||||
protozero_assert(m_pos == 0);
|
||||
protozero_assert(m_data);
|
||||
if (size == 0) {
|
||||
@ -179,7 +177,7 @@ class pbf_writer {
|
||||
m_pos = m_data->size();
|
||||
}
|
||||
|
||||
void rollback_submessage() {
|
||||
inline void rollback_submessage() {
|
||||
protozero_assert(m_pos != 0);
|
||||
protozero_assert(m_rollback_pos != size_is_known);
|
||||
protozero_assert(m_data);
|
||||
@ -187,20 +185,20 @@ class pbf_writer {
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
void commit_submessage() {
|
||||
inline void commit_submessage() {
|
||||
protozero_assert(m_pos != 0);
|
||||
protozero_assert(m_rollback_pos != size_is_known);
|
||||
protozero_assert(m_data);
|
||||
const auto length = pbf_length_type(m_data->size() - m_pos);
|
||||
auto length = pbf_length_type(m_data->size() - m_pos);
|
||||
|
||||
protozero_assert(m_data->size() >= m_pos - reserve_bytes);
|
||||
const auto n = write_varint(m_data->begin() + long(m_pos) - reserve_bytes, length);
|
||||
auto n = write_varint(m_data->begin() + long(m_pos) - reserve_bytes, length);
|
||||
|
||||
m_data->erase(m_data->begin() + long(m_pos) - reserve_bytes + n, m_data->begin() + long(m_pos));
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
void close_submessage() {
|
||||
inline void close_submessage() {
|
||||
protozero_assert(m_data);
|
||||
if (m_pos == 0 || m_rollback_pos == size_is_known) {
|
||||
return;
|
||||
@ -212,7 +210,7 @@ class pbf_writer {
|
||||
}
|
||||
}
|
||||
|
||||
void add_length_varint(pbf_tag_type tag, pbf_length_type length) {
|
||||
inline void add_length_varint(pbf_tag_type tag, pbf_length_type length) {
|
||||
add_field(tag, pbf_wire_type::length_delimited);
|
||||
add_varint(length);
|
||||
}
|
||||
@ -224,18 +222,20 @@ public:
|
||||
* stores a reference to that string and adds all data to it. The string
|
||||
* doesn't have to be empty. The pbf_writer will just append data.
|
||||
*/
|
||||
explicit pbf_writer(std::string& data) noexcept :
|
||||
inline explicit pbf_writer(std::string& data) noexcept :
|
||||
m_data(&data),
|
||||
m_parent_writer(nullptr) {
|
||||
m_parent_writer(nullptr),
|
||||
m_pos(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a writer without a data store. In this form the writer can not
|
||||
* be used!
|
||||
*/
|
||||
pbf_writer() noexcept :
|
||||
inline pbf_writer() noexcept :
|
||||
m_data(nullptr),
|
||||
m_parent_writer(nullptr) {
|
||||
m_parent_writer(nullptr),
|
||||
m_pos(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,9 +248,10 @@ public:
|
||||
* Setting this allows some optimizations but is only possible in
|
||||
* a few very specific cases.
|
||||
*/
|
||||
pbf_writer(pbf_writer& parent_writer, pbf_tag_type tag, std::size_t size=0) :
|
||||
inline pbf_writer(pbf_writer& parent_writer, pbf_tag_type tag, std::size_t size=0) :
|
||||
m_data(parent_writer.m_data),
|
||||
m_parent_writer(&parent_writer) {
|
||||
m_parent_writer(&parent_writer),
|
||||
m_pos(0) {
|
||||
m_parent_writer->open_submessage(tag, size);
|
||||
}
|
||||
|
||||
@ -261,30 +262,17 @@ public:
|
||||
pbf_writer& operator=(const pbf_writer&) noexcept = default;
|
||||
|
||||
/// A pbf_writer object can be moved
|
||||
pbf_writer(pbf_writer&&) noexcept = default;
|
||||
inline pbf_writer(pbf_writer&&) noexcept = default;
|
||||
|
||||
/// A pbf_writer object can be moved
|
||||
pbf_writer& operator=(pbf_writer&&) noexcept = default;
|
||||
inline pbf_writer& operator=(pbf_writer&&) noexcept = default;
|
||||
|
||||
~pbf_writer() {
|
||||
inline ~pbf_writer() {
|
||||
if (m_parent_writer) {
|
||||
m_parent_writer->close_submessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the contents of this object with the other.
|
||||
*
|
||||
* @param other Other object to swap data with.
|
||||
*/
|
||||
void swap(pbf_writer& other) noexcept {
|
||||
using std::swap;
|
||||
swap(m_data, other.m_data);
|
||||
swap(m_parent_writer, other.m_parent_writer);
|
||||
swap(m_rollback_pos, other.m_rollback_pos);
|
||||
swap(m_pos, other.m_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve size bytes in the underlying message store in addition to
|
||||
* whatever the message store already holds. So unlike
|
||||
@ -298,14 +286,7 @@ public:
|
||||
m_data->reserve(m_data->size() + size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel writing of this submessage. The complete submessage will be
|
||||
* removed as if it was never created and no fields were added.
|
||||
*
|
||||
* @pre Must be a pbf_writer of a submessage, ie one opened with the
|
||||
* pbf_writer constructor taking a parent message.
|
||||
*/
|
||||
void rollback() {
|
||||
inline void rollback() {
|
||||
protozero_assert(m_parent_writer && "you can't call rollback() on a pbf_writer without a parent");
|
||||
protozero_assert(m_pos == 0 && "you can't call rollback() on a pbf_writer that has an open nested submessage");
|
||||
m_parent_writer->rollback_submessage();
|
||||
@ -323,7 +304,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_bool(pbf_tag_type tag, bool value) {
|
||||
inline void add_bool(pbf_tag_type tag, bool value) {
|
||||
add_field(tag, pbf_wire_type::varint);
|
||||
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
|
||||
protozero_assert(m_data);
|
||||
@ -336,7 +317,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_enum(pbf_tag_type tag, int32_t value) {
|
||||
inline void add_enum(pbf_tag_type tag, int32_t value) {
|
||||
add_tagged_varint(tag, uint64_t(value));
|
||||
}
|
||||
|
||||
@ -346,7 +327,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_int32(pbf_tag_type tag, int32_t value) {
|
||||
inline void add_int32(pbf_tag_type tag, int32_t value) {
|
||||
add_tagged_varint(tag, uint64_t(value));
|
||||
}
|
||||
|
||||
@ -356,7 +337,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_sint32(pbf_tag_type tag, int32_t value) {
|
||||
inline void add_sint32(pbf_tag_type tag, int32_t value) {
|
||||
add_tagged_varint(tag, encode_zigzag32(value));
|
||||
}
|
||||
|
||||
@ -366,7 +347,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_uint32(pbf_tag_type tag, uint32_t value) {
|
||||
inline void add_uint32(pbf_tag_type tag, uint32_t value) {
|
||||
add_tagged_varint(tag, value);
|
||||
}
|
||||
|
||||
@ -376,7 +357,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_int64(pbf_tag_type tag, int64_t value) {
|
||||
inline void add_int64(pbf_tag_type tag, int64_t value) {
|
||||
add_tagged_varint(tag, uint64_t(value));
|
||||
}
|
||||
|
||||
@ -386,7 +367,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_sint64(pbf_tag_type tag, int64_t value) {
|
||||
inline void add_sint64(pbf_tag_type tag, int64_t value) {
|
||||
add_tagged_varint(tag, encode_zigzag64(value));
|
||||
}
|
||||
|
||||
@ -396,7 +377,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_uint64(pbf_tag_type tag, uint64_t value) {
|
||||
inline void add_uint64(pbf_tag_type tag, uint64_t value) {
|
||||
add_tagged_varint(tag, value);
|
||||
}
|
||||
|
||||
@ -406,7 +387,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_fixed32(pbf_tag_type tag, uint32_t value) {
|
||||
inline void add_fixed32(pbf_tag_type tag, uint32_t value) {
|
||||
add_field(tag, pbf_wire_type::fixed32);
|
||||
add_fixed<uint32_t>(value);
|
||||
}
|
||||
@ -417,7 +398,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_sfixed32(pbf_tag_type tag, int32_t value) {
|
||||
inline void add_sfixed32(pbf_tag_type tag, int32_t value) {
|
||||
add_field(tag, pbf_wire_type::fixed32);
|
||||
add_fixed<int32_t>(value);
|
||||
}
|
||||
@ -428,7 +409,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_fixed64(pbf_tag_type tag, uint64_t value) {
|
||||
inline void add_fixed64(pbf_tag_type tag, uint64_t value) {
|
||||
add_field(tag, pbf_wire_type::fixed64);
|
||||
add_fixed<uint64_t>(value);
|
||||
}
|
||||
@ -439,7 +420,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_sfixed64(pbf_tag_type tag, int64_t value) {
|
||||
inline void add_sfixed64(pbf_tag_type tag, int64_t value) {
|
||||
add_field(tag, pbf_wire_type::fixed64);
|
||||
add_fixed<int64_t>(value);
|
||||
}
|
||||
@ -450,7 +431,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_float(pbf_tag_type tag, float value) {
|
||||
inline void add_float(pbf_tag_type tag, float value) {
|
||||
add_field(tag, pbf_wire_type::fixed32);
|
||||
add_fixed<float>(value);
|
||||
}
|
||||
@ -461,7 +442,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_double(pbf_tag_type tag, double value) {
|
||||
inline void add_double(pbf_tag_type tag, double value) {
|
||||
add_field(tag, pbf_wire_type::fixed64);
|
||||
add_fixed<double>(value);
|
||||
}
|
||||
@ -473,7 +454,7 @@ public:
|
||||
* @param value Pointer to value to be written
|
||||
* @param size Number of bytes to be written
|
||||
*/
|
||||
void add_bytes(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
inline void add_bytes(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
|
||||
protozero_assert(m_data);
|
||||
protozero_assert(size <= std::numeric_limits<pbf_length_type>::max());
|
||||
@ -487,62 +468,10 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_bytes(pbf_tag_type tag, const data_view& value) {
|
||||
inline void add_bytes(pbf_tag_type tag, const std::string& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "bytes" field to data.
|
||||
*
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_bytes(pbf_tag_type tag, const std::string& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "bytes" field to data. Bytes from the value are written until
|
||||
* a null byte is encountered. The null byte is not added.
|
||||
*
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Pointer to zero-delimited value to be written
|
||||
*/
|
||||
void add_bytes(pbf_tag_type tag, const char* value) {
|
||||
add_bytes(tag, value, std::strlen(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "bytes" field to data using vectored input. All the data in the
|
||||
* 2nd and further arguments is "concatenated" with only a single copy
|
||||
* into the final buffer.
|
||||
*
|
||||
* This will work with objects of any type supporting the data() and
|
||||
* size() methods like std::string or protozero::data_view.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* std::string data1 = "abc";
|
||||
* std::string data2 = "xyz";
|
||||
* writer.add_bytes_vectored(1, data1, data2);
|
||||
* @endcode
|
||||
*
|
||||
* @tparam Ts List of types supporting data() and size() methods.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param values List of objects of types Ts with data to be appended.
|
||||
*/
|
||||
template <typename... Ts>
|
||||
void add_bytes_vectored(pbf_tag_type tag, Ts&&... values) {
|
||||
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
|
||||
protozero_assert(m_data);
|
||||
size_t sum_size = 0;
|
||||
(void)std::initializer_list<size_t>{sum_size += values.size()...};
|
||||
protozero_assert(sum_size <= std::numeric_limits<pbf_length_type>::max());
|
||||
add_length_varint(tag, pbf_length_type(sum_size));
|
||||
m_data->reserve(m_data->size() + sum_size);
|
||||
(void)std::initializer_list<int>{(m_data->append(values.data(), values.size()), 0)...};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "string" field to data.
|
||||
*
|
||||
@ -550,7 +479,7 @@ public:
|
||||
* @param value Pointer to value to be written
|
||||
* @param size Number of bytes to be written
|
||||
*/
|
||||
void add_string(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
inline void add_string(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
add_bytes(tag, value, size);
|
||||
}
|
||||
|
||||
@ -560,17 +489,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_string(pbf_tag_type tag, const data_view& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "string" field to data.
|
||||
*
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written
|
||||
*/
|
||||
void add_string(pbf_tag_type tag, const std::string& value) {
|
||||
inline void add_string(pbf_tag_type tag, const std::string& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
@ -581,7 +500,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Pointer to value to be written
|
||||
*/
|
||||
void add_string(pbf_tag_type tag, const char* value) {
|
||||
inline void add_string(pbf_tag_type tag, const char* value) {
|
||||
add_bytes(tag, value, std::strlen(value));
|
||||
}
|
||||
|
||||
@ -592,7 +511,7 @@ public:
|
||||
* @param value Pointer to message to be written
|
||||
* @param size Length of the message
|
||||
*/
|
||||
void add_message(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
inline void add_message(pbf_tag_type tag, const char* value, std::size_t size) {
|
||||
add_bytes(tag, value, size);
|
||||
}
|
||||
|
||||
@ -602,17 +521,7 @@ public:
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written. The value must be a complete message.
|
||||
*/
|
||||
void add_message(pbf_tag_type tag, const data_view& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "message" field to data.
|
||||
*
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param value Value to be written. The value must be a complete message.
|
||||
*/
|
||||
void add_message(pbf_tag_type tag, const std::string& value) {
|
||||
inline void add_message(pbf_tag_type tag, const std::string& value) {
|
||||
add_bytes(tag, value.data(), value.size());
|
||||
}
|
||||
|
||||
@ -626,126 +535,126 @@ public:
|
||||
/**
|
||||
* Add "repeated packed bool" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to bool.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_bool(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_bool(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed enum" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_enum(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_enum(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed int32" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_int32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_int32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed sint32" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_sint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_sint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_svarint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed uint32" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to uint32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_uint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_uint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed int64" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int64_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_int64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_int64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed sint64" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int64_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_sint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_sint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_svarint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed uint64" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to uint64_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_uint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_uint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_varint(tag, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "repeated packed fixed32" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to uint32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_fixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_fixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<uint32_t, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -753,14 +662,14 @@ public:
|
||||
/**
|
||||
* Add "repeated packed sfixed32" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int32_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_sfixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_sfixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<int32_t, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -768,14 +677,14 @@ public:
|
||||
/**
|
||||
* Add "repeated packed fixed64" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to uint64_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_fixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_fixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<uint64_t, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -783,14 +692,14 @@ public:
|
||||
/**
|
||||
* Add "repeated packed sfixed64" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to int64_t.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_sfixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_sfixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<int64_t, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -798,14 +707,14 @@ public:
|
||||
/**
|
||||
* Add "repeated packed float" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to float.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_float(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_float(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<float, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -813,14 +722,14 @@ public:
|
||||
/**
|
||||
* Add "repeated packed double" field to data.
|
||||
*
|
||||
* @tparam InputIterator A type satisfying the InputIterator concept.
|
||||
* @tparam InputIterator An type satisfying the InputIterator concept.
|
||||
* Dereferencing the iterator must yield a type assignable to double.
|
||||
* @param tag Tag (field number) of the field
|
||||
* @param first Iterator pointing to the beginning of the data
|
||||
* @param last Iterator pointing one past the end of data
|
||||
*/
|
||||
template <typename InputIterator>
|
||||
void add_packed_double(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
inline void add_packed_double(pbf_tag_type tag, InputIterator first, InputIterator last) {
|
||||
add_packed_fixed<double, InputIterator>(tag, first, last,
|
||||
typename std::iterator_traits<InputIterator>::iterator_category());
|
||||
}
|
||||
@ -833,16 +742,6 @@ public:
|
||||
|
||||
}; // class pbf_writer
|
||||
|
||||
/**
|
||||
* Swap two pbf_writer objects.
|
||||
*
|
||||
* @param lhs First object.
|
||||
* @param rhs Second object.
|
||||
*/
|
||||
inline void swap(pbf_writer& lhs, pbf_writer& rhs) noexcept {
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
class packed_field {
|
||||
@ -853,12 +752,6 @@ namespace detail {
|
||||
|
||||
public:
|
||||
|
||||
packed_field(const packed_field&) = delete;
|
||||
packed_field& operator=(const packed_field&) = delete;
|
||||
|
||||
packed_field(packed_field&&) = default;
|
||||
packed_field& operator=(packed_field&&) = default;
|
||||
|
||||
packed_field(pbf_writer& parent_writer, pbf_tag_type tag) :
|
||||
m_writer(parent_writer, tag) {
|
||||
}
|
||||
@ -878,14 +771,12 @@ namespace detail {
|
||||
|
||||
public:
|
||||
|
||||
template <typename P>
|
||||
packed_field_fixed(pbf_writer& parent_writer, P tag) :
|
||||
packed_field(parent_writer, static_cast<pbf_tag_type>(tag)) {
|
||||
packed_field_fixed(pbf_writer& parent_writer, pbf_tag_type tag) :
|
||||
packed_field(parent_writer, tag) {
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
packed_field_fixed(pbf_writer& parent_writer, P tag, std::size_t size) :
|
||||
packed_field(parent_writer, static_cast<pbf_tag_type>(tag), size * sizeof(T)) {
|
||||
packed_field_fixed(pbf_writer& parent_writer, pbf_tag_type tag, std::size_t size) :
|
||||
packed_field(parent_writer, tag, size * sizeof(T)) {
|
||||
}
|
||||
|
||||
void add_element(T value) {
|
||||
@ -899,9 +790,8 @@ namespace detail {
|
||||
|
||||
public:
|
||||
|
||||
template <typename P>
|
||||
packed_field_varint(pbf_writer& parent_writer, P tag) :
|
||||
packed_field(parent_writer, static_cast<pbf_tag_type>(tag)) {
|
||||
packed_field_varint(pbf_writer& parent_writer, pbf_tag_type tag) :
|
||||
packed_field(parent_writer, tag) {
|
||||
}
|
||||
|
||||
void add_element(T value) {
|
||||
@ -915,9 +805,8 @@ namespace detail {
|
||||
|
||||
public:
|
||||
|
||||
template <typename P>
|
||||
packed_field_svarint(pbf_writer& parent_writer, P tag) :
|
||||
packed_field(parent_writer, static_cast<pbf_tag_type>(tag)) {
|
||||
packed_field_svarint(pbf_writer& parent_writer, pbf_tag_type tag) :
|
||||
packed_field(parent_writer, tag) {
|
||||
}
|
||||
|
||||
void add_element(T value) {
|
||||
@ -928,46 +817,19 @@ namespace detail {
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
/// Class for generating packed repeated bool fields.
|
||||
using packed_field_bool = detail::packed_field_varint<bool>;
|
||||
|
||||
/// Class for generating packed repeated enum fields.
|
||||
using packed_field_enum = detail::packed_field_varint<int32_t>;
|
||||
|
||||
/// Class for generating packed repeated int32 fields.
|
||||
using packed_field_int32 = detail::packed_field_varint<int32_t>;
|
||||
|
||||
/// Class for generating packed repeated sint32 fields.
|
||||
using packed_field_sint32 = detail::packed_field_svarint<int32_t>;
|
||||
|
||||
/// Class for generating packed repeated uint32 fields.
|
||||
using packed_field_uint32 = detail::packed_field_varint<uint32_t>;
|
||||
|
||||
/// Class for generating packed repeated int64 fields.
|
||||
using packed_field_int64 = detail::packed_field_varint<int64_t>;
|
||||
|
||||
/// Class for generating packed repeated sint64 fields.
|
||||
using packed_field_sint64 = detail::packed_field_svarint<int64_t>;
|
||||
|
||||
/// Class for generating packed repeated uint64 fields.
|
||||
using packed_field_uint64 = detail::packed_field_varint<uint64_t>;
|
||||
|
||||
/// Class for generating packed repeated fixed32 fields.
|
||||
using packed_field_fixed32 = detail::packed_field_fixed<uint32_t>;
|
||||
|
||||
/// Class for generating packed repeated sfixed32 fields.
|
||||
using packed_field_sfixed32 = detail::packed_field_fixed<int32_t>;
|
||||
|
||||
/// Class for generating packed repeated fixed64 fields.
|
||||
using packed_field_fixed64 = detail::packed_field_fixed<uint64_t>;
|
||||
|
||||
/// Class for generating packed repeated sfixed64 fields.
|
||||
using packed_field_sfixed64 = detail::packed_field_fixed<int64_t>;
|
||||
|
||||
/// Class for generating packed repeated float fields.
|
||||
using packed_field_float = detail::packed_field_fixed<float>;
|
||||
|
||||
/// Class for generating packed repeated double fields.
|
||||
using packed_field_double = detail::packed_field_fixed<double>;
|
||||
|
||||
} // end namespace protozero
|
||||
|
@ -16,190 +16,33 @@ documentation.
|
||||
* @brief Contains the declaration of low-level types used in the pbf format.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <protozero/config.hpp>
|
||||
|
||||
namespace protozero {
|
||||
|
||||
/**
|
||||
* The type used for field tags (field numbers).
|
||||
*/
|
||||
using pbf_tag_type = uint32_t;
|
||||
|
||||
/**
|
||||
* The type used to encode type information.
|
||||
* See the table on
|
||||
* https://developers.google.com/protocol-buffers/docs/encoding
|
||||
*/
|
||||
enum class pbf_wire_type : uint32_t {
|
||||
varint = 0, // int32/64, uint32/64, sint32/64, bool, enum
|
||||
fixed64 = 1, // fixed64, sfixed64, double
|
||||
length_delimited = 2, // string, bytes, embedded messages,
|
||||
// packed repeated fields
|
||||
fixed32 = 5, // fixed32, sfixed32, float
|
||||
unknown = 99 // used for default setting in this library
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the tag and wire type of the current field in one integer suitable
|
||||
* for comparison with a switch statement.
|
||||
*
|
||||
* See pbf_reader.tag_and_type() for an example how to use this.
|
||||
*/
|
||||
template <typename T>
|
||||
constexpr inline uint32_t tag_and_type(T tag, pbf_wire_type wire_type) noexcept {
|
||||
return (static_cast<uint32_t>(static_cast<pbf_tag_type>(tag)) << 3) | static_cast<uint32_t>(wire_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type used for length values, such as the length of a field.
|
||||
*/
|
||||
using pbf_length_type = uint32_t;
|
||||
|
||||
#ifdef PROTOZERO_USE_VIEW
|
||||
using data_view = PROTOZERO_USE_VIEW;
|
||||
#else
|
||||
|
||||
/**
|
||||
* Holds a pointer to some data and a length.
|
||||
*
|
||||
* This class is supposed to be compatible with the std::string_view
|
||||
* that will be available in C++17.
|
||||
*/
|
||||
class data_view {
|
||||
|
||||
const char* m_data;
|
||||
std::size_t m_size;
|
||||
|
||||
public:
|
||||
/**
|
||||
* The type used for field tags (field numbers).
|
||||
*/
|
||||
typedef uint32_t pbf_tag_type;
|
||||
|
||||
/**
|
||||
* Default constructor. Construct an empty data_view.
|
||||
* The type used to encode type information.
|
||||
* See the table on
|
||||
* https://developers.google.com/protocol-buffers/docs/encoding
|
||||
*/
|
||||
constexpr data_view() noexcept
|
||||
: m_data(nullptr),
|
||||
m_size(0) {
|
||||
}
|
||||
enum class pbf_wire_type : uint32_t {
|
||||
varint = 0, // int32/64, uint32/64, sint32/64, bool, enum
|
||||
fixed64 = 1, // fixed64, sfixed64, double
|
||||
length_delimited = 2, // string, bytes, embedded messages,
|
||||
// packed repeated fields
|
||||
fixed32 = 5, // fixed32, sfixed32, float
|
||||
unknown = 99 // used for default setting in this library
|
||||
};
|
||||
|
||||
/**
|
||||
* Create data_view from pointer and size.
|
||||
*
|
||||
* @param ptr Pointer to the data.
|
||||
* @param length Length of the data.
|
||||
* The type used for length values, such as the length of a field.
|
||||
*/
|
||||
constexpr data_view(const char* ptr, std::size_t length) noexcept
|
||||
: m_data(ptr),
|
||||
m_size(length) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data_view from string.
|
||||
*
|
||||
* @param str String with the data.
|
||||
*/
|
||||
data_view(const std::string& str) noexcept
|
||||
: m_data(str.data()),
|
||||
m_size(str.size()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create data_view from zero-terminated string.
|
||||
*
|
||||
* @param ptr Pointer to the data.
|
||||
*/
|
||||
data_view(const char* ptr) noexcept
|
||||
: m_data(ptr),
|
||||
m_size(std::strlen(ptr)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the contents of this object with the other.
|
||||
*
|
||||
* @param other Other object to swap data with.
|
||||
*/
|
||||
void swap(data_view& other) noexcept {
|
||||
using std::swap;
|
||||
swap(m_data, other.m_data);
|
||||
swap(m_size, other.m_size);
|
||||
}
|
||||
|
||||
/// Return pointer to data.
|
||||
constexpr const char* data() const noexcept {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
/// Return length of data in bytes.
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/// Returns true if size is 0.
|
||||
constexpr bool empty() const noexcept {
|
||||
return m_size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert data view to string.
|
||||
*
|
||||
* @pre Must not be default constructed data_view.
|
||||
*/
|
||||
std::string to_string() const {
|
||||
protozero_assert(m_data);
|
||||
return std::string{m_data, m_size};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert data view to string.
|
||||
*
|
||||
* @pre Must not be default constructed data_view.
|
||||
*/
|
||||
explicit operator std::string() const {
|
||||
protozero_assert(m_data);
|
||||
return std::string{m_data, m_size};
|
||||
}
|
||||
|
||||
}; // class data_view
|
||||
|
||||
/**
|
||||
* Swap two data_view objects.
|
||||
*
|
||||
* @param lhs First object.
|
||||
* @param rhs Second object.
|
||||
*/
|
||||
inline void swap(data_view& lhs, data_view& rhs) noexcept {
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Two data_view instances are equal if they have the same size and the
|
||||
* same content.
|
||||
*
|
||||
* @param lhs First object.
|
||||
* @param rhs Second object.
|
||||
*/
|
||||
inline bool operator==(const data_view& lhs, const data_view& rhs) noexcept {
|
||||
return lhs.size() == rhs.size() && std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data());
|
||||
}
|
||||
|
||||
/**
|
||||
* Two data_view instances are not equal if they have different sizes or the
|
||||
* content differs.
|
||||
*
|
||||
* @param lhs First object.
|
||||
* @param rhs Second object.
|
||||
*/
|
||||
inline bool operator!=(const data_view& lhs, const data_view& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef uint32_t pbf_length_type;
|
||||
|
||||
} // end namespace protozero
|
||||
|
||||
|
@ -23,54 +23,13 @@ documentation.
|
||||
namespace protozero {
|
||||
|
||||
/**
|
||||
* The maximum length of a 64 bit varint.
|
||||
* The maximum length of a 64bit varint.
|
||||
*/
|
||||
constexpr const int8_t max_varint_length = sizeof(uint64_t) * 8 / 7 + 1;
|
||||
|
||||
namespace detail {
|
||||
|
||||
// from https://github.com/facebook/folly/blob/master/folly/Varint.h
|
||||
inline uint64_t decode_varint_impl(const char** data, const char* end) {
|
||||
const int8_t* begin = reinterpret_cast<const int8_t*>(*data);
|
||||
const int8_t* iend = reinterpret_cast<const int8_t*>(end);
|
||||
const int8_t* p = begin;
|
||||
uint64_t val = 0;
|
||||
|
||||
if (iend - begin >= max_varint_length) { // fast path
|
||||
do {
|
||||
int64_t b;
|
||||
b = *p++; val = uint64_t((b & 0x7f) ); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 7); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 14); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 21); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 28); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 35); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 42); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 49); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 56); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 63); if (b >= 0) break;
|
||||
throw varint_too_long_exception();
|
||||
} while (false);
|
||||
} else {
|
||||
int shift = 0;
|
||||
while (p != iend && *p < 0) {
|
||||
val |= uint64_t(*p++ & 0x7f) << shift;
|
||||
shift += 7;
|
||||
}
|
||||
if (p == iend) {
|
||||
throw end_of_buffer_exception();
|
||||
}
|
||||
val |= uint64_t(*p++) << shift;
|
||||
}
|
||||
|
||||
*data = reinterpret_cast<const char*>(p);
|
||||
return val;
|
||||
}
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
// from https://github.com/facebook/folly/blob/master/folly/Varint.h
|
||||
/**
|
||||
* Decode a 64 bit varint.
|
||||
* Decode a 64bit varint.
|
||||
*
|
||||
* Strong exception guarantee: if there is an exception the data pointer will
|
||||
* not be changed.
|
||||
@ -80,69 +39,55 @@ namespace detail {
|
||||
* @param[in] end Pointer one past the end of the input data.
|
||||
* @returns The decoded integer
|
||||
* @throws varint_too_long_exception if the varint is longer then the maximum
|
||||
* length that would fit in a 64 bit int. Usually this means your data
|
||||
* length that would fit in a 64bit int. Usually this means your data
|
||||
* is corrupted or you are trying to read something as a varint that
|
||||
* isn't.
|
||||
* @throws end_of_buffer_exception if the *end* of the buffer was reached
|
||||
* before the end of the varint.
|
||||
*/
|
||||
inline uint64_t decode_varint(const char** data, const char* end) {
|
||||
// If this is a one-byte varint, decode it here.
|
||||
if (end != *data && ((**data & 0x80) == 0)) {
|
||||
uint64_t val = uint64_t(**data);
|
||||
++(*data);
|
||||
return val;
|
||||
}
|
||||
// If this varint is more than one byte, defer to complete implementation.
|
||||
return detail::decode_varint_impl(data, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip over a varint.
|
||||
*
|
||||
* Strong exception guarantee: if there is an exception the data pointer will
|
||||
* not be changed.
|
||||
*
|
||||
* @param[in,out] data Pointer to pointer to the input data. After the function
|
||||
* returns this will point to the next data to be read.
|
||||
* @param[in] end Pointer one past the end of the input data.
|
||||
* @throws end_of_buffer_exception if the *end* of the buffer was reached
|
||||
* before the end of the varint.
|
||||
*/
|
||||
inline void skip_varint(const char** data, const char* end) {
|
||||
const int8_t* begin = reinterpret_cast<const int8_t*>(*data);
|
||||
const int8_t* iend = reinterpret_cast<const int8_t*>(end);
|
||||
const int8_t* p = begin;
|
||||
uint64_t val = 0;
|
||||
|
||||
while (p != iend && *p < 0) {
|
||||
++p;
|
||||
if (iend - begin >= max_varint_length) { // fast path
|
||||
do {
|
||||
int64_t b;
|
||||
b = *p++; val = uint64_t((b & 0x7f) ); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 7); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 14); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 21); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 28); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 35); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 42); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 49); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 56); if (b >= 0) break;
|
||||
b = *p++; val |= uint64_t((b & 0x7f) << 63); if (b >= 0) break;
|
||||
throw varint_too_long_exception();
|
||||
} while (false);
|
||||
} else {
|
||||
int shift = 0;
|
||||
while (p != iend && *p < 0) {
|
||||
val |= uint64_t(*p++ & 0x7f) << shift;
|
||||
shift += 7;
|
||||
}
|
||||
if (p == iend) {
|
||||
throw end_of_buffer_exception();
|
||||
}
|
||||
val |= uint64_t(*p++) << shift;
|
||||
}
|
||||
|
||||
if (p >= begin + max_varint_length) {
|
||||
throw varint_too_long_exception();
|
||||
}
|
||||
|
||||
if (p == iend) {
|
||||
throw end_of_buffer_exception();
|
||||
}
|
||||
|
||||
++p;
|
||||
|
||||
*data = reinterpret_cast<const char*>(p);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Varint encode a 64 bit integer.
|
||||
*
|
||||
* @tparam T An output iterator type.
|
||||
* @param data Output iterator the varint encoded value will be written to
|
||||
* byte by byte.
|
||||
* @param value The integer that will be encoded.
|
||||
* @throws Any exception thrown by increment or dereference operator on data.
|
||||
* Varint-encode a 64bit integer.
|
||||
*/
|
||||
template <typename T>
|
||||
inline int write_varint(T data, uint64_t value) {
|
||||
int n = 1;
|
||||
template <typename OutputIterator>
|
||||
inline int write_varint(OutputIterator data, uint64_t value) {
|
||||
int n=1;
|
||||
|
||||
while (value >= 0x80) {
|
||||
*data++ = char((value & 0x7f) | 0x80);
|
||||
@ -157,29 +102,29 @@ inline int write_varint(T data, uint64_t value) {
|
||||
/**
|
||||
* ZigZag encodes a 32 bit integer.
|
||||
*/
|
||||
inline constexpr uint32_t encode_zigzag32(int32_t value) noexcept {
|
||||
inline uint32_t encode_zigzag32(int32_t value) noexcept {
|
||||
return (static_cast<uint32_t>(value) << 1) ^ (static_cast<uint32_t>(value >> 31));
|
||||
}
|
||||
|
||||
/**
|
||||
* ZigZag encodes a 64 bit integer.
|
||||
*/
|
||||
inline constexpr uint64_t encode_zigzag64(int64_t value) noexcept {
|
||||
inline uint64_t encode_zigzag64(int64_t value) noexcept {
|
||||
return (static_cast<uint64_t>(value) << 1) ^ (static_cast<uint64_t>(value >> 63));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a 32 bit ZigZag-encoded integer.
|
||||
*/
|
||||
inline constexpr int32_t decode_zigzag32(uint32_t value) noexcept {
|
||||
return static_cast<int32_t>(value >> 1) ^ -static_cast<int32_t>(value & 1);
|
||||
inline int32_t decode_zigzag32(uint32_t value) noexcept {
|
||||
return int32_t(value >> 1) ^ -int32_t(value & 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a 64 bit ZigZag-encoded integer.
|
||||
*/
|
||||
inline constexpr int64_t decode_zigzag64(uint64_t value) noexcept {
|
||||
return static_cast<int64_t>(value >> 1) ^ -static_cast<int64_t>(value & 1);
|
||||
inline int64_t decode_zigzag64(uint64_t value) noexcept {
|
||||
return int64_t(value >> 1) ^ -int64_t(value & 1);
|
||||
}
|
||||
|
||||
} // end namespace protozero
|
||||
|
@ -10,25 +10,13 @@ documentation.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file version.hpp
|
||||
*
|
||||
* @brief Contains macros defining the protozero version.
|
||||
*/
|
||||
|
||||
/// The major version number
|
||||
#define PROTOZERO_VERSION_MAJOR 1
|
||||
#define PROTOZERO_VERSION_MINOR 3
|
||||
#define PROTOZERO_VERSION_PATCH 0
|
||||
|
||||
/// The minor version number
|
||||
#define PROTOZERO_VERSION_MINOR 5
|
||||
|
||||
/// The patch number
|
||||
#define PROTOZERO_VERSION_PATCH 2
|
||||
|
||||
/// The complete version number
|
||||
#define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH)
|
||||
|
||||
/// Version number as string
|
||||
#define PROTOZERO_VERSION_STRING "1.5.2"
|
||||
#define PROTOZERO_VERSION_STRING "1.3.0"
|
||||
|
||||
|
||||
#endif // PROTOZERO_VERSION_HPP
|
||||
|
185
read_json.cpp
185
read_json.cpp
@ -1,185 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "geometry.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "read_json.hpp"
|
||||
#include "text.hpp"
|
||||
#include "mvt.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
|
||||
const char *geometry_names[GEOM_TYPES] = {
|
||||
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
||||
};
|
||||
|
||||
int geometry_within[GEOM_TYPES] = {
|
||||
-1, /* point */
|
||||
GEOM_POINT, /* multipoint */
|
||||
GEOM_POINT, /* linestring */
|
||||
GEOM_LINESTRING, /* multilinestring */
|
||||
GEOM_LINESTRING, /* polygon */
|
||||
GEOM_POLYGON, /* multipolygon */
|
||||
};
|
||||
|
||||
int mb_geometry[GEOM_TYPES] = {
|
||||
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
|
||||
};
|
||||
|
||||
void json_context(json_object *j) {
|
||||
char *s = json_stringify(j);
|
||||
|
||||
if (strlen(s) >= 500) {
|
||||
sprintf(s + 497, "...");
|
||||
}
|
||||
|
||||
fprintf(stderr, "In JSON object %s\n", s);
|
||||
free(s); // stringify
|
||||
}
|
||||
|
||||
void parse_geometry(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 type %d\n", fname, line, t);
|
||||
json_context(feature);
|
||||
return;
|
||||
}
|
||||
|
||||
int within = geometry_within[t];
|
||||
if (within >= 0) {
|
||||
size_t i;
|
||||
for (i = 0; i < j->length; i++) {
|
||||
if (within == GEOM_POINT) {
|
||||
if (i == 0 || mb_geometry[t] == VT_POINT) {
|
||||
op = VT_MOVETO;
|
||||
} else {
|
||||
op = VT_LINETO;
|
||||
}
|
||||
}
|
||||
|
||||
parse_geometry(within, j->array[i], out, op, fname, line, feature);
|
||||
}
|
||||
} else {
|
||||
if (j->length >= 2 && j->array[0]->type == JSON_NUMBER && j->array[1]->type == JSON_NUMBER) {
|
||||
long long x, y;
|
||||
double lon = j->array[0]->number;
|
||||
double lat = j->array[1]->number;
|
||||
projection->project(lon, lat, 32, &x, &y);
|
||||
|
||||
if (j->length > 2) {
|
||||
static int warned = 0;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "%s:%d: ignoring dimensions beyond two\n", fname, line);
|
||||
json_context(j);
|
||||
json_context(feature);
|
||||
warned = 1;
|
||||
}
|
||||
}
|
||||
|
||||
out.push_back(draw(op, x, y));
|
||||
} else {
|
||||
fprintf(stderr, "%s:%d: malformed point\n", fname, line);
|
||||
json_context(j);
|
||||
json_context(feature);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (t == GEOM_POLYGON) {
|
||||
// Note that this is not using the correct meaning of closepath.
|
||||
//
|
||||
// We are using it here to close an entire Polygon, to distinguish
|
||||
// the Polygons within a MultiPolygon from each other.
|
||||
//
|
||||
// This will be undone in fix_polygon(), which needs to know which
|
||||
// rings come from which Polygons so that it can make the winding order
|
||||
// of the outer ring be the opposite of the order of the inner rings.
|
||||
|
||||
out.push_back(draw(VT_CLOSEPATH, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void canonicalize(json_object *o) {
|
||||
if (o->type == JSON_NUMBER) {
|
||||
std::string s;
|
||||
long long v;
|
||||
unsigned long long uv;
|
||||
|
||||
if (is_integer(o->string, &v)) {
|
||||
s = std::to_string(v);
|
||||
} else if (is_unsigned_integer(o->string, &uv)) {
|
||||
s = std::to_string(uv);
|
||||
} else {
|
||||
s = milo::dtoa_milo(o->number);
|
||||
}
|
||||
free(o->string);
|
||||
o->string = strdup(s.c_str());
|
||||
} else if (o->type == JSON_HASH) {
|
||||
for (size_t i = 0; i < o->length; i++) {
|
||||
canonicalize(o->values[i]);
|
||||
}
|
||||
} else if (o->type == JSON_ARRAY) {
|
||||
for (size_t i = 0; i < o->length; i++) {
|
||||
canonicalize(o->array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stringify_value(json_object *value, int &type, std::string &stringified, const char *reading, int line, json_object *feature) {
|
||||
if (value != NULL) {
|
||||
int vt = value->type;
|
||||
std::string val;
|
||||
|
||||
if (vt == JSON_STRING || vt == JSON_NUMBER) {
|
||||
val = value->string;
|
||||
} else if (vt == JSON_TRUE) {
|
||||
val = "true";
|
||||
} else if (vt == JSON_FALSE) {
|
||||
val = "false";
|
||||
} else if (vt == JSON_NULL) {
|
||||
val = "null";
|
||||
} else {
|
||||
canonicalize(value);
|
||||
const char *v = json_stringify(value);
|
||||
val = std::string(v);
|
||||
free((void *) v); // stringify
|
||||
}
|
||||
|
||||
if (vt == JSON_STRING) {
|
||||
type = mvt_string;
|
||||
stringified = val;
|
||||
std::string err = check_utf8(val);
|
||||
if (err != "") {
|
||||
fprintf(stderr, "%s:%d: %s\n", reading, line, err.c_str());
|
||||
json_context(feature);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (vt == JSON_NUMBER) {
|
||||
type = mvt_double;
|
||||
|
||||
long long v;
|
||||
unsigned long long uv;
|
||||
|
||||
if (is_integer(value->string, &v)) {
|
||||
stringified = std::to_string(v);
|
||||
} else if (is_unsigned_integer(value->string, &uv)) {
|
||||
stringified = std::to_string(uv);
|
||||
} else {
|
||||
stringified = milo::dtoa_milo(value->number);
|
||||
}
|
||||
} else if (vt == JSON_TRUE || vt == JSON_FALSE) {
|
||||
type = mvt_bool;
|
||||
stringified = val;
|
||||
} else if (vt == JSON_NULL) {
|
||||
type = mvt_null;
|
||||
stringified = "null";
|
||||
} else {
|
||||
type = mvt_string;
|
||||
stringified = val;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#define GEOM_POINT 0 /* array of positions */
|
||||
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
||||
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
||||
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
||||
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
||||
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
||||
#define GEOM_TYPES 6
|
||||
|
||||
extern const char *geometry_names[GEOM_TYPES];
|
||||
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 stringify_value(json_object *value, int &type, std::string &stringified, const char *reading, int line, json_object *feature);
|
554
serial.cpp
554
serial.cpp
@ -7,24 +7,11 @@
|
||||
#include <sqlite3.h>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <limits.h>
|
||||
#include "protozero/varint.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
#include "tile.hpp"
|
||||
#include "serial.hpp"
|
||||
#include "options.hpp"
|
||||
#include "main.hpp"
|
||||
#include "pool.hpp"
|
||||
#include "projection.hpp"
|
||||
#include "evaluator.hpp"
|
||||
#include "milo/dtoa_milo.h"
|
||||
|
||||
// Offset coordinates to keep them positive
|
||||
#define COORD_OFFSET (4LL << 32)
|
||||
#define SHIFT_RIGHT(a) ((((a) + COORD_OFFSET) >> geometry_scale) - (COORD_OFFSET >> geometry_scale))
|
||||
#define SHIFT_LEFT(a) ((((a) + (COORD_OFFSET >> geometry_scale)) << geometry_scale) - COORD_OFFSET)
|
||||
|
||||
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname) {
|
||||
size_t w = fwrite(ptr, size, nitems, stream);
|
||||
@ -35,17 +22,17 @@ size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, c
|
||||
return w;
|
||||
}
|
||||
|
||||
void serialize_int(FILE *out, int n, std::atomic<long long> *fpos, const char *fname) {
|
||||
void serialize_int(FILE *out, int n, long long *fpos, const char *fname) {
|
||||
serialize_long_long(out, n, fpos, fname);
|
||||
}
|
||||
|
||||
void serialize_long_long(FILE *out, long long n, std::atomic<long long> *fpos, const char *fname) {
|
||||
void serialize_long_long(FILE *out, long long n, long long *fpos, const char *fname) {
|
||||
unsigned long long zigzag = protozero::encode_zigzag64(n);
|
||||
|
||||
serialize_ulong_long(out, zigzag, fpos, fname);
|
||||
}
|
||||
|
||||
void serialize_ulong_long(FILE *out, unsigned long long zigzag, std::atomic<long long> *fpos, const char *fname) {
|
||||
void serialize_ulong_long(FILE *out, unsigned long long zigzag, long long *fpos, const char *fname) {
|
||||
while (1) {
|
||||
unsigned char b = zigzag & 0x7F;
|
||||
if ((zigzag >> 7) != 0) {
|
||||
@ -67,12 +54,12 @@ void serialize_ulong_long(FILE *out, unsigned long long zigzag, std::atomic<long
|
||||
}
|
||||
}
|
||||
|
||||
void serialize_byte(FILE *out, signed char n, std::atomic<long long> *fpos, const char *fname) {
|
||||
void serialize_byte(FILE *out, signed char n, long long *fpos, const char *fname) {
|
||||
fwrite_check(&n, sizeof(signed char), 1, out, fname);
|
||||
*fpos += sizeof(signed char);
|
||||
}
|
||||
|
||||
void serialize_uint(FILE *out, unsigned n, std::atomic<long long> *fpos, const char *fname) {
|
||||
void serialize_uint(FILE *out, unsigned n, long long *fpos, const char *fname) {
|
||||
fwrite_check(&n, sizeof(unsigned), 1, out, fname);
|
||||
*fpos += sizeof(unsigned);
|
||||
}
|
||||
@ -117,14 +104,14 @@ void deserialize_byte(char **f, signed char *n) {
|
||||
*f += sizeof(signed char);
|
||||
}
|
||||
|
||||
int deserialize_long_long_io(FILE *f, long long *n, std::atomic<long long> *geompos) {
|
||||
int deserialize_long_long_io(FILE *f, long long *n, long long *geompos) {
|
||||
unsigned long long zigzag = 0;
|
||||
int ret = deserialize_ulong_long_io(f, &zigzag, geompos);
|
||||
*n = protozero::decode_zigzag64(zigzag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int deserialize_ulong_long_io(FILE *f, unsigned long long *zigzag, std::atomic<long long> *geompos) {
|
||||
int deserialize_ulong_long_io(FILE *f, unsigned long long *zigzag, long long *geompos) {
|
||||
*zigzag = 0;
|
||||
int shift = 0;
|
||||
|
||||
@ -148,14 +135,14 @@ int deserialize_ulong_long_io(FILE *f, unsigned long long *zigzag, std::atomic<l
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deserialize_int_io(FILE *f, int *n, std::atomic<long long> *geompos) {
|
||||
int deserialize_int_io(FILE *f, int *n, long long *geompos) {
|
||||
long long ll = 0;
|
||||
int ret = deserialize_long_long_io(f, &ll, geompos);
|
||||
*n = ll;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int deserialize_uint_io(FILE *f, unsigned *n, std::atomic<long long> *geompos) {
|
||||
int deserialize_uint_io(FILE *f, unsigned *n, long long *geompos) {
|
||||
if (fread(n, sizeof(unsigned), 1, f) != 1) {
|
||||
return 0;
|
||||
}
|
||||
@ -163,7 +150,7 @@ int deserialize_uint_io(FILE *f, unsigned *n, std::atomic<long long> *geompos) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deserialize_byte_io(FILE *f, signed char *n, std::atomic<long long> *geompos) {
|
||||
int deserialize_byte_io(FILE *f, signed char *n, long long *geompos) {
|
||||
int c = getc(f);
|
||||
if (c == EOF) {
|
||||
return 0;
|
||||
@ -173,7 +160,7 @@ int deserialize_byte_io(FILE *f, signed char *n, std::atomic<long long> *geompos
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void write_geometry(drawvec const &dv, std::atomic<long long> *fpos, FILE *out, const char *fname, long long wx, long long wy) {
|
||||
static void write_geometry(drawvec const &dv, long long *fpos, FILE *out, const char *fname, long long wx, long long wy) {
|
||||
for (size_t i = 0; i < dv.size(); i++) {
|
||||
if (dv[i].op == VT_MOVETO || dv[i].op == VT_LINETO) {
|
||||
serialize_byte(out, dv[i].op, fpos, fname);
|
||||
@ -187,8 +174,7 @@ static void write_geometry(drawvec const &dv, std::atomic<long long> *fpos, FILE
|
||||
}
|
||||
}
|
||||
|
||||
// called from generating the next zoom level
|
||||
void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long> *geompos, const char *fname, long long wx, long long wy, bool include_minzoom) {
|
||||
void serialize_feature(FILE *geomfile, serial_feature *sf, long long *geompos, const char *fname, long long wx, long long wy, bool include_minzoom) {
|
||||
serialize_byte(geomfile, sf->t, geompos, fname);
|
||||
|
||||
long long layer = 0;
|
||||
@ -225,516 +211,22 @@ void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long
|
||||
serialize_long_long(geomfile, sf->extent, geompos, fname);
|
||||
}
|
||||
|
||||
serialize_long_long(geomfile, sf->metapos, geompos, fname);
|
||||
serialize_int(geomfile, sf->m, geompos, fname);
|
||||
if (sf->m != 0) {
|
||||
serialize_long_long(geomfile, sf->metapos, geompos, fname);
|
||||
}
|
||||
|
||||
if (sf->metapos < 0) {
|
||||
serialize_long_long(geomfile, sf->keys.size(), geompos, fname);
|
||||
if (sf->metapos < 0 && sf->m != sf->keys.size()) {
|
||||
fprintf(stderr, "Internal error: %lld doesn't match %lld\n", (long long) sf->m, (long long) sf->keys.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sf->keys.size(); i++) {
|
||||
serialize_long_long(geomfile, sf->keys[i], geompos, fname);
|
||||
serialize_long_long(geomfile, sf->values[i], geompos, fname);
|
||||
}
|
||||
for (size_t i = 0; i < sf->keys.size(); i++) {
|
||||
serialize_long_long(geomfile, sf->keys[i], geompos, fname);
|
||||
serialize_long_long(geomfile, sf->values[i], geompos, fname);
|
||||
}
|
||||
|
||||
if (include_minzoom) {
|
||||
serialize_byte(geomfile, sf->feature_minzoom, geompos, fname);
|
||||
}
|
||||
}
|
||||
|
||||
serial_feature deserialize_feature(FILE *geoms, std::atomic<long long> *geompos_in, char *metabase, long long *meta_off, unsigned z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y) {
|
||||
serial_feature sf;
|
||||
|
||||
deserialize_byte_io(geoms, &sf.t, geompos_in);
|
||||
if (sf.t < 0) {
|
||||
return sf;
|
||||
}
|
||||
|
||||
deserialize_long_long_io(geoms, &sf.layer, geompos_in);
|
||||
|
||||
sf.seq = 0;
|
||||
if (sf.layer & (1 << 5)) {
|
||||
deserialize_long_long_io(geoms, &sf.seq, geompos_in);
|
||||
}
|
||||
|
||||
sf.tippecanoe_minzoom = -1;
|
||||
sf.tippecanoe_maxzoom = -1;
|
||||
sf.id = 0;
|
||||
sf.has_id = false;
|
||||
if (sf.layer & (1 << 1)) {
|
||||
deserialize_int_io(geoms, &sf.tippecanoe_minzoom, geompos_in);
|
||||
}
|
||||
if (sf.layer & (1 << 0)) {
|
||||
deserialize_int_io(geoms, &sf.tippecanoe_maxzoom, geompos_in);
|
||||
}
|
||||
if (sf.layer & (1 << 2)) {
|
||||
sf.has_id = true;
|
||||
deserialize_ulong_long_io(geoms, &sf.id, geompos_in);
|
||||
}
|
||||
|
||||
deserialize_int_io(geoms, &sf.segment, geompos_in);
|
||||
|
||||
sf.index = 0;
|
||||
sf.extent = 0;
|
||||
|
||||
sf.geometry = decode_geometry(geoms, geompos_in, z, tx, ty, sf.bbox, initial_x[sf.segment], initial_y[sf.segment]);
|
||||
if (sf.layer & (1 << 4)) {
|
||||
deserialize_ulong_long_io(geoms, &sf.index, geompos_in);
|
||||
}
|
||||
if (sf.layer & (1 << 3)) {
|
||||
deserialize_long_long_io(geoms, &sf.extent, geompos_in);
|
||||
}
|
||||
|
||||
sf.layer >>= 6;
|
||||
|
||||
sf.metapos = 0;
|
||||
deserialize_long_long_io(geoms, &sf.metapos, geompos_in);
|
||||
|
||||
if (sf.metapos >= 0) {
|
||||
char *meta = metabase + sf.metapos + meta_off[sf.segment];
|
||||
long long count;
|
||||
deserialize_long_long(&meta, &count);
|
||||
|
||||
for (long long i = 0; i < count; i++) {
|
||||
long long k, v;
|
||||
deserialize_long_long(&meta, &k);
|
||||
deserialize_long_long(&meta, &v);
|
||||
sf.keys.push_back(k);
|
||||
sf.values.push_back(v);
|
||||
}
|
||||
} else {
|
||||
long long count;
|
||||
deserialize_long_long_io(geoms, &count, geompos_in);
|
||||
|
||||
for (long long i = 0; i < count; i++) {
|
||||
long long k, v;
|
||||
deserialize_long_long_io(geoms, &k, geompos_in);
|
||||
deserialize_long_long_io(geoms, &v, geompos_in);
|
||||
sf.keys.push_back(k);
|
||||
sf.values.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
deserialize_byte_io(geoms, &sf.feature_minzoom, geompos_in);
|
||||
|
||||
return sf;
|
||||
}
|
||||
|
||||
static long long scale_geometry(struct serialization_state *sst, long long *bbox, drawvec &geom) {
|
||||
long long offset = 0;
|
||||
long long prev = 0;
|
||||
bool has_prev = false;
|
||||
double scale = 1.0 / (1 << geometry_scale);
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO || geom[i].op == VT_LINETO) {
|
||||
long long x = geom[i].x;
|
||||
long long y = geom[i].y;
|
||||
|
||||
if (additional[A_DETECT_WRAPAROUND]) {
|
||||
x += offset;
|
||||
if (has_prev) {
|
||||
if (x - prev > (1LL << 31)) {
|
||||
offset -= 1LL << 32;
|
||||
x -= 1LL << 32;
|
||||
} else if (prev - x > (1LL << 31)) {
|
||||
offset += 1LL << 32;
|
||||
x += 1LL << 32;
|
||||
}
|
||||
}
|
||||
|
||||
has_prev = true;
|
||||
prev = x;
|
||||
}
|
||||
|
||||
if (x < bbox[0]) {
|
||||
bbox[0] = x;
|
||||
}
|
||||
if (y < bbox[1]) {
|
||||
bbox[1] = y;
|
||||
}
|
||||
if (x > bbox[2]) {
|
||||
bbox[2] = x;
|
||||
}
|
||||
if (y > bbox[3]) {
|
||||
bbox[3] = y;
|
||||
}
|
||||
|
||||
if (!*(sst->initialized)) {
|
||||
if (x < 0 || x >= (1LL << 32) || y < 0 || y >= (1LL << 32)) {
|
||||
*(sst->initial_x) = 1LL << 31;
|
||||
*(sst->initial_y) = 1LL << 31;
|
||||
} else {
|
||||
*(sst->initial_x) = (((x + COORD_OFFSET) >> geometry_scale) << geometry_scale) - COORD_OFFSET;
|
||||
*(sst->initial_y) = (((y + COORD_OFFSET) >> geometry_scale) << geometry_scale) - COORD_OFFSET;
|
||||
}
|
||||
|
||||
*(sst->initialized) = 1;
|
||||
}
|
||||
|
||||
if (additional[A_GRID_LOW_ZOOMS]) {
|
||||
// If we are gridding, snap to the maxzoom grid in case the incoming data
|
||||
// is already supposed to be aligned to tile boundaries (but is not, exactly,
|
||||
// because of rounding error during projection).
|
||||
|
||||
geom[i].x = std::round(x * scale);
|
||||
geom[i].y = std::round(y * scale);
|
||||
} else {
|
||||
geom[i].x = SHIFT_RIGHT(x);
|
||||
geom[i].y = SHIFT_RIGHT(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return geom.size();
|
||||
}
|
||||
|
||||
static std::string strip_zeroes(std::string s) {
|
||||
// Doesn't do anything special with '-' followed by leading zeros
|
||||
// since integer IDs must be positive
|
||||
|
||||
while (s.size() > 0 && s[0] == '0') {
|
||||
s.erase(s.begin());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// called from frontends
|
||||
int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
|
||||
struct reader *r = &(*sst->readers)[sst->segment];
|
||||
|
||||
sf.bbox[0] = LLONG_MAX;
|
||||
sf.bbox[1] = LLONG_MAX;
|
||||
sf.bbox[2] = LLONG_MIN;
|
||||
sf.bbox[3] = LLONG_MIN;
|
||||
scale_geometry(sst, sf.bbox, sf.geometry);
|
||||
|
||||
// This has to happen after scaling so that the wraparound detection has happened first.
|
||||
// Otherwise the inner/outer calculation will be confused by bad geometries.
|
||||
if (sf.t == VT_POLYGON) {
|
||||
sf.geometry = fix_polygon(sf.geometry);
|
||||
}
|
||||
|
||||
for (auto &c : clipbboxes) {
|
||||
if (sf.t == VT_POLYGON) {
|
||||
sf.geometry = simple_clip_poly(sf.geometry, SHIFT_RIGHT(c.minx), SHIFT_RIGHT(c.miny), SHIFT_RIGHT(c.maxx), SHIFT_RIGHT(c.maxy));
|
||||
} else if (sf.t == VT_LINE) {
|
||||
sf.geometry = clip_lines(sf.geometry, SHIFT_RIGHT(c.minx), SHIFT_RIGHT(c.miny), SHIFT_RIGHT(c.maxx), SHIFT_RIGHT(c.maxy));
|
||||
sf.geometry = remove_noop(sf.geometry, sf.t, 0);
|
||||
} else if (sf.t == VT_POINT) {
|
||||
sf.geometry = clip_point(sf.geometry, SHIFT_RIGHT(c.minx), SHIFT_RIGHT(c.miny), SHIFT_RIGHT(c.maxx), SHIFT_RIGHT(c.maxy));
|
||||
}
|
||||
|
||||
sf.bbox[0] = LLONG_MAX;
|
||||
sf.bbox[1] = LLONG_MAX;
|
||||
sf.bbox[2] = LLONG_MIN;
|
||||
sf.bbox[3] = LLONG_MIN;
|
||||
|
||||
for (auto &g : sf.geometry) {
|
||||
long long x = SHIFT_LEFT(g.x);
|
||||
long long y = SHIFT_LEFT(g.y);
|
||||
|
||||
if (x < sf.bbox[0]) {
|
||||
sf.bbox[0] = x;
|
||||
}
|
||||
if (y < sf.bbox[1]) {
|
||||
sf.bbox[1] = y;
|
||||
}
|
||||
if (x > sf.bbox[2]) {
|
||||
sf.bbox[2] = x;
|
||||
}
|
||||
if (y > sf.bbox[3]) {
|
||||
sf.bbox[3] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sf.geometry.size() == 0) {
|
||||
// Feature was clipped away
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!sf.has_id) {
|
||||
if (additional[A_GENERATE_IDS]) {
|
||||
sf.has_id = true;
|
||||
sf.id = sf.seq + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sst->want_dist) {
|
||||
std::vector<unsigned long long> locs;
|
||||
for (size_t i = 0; i < sf.geometry.size(); i++) {
|
||||
if (sf.geometry[i].op == VT_MOVETO || sf.geometry[i].op == VT_LINETO) {
|
||||
locs.push_back(encode_index(SHIFT_LEFT(sf.geometry[i].x), SHIFT_LEFT(sf.geometry[i].y)));
|
||||
}
|
||||
}
|
||||
std::sort(locs.begin(), locs.end());
|
||||
size_t n = 0;
|
||||
double sum = 0;
|
||||
for (size_t i = 1; i < locs.size(); i++) {
|
||||
if (locs[i - 1] != locs[i]) {
|
||||
sum += log(locs[i] - locs[i - 1]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
double avg = exp(sum / n);
|
||||
// Convert approximately from tile units to feet
|
||||
double dist_ft = sqrt(avg) / 33;
|
||||
|
||||
*(sst->dist_sum) += log(dist_ft) * n;
|
||||
*(sst->dist_count) += n;
|
||||
}
|
||||
locs.clear();
|
||||
}
|
||||
|
||||
bool inline_meta = true;
|
||||
// Don't inline metadata for features that will span several tiles at maxzoom
|
||||
if (sf.geometry.size() > 0 && (sf.bbox[2] < sf.bbox[0] || sf.bbox[3] < sf.bbox[1])) {
|
||||
fprintf(stderr, "Internal error: impossible feature bounding box %llx,%llx,%llx,%llx\n", sf.bbox[0], sf.bbox[1], sf.bbox[2], sf.bbox[3]);
|
||||
}
|
||||
if (sf.bbox[0] == LLONG_MAX) {
|
||||
// No bounding box (empty geometry)
|
||||
// Shouldn't happen, but avoid arithmetic overflow below
|
||||
} else if (sf.bbox[2] - sf.bbox[0] > (2LL << (32 - sst->maxzoom)) || sf.bbox[3] - sf.bbox[1] > (2LL << (32 - sst->maxzoom))) {
|
||||
inline_meta = false;
|
||||
|
||||
if (prevent[P_CLIPPING]) {
|
||||
static std::atomic<long long> warned(0);
|
||||
long long extent = ((sf.bbox[2] - sf.bbox[0]) / ((1LL << (32 - sst->maxzoom)) + 1)) * ((sf.bbox[3] - sf.bbox[1]) / ((1LL << (32 - sst->maxzoom)) + 1));
|
||||
if (extent > warned) {
|
||||
fprintf(stderr, "Warning: %s:%d: Large unclipped (-pc) feature may be duplicated across %lld tiles\n", sst->fname, sst->line, extent);
|
||||
warned = extent;
|
||||
|
||||
if (extent > 10000) {
|
||||
fprintf(stderr, "Exiting because this can't be right.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double extent = 0;
|
||||
if (additional[A_DROP_SMALLEST_AS_NEEDED] || additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
|
||||
if (sf.t == VT_POLYGON) {
|
||||
for (size_t i = 0; i < sf.geometry.size(); i++) {
|
||||
if (sf.geometry[i].op == VT_MOVETO) {
|
||||
size_t j;
|
||||
for (j = i + 1; j < sf.geometry.size(); j++) {
|
||||
if (sf.geometry[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
extent += get_area(sf.geometry, i, j);
|
||||
i = j - 1;
|
||||
}
|
||||
}
|
||||
} else if (sf.t == VT_LINE) {
|
||||
for (size_t i = 1; i < sf.geometry.size(); i++) {
|
||||
if (sf.geometry[i].op == VT_LINETO) {
|
||||
double xd = sf.geometry[i].x - sf.geometry[i - 1].x;
|
||||
double yd = sf.geometry[i].y - sf.geometry[i - 1].y;
|
||||
extent += sqrt(xd * xd + yd * yd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (extent <= LLONG_MAX) {
|
||||
sf.extent = (long long) extent;
|
||||
} else {
|
||||
sf.extent = LLONG_MAX;
|
||||
}
|
||||
|
||||
if (!prevent[P_INPUT_ORDER]) {
|
||||
sf.seq = 0;
|
||||
}
|
||||
|
||||
long long bbox_index;
|
||||
|
||||
// Calculate the center even if off the edge of the plane,
|
||||
// and then mask to bring it back into the addressable area
|
||||
long long midx = (sf.bbox[0] / 2 + sf.bbox[2] / 2) & ((1LL << 32) - 1);
|
||||
long long midy = (sf.bbox[1] / 2 + sf.bbox[3] / 2) & ((1LL << 32) - 1);
|
||||
bbox_index = encode_index(midx, midy);
|
||||
|
||||
if (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED] || additional[A_CALCULATE_FEATURE_DENSITY] || additional[A_INCREASE_GAMMA_AS_NEEDED] || sst->uses_gamma || cluster_distance != 0) {
|
||||
sf.index = bbox_index;
|
||||
} else {
|
||||
sf.index = 0;
|
||||
}
|
||||
|
||||
if (sst->layermap->count(sf.layername) == 0) {
|
||||
sst->layermap->insert(std::pair<std::string, layermap_entry>(sf.layername, layermap_entry(sst->layermap->size())));
|
||||
}
|
||||
|
||||
auto ai = sst->layermap->find(sf.layername);
|
||||
if (ai != sst->layermap->end()) {
|
||||
sf.layer = ai->second.id;
|
||||
|
||||
if (!sst->filters) {
|
||||
if (sf.t == VT_POINT) {
|
||||
ai->second.points++;
|
||||
} else if (sf.t == VT_LINE) {
|
||||
ai->second.lines++;
|
||||
} else if (sf.t == VT_POLYGON) {
|
||||
ai->second.polygons++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Internal error: can't find layer name %s\n", sf.layername.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (ssize_t i = (ssize_t) sf.full_keys.size() - 1; i >= 0; i--) {
|
||||
coerce_value(sf.full_keys[i], sf.full_values[i].type, sf.full_values[i].s, sst->attribute_types);
|
||||
|
||||
if (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());
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
char *err;
|
||||
long long id_value = strtoull(sf.full_values[i].s.c_str(), &err, 10);
|
||||
|
||||
if (err != NULL && *err != '\0') {
|
||||
static bool warned_frac = false;
|
||||
|
||||
if (!warned_frac) {
|
||||
fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", sf.full_values[i].s.c_str());
|
||||
warned_frac = true;
|
||||
}
|
||||
} else if (std::to_string(id_value) != strip_zeroes(sf.full_values[i].s)) {
|
||||
static bool warned = false;
|
||||
|
||||
if (!warned) {
|
||||
fprintf(stderr, "Warning: Can't represent too-large feature ID %s\n", sf.full_values[i].s.c_str());
|
||||
warned = true;
|
||||
}
|
||||
} else {
|
||||
sf.id = id_value;
|
||||
sf.has_id = true;
|
||||
|
||||
sf.full_keys.erase(sf.full_keys.begin() + i);
|
||||
sf.full_values.erase(sf.full_values.begin() + i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sst->exclude_all) {
|
||||
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) {
|
||||
sf.full_keys.erase(sf.full_keys.begin() + i);
|
||||
sf.full_values.erase(sf.full_values.begin() + i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sst->filters) {
|
||||
for (size_t i = 0; i < sf.full_keys.size(); i++) {
|
||||
type_and_string attrib;
|
||||
attrib.type = sf.full_values[i].type;
|
||||
attrib.string = sf.full_values[i].s;
|
||||
|
||||
auto fk = sst->layermap->find(sf.layername);
|
||||
add_to_file_keys(fk->second.file_keys, sf.full_keys[i], attrib);
|
||||
}
|
||||
}
|
||||
|
||||
if (inline_meta) {
|
||||
sf.metapos = -1;
|
||||
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));
|
||||
sf.values.push_back(addpool(r->poolfile, r->treefile, sf.full_values[i].s.c_str(), sf.full_values[i].type));
|
||||
}
|
||||
} else {
|
||||
sf.metapos = r->metapos;
|
||||
serialize_long_long(r->metafile, sf.full_keys.size(), &r->metapos, sst->fname);
|
||||
for (size_t i = 0; i < sf.full_keys.size(); i++) {
|
||||
serialize_long_long(r->metafile, addpool(r->poolfile, r->treefile, sf.full_keys[i].c_str(), mvt_string), &r->metapos, sst->fname);
|
||||
serialize_long_long(r->metafile, addpool(r->poolfile, r->treefile, sf.full_values[i].s.c_str(), sf.full_values[i].type), &r->metapos, sst->fname);
|
||||
}
|
||||
}
|
||||
|
||||
long long geomstart = r->geompos;
|
||||
serialize_feature(r->geomfile, &sf, &r->geompos, sst->fname, SHIFT_RIGHT(*(sst->initial_x)), SHIFT_RIGHT(*(sst->initial_y)), false);
|
||||
|
||||
struct index index;
|
||||
index.start = geomstart;
|
||||
index.end = r->geompos;
|
||||
index.segment = sst->segment;
|
||||
index.seq = *(sst->layer_seq);
|
||||
index.t = sf.t;
|
||||
index.ix = bbox_index;
|
||||
|
||||
fwrite_check(&index, sizeof(struct index), 1, r->indexfile, sst->fname);
|
||||
r->indexpos += sizeof(struct index);
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
if (sf.bbox[i] < r->file_bbox[i]) {
|
||||
r->file_bbox[i] = sf.bbox[i];
|
||||
}
|
||||
}
|
||||
for (size_t i = 2; i < 4; i++) {
|
||||
if (sf.bbox[i] > r->file_bbox[i]) {
|
||||
r->file_bbox[i] = sf.bbox[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (*(sst->progress_seq) % 10000 == 0) {
|
||||
checkdisk(sst->readers);
|
||||
if (!quiet && !quiet_progress && progress_time()) {
|
||||
fprintf(stderr, "Read %.2f million features\r", *sst->progress_seq / 1000000.0);
|
||||
}
|
||||
}
|
||||
(*(sst->progress_seq))++;
|
||||
(*(sst->layer_seq))++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void coerce_value(std::string const &key, int &vt, std::string &val, std::map<std::string, int> const *attribute_types) {
|
||||
auto a = (*attribute_types).find(key);
|
||||
if (a != attribute_types->end()) {
|
||||
if (a->second == mvt_string) {
|
||||
vt = mvt_string;
|
||||
} else if (a->second == mvt_float) {
|
||||
vt = mvt_double;
|
||||
val = milo::dtoa_milo(atof(val.c_str()));
|
||||
} else if (a->second == mvt_int) {
|
||||
vt = mvt_double;
|
||||
if (val.size() == 0) {
|
||||
val = "0";
|
||||
}
|
||||
|
||||
for (size_t ii = 0; ii < val.size(); ii++) {
|
||||
char c = val[ii];
|
||||
if (c < '0' || c > '9') {
|
||||
val = std::to_string(round(atof(val.c_str())));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (a->second == mvt_bool) {
|
||||
if (val == "false" || val == "0" || val == "null" || val.size() == 0 || (vt == mvt_double && atof(val.c_str()) == 0)) {
|
||||
vt = mvt_bool;
|
||||
val = "false";
|
||||
} else {
|
||||
vt = mvt_bool;
|
||||
val = "true";
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Can't happen: attribute type %d\n", a->second);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
182
serial.hpp
182
serial.hpp
@ -1,24 +1,11 @@
|
||||
#ifndef SERIAL_HPP
|
||||
#define SERIAL_HPP
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <sys/stat.h>
|
||||
#include "geometry.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
|
||||
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname);
|
||||
|
||||
void serialize_int(FILE *out, int n, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_long_long(FILE *out, long long n, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_ulong_long(FILE *out, unsigned long long n, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_byte(FILE *out, signed char n, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_uint(FILE *out, unsigned n, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_string(FILE *out, const char *s, std::atomic<long long> *fpos, const char *fname);
|
||||
void serialize_int(FILE *out, int n, long long *fpos, const char *fname);
|
||||
void serialize_long_long(FILE *out, long long n, long long *fpos, const char *fname);
|
||||
void serialize_ulong_long(FILE *out, unsigned long long n, long long *fpos, const char *fname);
|
||||
void serialize_byte(FILE *out, signed char n, long long *fpos, const char *fname);
|
||||
void serialize_uint(FILE *out, unsigned n, long long *fpos, const char *fname);
|
||||
void serialize_string(FILE *out, const char *s, long long *fpos, const char *fname);
|
||||
|
||||
void deserialize_int(char **f, int *n);
|
||||
void deserialize_long_long(char **f, long long *n);
|
||||
@ -26,146 +13,37 @@ void deserialize_ulong_long(char **f, unsigned long long *n);
|
||||
void deserialize_uint(char **f, unsigned *n);
|
||||
void deserialize_byte(char **f, signed char *n);
|
||||
|
||||
int deserialize_int_io(FILE *f, int *n, std::atomic<long long> *geompos);
|
||||
int deserialize_long_long_io(FILE *f, long long *n, std::atomic<long long> *geompos);
|
||||
int deserialize_ulong_long_io(FILE *f, unsigned long long *n, std::atomic<long long> *geompos);
|
||||
int deserialize_uint_io(FILE *f, unsigned *n, std::atomic<long long> *geompos);
|
||||
int deserialize_byte_io(FILE *f, signed char *n, std::atomic<long long> *geompos);
|
||||
|
||||
struct serial_val {
|
||||
int type = 0;
|
||||
std::string s = "";
|
||||
};
|
||||
int deserialize_int_io(FILE *f, int *n, long long *geompos);
|
||||
int deserialize_long_long_io(FILE *f, long long *n, long long *geompos);
|
||||
int deserialize_ulong_long_io(FILE *f, unsigned long long *n, long long *geompos);
|
||||
int deserialize_uint_io(FILE *f, unsigned *n, long long *geompos);
|
||||
int deserialize_byte_io(FILE *f, signed char *n, long long *geompos);
|
||||
|
||||
struct serial_feature {
|
||||
long long layer = 0;
|
||||
int segment = 0;
|
||||
long long seq = 0;
|
||||
long long layer;
|
||||
int segment;
|
||||
long long seq;
|
||||
|
||||
signed char t = 0;
|
||||
signed char feature_minzoom = 0;
|
||||
signed char t;
|
||||
signed char feature_minzoom;
|
||||
|
||||
bool has_id = false;
|
||||
unsigned long long id = 0;
|
||||
bool has_id;
|
||||
unsigned long long id;
|
||||
|
||||
bool has_tippecanoe_minzoom = false;
|
||||
int tippecanoe_minzoom = 0;
|
||||
bool has_tippecanoe_minzoom;
|
||||
int tippecanoe_minzoom;
|
||||
|
||||
bool has_tippecanoe_maxzoom = false;
|
||||
int tippecanoe_maxzoom = 0;
|
||||
bool has_tippecanoe_maxzoom;
|
||||
int tippecanoe_maxzoom;
|
||||
|
||||
drawvec geometry = drawvec();
|
||||
unsigned long long index = 0;
|
||||
long long extent = 0;
|
||||
drawvec geometry;
|
||||
unsigned long long index;
|
||||
long long extent;
|
||||
|
||||
std::vector<long long> keys{};
|
||||
std::vector<long long> values{};
|
||||
// If >= 0, metadata is external
|
||||
long long metapos = 0;
|
||||
|
||||
// XXX This isn't serialized. Should it be here?
|
||||
long long bbox[4] = {0, 0, 0, 0};
|
||||
std::vector<std::string> full_keys{};
|
||||
std::vector<serial_val> full_values{};
|
||||
std::string layername = "";
|
||||
bool dropped = false;
|
||||
size_t m;
|
||||
std::vector<long long> keys;
|
||||
std::vector<long long> values;
|
||||
long long metapos;
|
||||
};
|
||||
|
||||
void serialize_feature(FILE *geomfile, serial_feature *sf, std::atomic<long long> *geompos, const char *fname, long long wx, long long wy, bool include_minzoom);
|
||||
serial_feature deserialize_feature(FILE *geoms, std::atomic<long long> *geompos_in, char *metabase, long long *meta_off, unsigned z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y);
|
||||
|
||||
struct reader {
|
||||
int metafd = -1;
|
||||
int poolfd = -1;
|
||||
int treefd = -1;
|
||||
int geomfd = -1;
|
||||
int indexfd = -1;
|
||||
|
||||
FILE *metafile = NULL;
|
||||
struct memfile *poolfile = NULL;
|
||||
struct memfile *treefile = NULL;
|
||||
FILE *geomfile = NULL;
|
||||
FILE *indexfile = NULL;
|
||||
|
||||
std::atomic<long long> metapos;
|
||||
std::atomic<long long> geompos;
|
||||
std::atomic<long long> indexpos;
|
||||
|
||||
long long file_bbox[4] = {0, 0, 0, 0};
|
||||
|
||||
struct stat geomst {};
|
||||
struct stat metast {};
|
||||
|
||||
char *geom_map = NULL;
|
||||
|
||||
reader()
|
||||
: metapos(0), geompos(0), indexpos(0) {
|
||||
}
|
||||
|
||||
reader(reader const &r) {
|
||||
metafd = r.metafd;
|
||||
poolfd = r.poolfd;
|
||||
treefd = r.treefd;
|
||||
geomfd = r.geomfd;
|
||||
indexfd = r.indexfd;
|
||||
|
||||
metafile = r.metafile;
|
||||
poolfile = r.poolfile;
|
||||
treefile = r.treefile;
|
||||
geomfile = r.geomfile;
|
||||
indexfile = r.indexfile;
|
||||
|
||||
long long p = r.metapos;
|
||||
metapos = p;
|
||||
|
||||
p = r.geompos;
|
||||
geompos = p;
|
||||
|
||||
p = r.indexpos;
|
||||
indexpos = p;
|
||||
|
||||
memcpy(file_bbox, r.file_bbox, sizeof(file_bbox));
|
||||
|
||||
geomst = r.geomst;
|
||||
metast = r.metast;
|
||||
|
||||
geom_map = r.geom_map;
|
||||
}
|
||||
};
|
||||
|
||||
struct serialization_state {
|
||||
const char *fname = NULL; // source file name
|
||||
int line = 0; // user-oriented location within source for error reports
|
||||
|
||||
std::atomic<long long> *layer_seq = NULL; // sequence within current layer
|
||||
std::atomic<long long> *progress_seq = NULL; // overall sequence for progress indicator
|
||||
|
||||
std::vector<struct reader> *readers = NULL; // array of data for each input thread
|
||||
int segment = 0; // the current input thread
|
||||
|
||||
unsigned *initial_x = NULL; // relative offset of all geometries
|
||||
unsigned *initial_y = NULL;
|
||||
int *initialized = NULL;
|
||||
|
||||
double *dist_sum = NULL; // running tally for calculation of resolution within features
|
||||
size_t *dist_count = NULL;
|
||||
bool want_dist = false;
|
||||
|
||||
int maxzoom = 0;
|
||||
int basezoom = 0;
|
||||
|
||||
bool filters = false;
|
||||
bool uses_gamma = false;
|
||||
|
||||
std::map<std::string, layermap_entry> *layermap = NULL;
|
||||
|
||||
std::map<std::string, int> const *attribute_types = NULL;
|
||||
std::set<std::string> *exclude = NULL;
|
||||
std::set<std::string> *include = NULL;
|
||||
int exclude_all = 0;
|
||||
};
|
||||
|
||||
int serialize_feature(struct serialization_state *sst, serial_feature &sf);
|
||||
void coerce_value(std::string const &key, int &vt, std::string &val, std::map<std::string, int> const *attribute_types);
|
||||
|
||||
#endif
|
||||
void serialize_feature(FILE *geomfile, serial_feature *sf, long long *geompos, const char *fname, long long wx, long long wy, bool include_minzoom);
|
||||
|
@ -1,100 +0,0 @@
|
||||
{ "type": "Feature", "properties": { "thesum": 1, "themax": 1, "themin": 1, "theproduct": 1, "themean": 1, "theconcat": 1, "thecomma": 1 }, "geometry": { "type": "Point", "coordinates": [ 134.198884,-54.297477 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 2, "themax": 2, "themin": 2, "theproduct": 2, "themean": 2, "theconcat": 2, "thecomma": 2 }, "geometry": { "type": "Point", "coordinates": [ 14.059736,46.728490 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 3, "themax": 3, "themin": 3, "theproduct": 3, "themean": 3, "theconcat": 3, "thecomma": 3 }, "geometry": { "type": "Point", "coordinates": [ -147.369727,84.781281 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 4, "themax": 4, "themin": 4, "theproduct": 4, "themean": 4, "theconcat": 4, "thecomma": 4 }, "geometry": { "type": "Point", "coordinates": [ -66.234387,89.199903 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 5, "themax": 5, "themin": 5, "theproduct": 5, "themean": 5, "theconcat": 5, "thecomma": 5 }, "geometry": { "type": "Point", "coordinates": [ -153.412664,29.072260 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 6, "themax": 6, "themin": 6, "theproduct": 6, "themean": 6, "theconcat": 6, "thecomma": 6 }, "geometry": { "type": "Point", "coordinates": [ 170.262110,-59.450058 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 7, "themax": 7, "themin": 7, "theproduct": 7, "themean": 7, "theconcat": 7, "thecomma": 7 }, "geometry": { "type": "Point", "coordinates": [ 126.605140,8.723849 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 8, "themax": 8, "themin": 8, "theproduct": 8, "themean": 8, "theconcat": 8, "thecomma": 8 }, "geometry": { "type": "Point", "coordinates": [ 161.440413,-40.375296 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 9, "themax": 9, "themin": 9, "theproduct": 9, "themean": 9, "theconcat": 9, "thecomma": 9 }, "geometry": { "type": "Point", "coordinates": [ -168.588146,-52.640848 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 10, "themax": 10, "themin": 10, "theproduct": 10, "themean": 10, "theconcat": 10, "thecomma": 10 }, "geometry": { "type": "Point", "coordinates": [ 87.732615,-76.468219 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 11, "themax": 11, "themin": 11, "theproduct": 11, "themean": 11, "theconcat": 11, "thecomma": 11 }, "geometry": { "type": "Point", "coordinates": [ 30.857236,80.182977 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 12, "themax": 12, "themin": 12, "theproduct": 12, "themean": 12, "theconcat": 12, "thecomma": 12 }, "geometry": { "type": "Point", "coordinates": [ -145.428454,26.334493 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 13, "themax": 13, "themin": 13, "theproduct": 13, "themean": 13, "theconcat": 13, "thecomma": 13 }, "geometry": { "type": "Point", "coordinates": [ -3.709986,47.351847 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 14, "themax": 14, "themin": 14, "theproduct": 14, "themean": 14, "theconcat": 14, "thecomma": 14 }, "geometry": { "type": "Point", "coordinates": [ -145.079976,80.547441 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 15, "themax": 15, "themin": 15, "theproduct": 15, "themean": 15, "theconcat": 15, "thecomma": 15 }, "geometry": { "type": "Point", "coordinates": [ 14.666648,-65.254575 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 16, "themax": 16, "themin": 16, "theproduct": 16, "themean": 16, "theconcat": 16, "thecomma": 16 }, "geometry": { "type": "Point", "coordinates": [ 24.659014,60.295014 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 17, "themax": 17, "themin": 17, "theproduct": 17, "themean": 17, "theconcat": 17, "thecomma": 17 }, "geometry": { "type": "Point", "coordinates": [ 110.427380,38.364152 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 18, "themax": 18, "themin": 18, "theproduct": 18, "themean": 18, "theconcat": 18, "thecomma": 18 }, "geometry": { "type": "Point", "coordinates": [ 6.564431,-44.802836 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 19, "themax": 19, "themin": 19, "theproduct": 19, "themean": 19, "theconcat": 19, "thecomma": 19 }, "geometry": { "type": "Point", "coordinates": [ -25.148684,-41.191936 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 20, "themax": 20, "themin": 20, "theproduct": 20, "themean": 20, "theconcat": 20, "thecomma": 20 }, "geometry": { "type": "Point", "coordinates": [ 94.640674,87.473404 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 21, "themax": 21, "themin": 21, "theproduct": 21, "themean": 21, "theconcat": 21, "thecomma": 21 }, "geometry": { "type": "Point", "coordinates": [ -15.166749,44.154022 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 22, "themax": 22, "themin": 22, "theproduct": 22, "themean": 22, "theconcat": 22, "thecomma": 22 }, "geometry": { "type": "Point", "coordinates": [ -83.839224,-22.324076 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 23, "themax": 23, "themin": 23, "theproduct": 23, "themean": 23, "theconcat": 23, "thecomma": 23 }, "geometry": { "type": "Point", "coordinates": [ -131.431059,-48.656317 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 24, "themax": 24, "themin": 24, "theproduct": 24, "themean": 24, "theconcat": 24, "thecomma": 24 }, "geometry": { "type": "Point", "coordinates": [ 13.458676,-81.541789 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 25, "themax": 25, "themin": 25, "theproduct": 25, "themean": 25, "theconcat": 25, "thecomma": 25 }, "geometry": { "type": "Point", "coordinates": [ 49.375287,54.035848 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 26, "themax": 26, "themin": 26, "theproduct": 26, "themean": 26, "theconcat": 26, "thecomma": 26 }, "geometry": { "type": "Point", "coordinates": [ 44.023761,42.750924 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 27, "themax": 27, "themin": 27, "theproduct": 27, "themean": 27, "theconcat": 27, "thecomma": 27 }, "geometry": { "type": "Point", "coordinates": [ 23.815303,87.689971 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 28, "themax": 28, "themin": 28, "theproduct": 28, "themean": 28, "theconcat": 28, "thecomma": 28 }, "geometry": { "type": "Point", "coordinates": [ -108.418101,69.859222 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 29, "themax": 29, "themin": 29, "theproduct": 29, "themean": 29, "theconcat": 29, "thecomma": 29 }, "geometry": { "type": "Point", "coordinates": [ -162.422461,-72.828993 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 30, "themax": 30, "themin": 30, "theproduct": 30, "themean": 30, "theconcat": 30, "thecomma": 30 }, "geometry": { "type": "Point", "coordinates": [ 41.555960,87.834643 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 31, "themax": 31, "themin": 31, "theproduct": 31, "themean": 31, "theconcat": 31, "thecomma": 31 }, "geometry": { "type": "Point", "coordinates": [ 151.433696,-2.049808 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 32, "themax": 32, "themin": 32, "theproduct": 32, "themean": 32, "theconcat": 32, "thecomma": 32 }, "geometry": { "type": "Point", "coordinates": [ -156.347397,-54.157799 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 33, "themax": 33, "themin": 33, "theproduct": 33, "themean": 33, "theconcat": 33, "thecomma": 33 }, "geometry": { "type": "Point", "coordinates": [ 177.449262,76.384948 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 34, "themax": 34, "themin": 34, "theproduct": 34, "themean": 34, "theconcat": 34, "thecomma": 34 }, "geometry": { "type": "Point", "coordinates": [ 67.516237,89.283900 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 35, "themax": 35, "themin": 35, "theproduct": 35, "themean": 35, "theconcat": 35, "thecomma": 35 }, "geometry": { "type": "Point", "coordinates": [ 57.957991,-82.230182 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 36, "themax": 36, "themin": 36, "theproduct": 36, "themean": 36, "theconcat": 36, "thecomma": 36 }, "geometry": { "type": "Point", "coordinates": [ 152.745823,-78.389341 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 37, "themax": 37, "themin": 37, "theproduct": 37, "themean": 37, "theconcat": 37, "thecomma": 37 }, "geometry": { "type": "Point", "coordinates": [ -79.735349,80.847381 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 38, "themax": 38, "themin": 38, "theproduct": 38, "themean": 38, "theconcat": 38, "thecomma": 38 }, "geometry": { "type": "Point", "coordinates": [ -176.469083,-1.175014 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 39, "themax": 39, "themin": 39, "theproduct": 39, "themean": 39, "theconcat": 39, "thecomma": 39 }, "geometry": { "type": "Point", "coordinates": [ 20.369644,-44.945809 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 40, "themax": 40, "themin": 40, "theproduct": 40, "themean": 40, "theconcat": 40, "thecomma": 40 }, "geometry": { "type": "Point", "coordinates": [ 75.300338,89.728838 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 41, "themax": 41, "themin": 41, "theproduct": 41, "themean": 41, "theconcat": 41, "thecomma": 41 }, "geometry": { "type": "Point", "coordinates": [ -60.903503,-89.434640 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 42, "themax": 42, "themin": 42, "theproduct": 42, "themean": 42, "theconcat": 42, "thecomma": 42 }, "geometry": { "type": "Point", "coordinates": [ -116.214566,-78.600594 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 43, "themax": 43, "themin": 43, "theproduct": 43, "themean": 43, "theconcat": 43, "thecomma": 43 }, "geometry": { "type": "Point", "coordinates": [ -168.143210,-37.381940 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 44, "themax": 44, "themin": 44, "theproduct": 44, "themean": 44, "theconcat": 44, "thecomma": 44 }, "geometry": { "type": "Point", "coordinates": [ 146.600367,-65.112907 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 45, "themax": 45, "themin": 45, "theproduct": 45, "themean": 45, "theconcat": 45, "thecomma": 45 }, "geometry": { "type": "Point", "coordinates": [ -144.960448,89.877412 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 46, "themax": 46, "themin": 46, "theproduct": 46, "themean": 46, "theconcat": 46, "thecomma": 46 }, "geometry": { "type": "Point", "coordinates": [ 37.779538,-9.255682 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 47, "themax": 47, "themin": 47, "theproduct": 47, "themean": 47, "theconcat": 47, "thecomma": 47 }, "geometry": { "type": "Point", "coordinates": [ 141.921366,-86.191382 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 48, "themax": 48, "themin": 48, "theproduct": 48, "themean": 48, "theconcat": 48, "thecomma": 48 }, "geometry": { "type": "Point", "coordinates": [ 3.757458,-46.957098 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 49, "themax": 49, "themin": 49, "theproduct": 49, "themean": 49, "theconcat": 49, "thecomma": 49 }, "geometry": { "type": "Point", "coordinates": [ -178.557808,-17.999930 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 50, "themax": 50, "themin": 50, "theproduct": 50, "themean": 50, "theconcat": 50, "thecomma": 50 }, "geometry": { "type": "Point", "coordinates": [ -94.775598,89.666291 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 51, "themax": 51, "themin": 51, "theproduct": 51, "themean": 51, "theconcat": 51, "thecomma": 51 }, "geometry": { "type": "Point", "coordinates": [ -105.311977,25.819445 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 52, "themax": 52, "themin": 52, "theproduct": 52, "themean": 52, "theconcat": 52, "thecomma": 52 }, "geometry": { "type": "Point", "coordinates": [ 116.462344,-73.172234 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 53, "themax": 53, "themin": 53, "theproduct": 53, "themean": 53, "theconcat": 53, "thecomma": 53 }, "geometry": { "type": "Point", "coordinates": [ -84.902185,62.166503 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 54, "themax": 54, "themin": 54, "theproduct": 54, "themean": 54, "theconcat": 54, "thecomma": 54 }, "geometry": { "type": "Point", "coordinates": [ -141.394664,-11.763473 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 55, "themax": 55, "themin": 55, "theproduct": 55, "themean": 55, "theconcat": 55, "thecomma": 55 }, "geometry": { "type": "Point", "coordinates": [ 96.026399,83.713544 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 56, "themax": 56, "themin": 56, "theproduct": 56, "themean": 56, "theconcat": 56, "thecomma": 56 }, "geometry": { "type": "Point", "coordinates": [ -154.653153,-89.307708 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 57, "themax": 57, "themin": 57, "theproduct": 57, "themean": 57, "theconcat": 57, "thecomma": 57 }, "geometry": { "type": "Point", "coordinates": [ -71.769818,83.010189 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 58, "themax": 58, "themin": 58, "theproduct": 58, "themean": 58, "theconcat": 58, "thecomma": 58 }, "geometry": { "type": "Point", "coordinates": [ 141.629089,-84.969764 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 59, "themax": 59, "themin": 59, "theproduct": 59, "themean": 59, "theconcat": 59, "thecomma": 59 }, "geometry": { "type": "Point", "coordinates": [ -146.893857,-72.900555 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 60, "themax": 60, "themin": 60, "theproduct": 60, "themean": 60, "theconcat": 60, "thecomma": 60 }, "geometry": { "type": "Point", "coordinates": [ 13.616243,86.468765 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 61, "themax": 61, "themin": 61, "theproduct": 61, "themean": 61, "theconcat": 61, "thecomma": 61 }, "geometry": { "type": "Point", "coordinates": [ 146.239761,-77.415130 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 62, "themax": 62, "themin": 62, "theproduct": 62, "themean": 62, "theconcat": 62, "thecomma": 62 }, "geometry": { "type": "Point", "coordinates": [ 120.720040,34.052368 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 63, "themax": 63, "themin": 63, "theproduct": 63, "themean": 63, "theconcat": 63, "thecomma": 63 }, "geometry": { "type": "Point", "coordinates": [ -50.738121,-49.044879 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 64, "themax": 64, "themin": 64, "theproduct": 64, "themean": 64, "theconcat": 64, "thecomma": 64 }, "geometry": { "type": "Point", "coordinates": [ 159.682795,-17.137421 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 65, "themax": 65, "themin": 65, "theproduct": 65, "themean": 65, "theconcat": 65, "thecomma": 65 }, "geometry": { "type": "Point", "coordinates": [ -166.439086,2.775299 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 66, "themax": 66, "themin": 66, "theproduct": 66, "themean": 66, "theconcat": 66, "thecomma": 66 }, "geometry": { "type": "Point", "coordinates": [ -68.075084,-6.863559 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 67, "themax": 67, "themin": 67, "theproduct": 67, "themean": 67, "theconcat": 67, "thecomma": 67 }, "geometry": { "type": "Point", "coordinates": [ -177.446873,22.270257 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 68, "themax": 68, "themin": 68, "theproduct": 68, "themean": 68, "theconcat": 68, "thecomma": 68 }, "geometry": { "type": "Point", "coordinates": [ 116.851469,-89.159093 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 69, "themax": 69, "themin": 69, "theproduct": 69, "themean": 69, "theconcat": 69, "thecomma": 69 }, "geometry": { "type": "Point", "coordinates": [ 113.612595,13.841587 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 70, "themax": 70, "themin": 70, "theproduct": 70, "themean": 70, "theconcat": 70, "thecomma": 70 }, "geometry": { "type": "Point", "coordinates": [ 147.030951,-21.627240 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 71, "themax": 71, "themin": 71, "theproduct": 71, "themean": 71, "theconcat": 71, "thecomma": 71 }, "geometry": { "type": "Point", "coordinates": [ -171.838003,-55.021829 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 72, "themax": 72, "themin": 72, "theproduct": 72, "themean": 72, "theconcat": 72, "thecomma": 72 }, "geometry": { "type": "Point", "coordinates": [ -179.320808,-69.030987 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 73, "themax": 73, "themin": 73, "theproduct": 73, "themean": 73, "theconcat": 73, "thecomma": 73 }, "geometry": { "type": "Point", "coordinates": [ -41.291951,-0.546778 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 74, "themax": 74, "themin": 74, "theproduct": 74, "themean": 74, "theconcat": 74, "thecomma": 74 }, "geometry": { "type": "Point", "coordinates": [ -159.602264,33.516804 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 75, "themax": 75, "themin": 75, "theproduct": 75, "themean": 75, "theconcat": 75, "thecomma": 75 }, "geometry": { "type": "Point", "coordinates": [ -157.220701,-62.925493 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 76, "themax": 76, "themin": 76, "theproduct": 76, "themean": 76, "theconcat": 76, "thecomma": 76 }, "geometry": { "type": "Point", "coordinates": [ 35.449285,-21.548332 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 77, "themax": 77, "themin": 77, "theproduct": 77, "themean": 77, "theconcat": 77, "thecomma": 77 }, "geometry": { "type": "Point", "coordinates": [ 101.921779,85.807116 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 78, "themax": 78, "themin": 78, "theproduct": 78, "themean": 78, "theconcat": 78, "thecomma": 78 }, "geometry": { "type": "Point", "coordinates": [ -128.051674,83.348143 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 79, "themax": 79, "themin": 79, "theproduct": 79, "themean": 79, "theconcat": 79, "thecomma": 79 }, "geometry": { "type": "Point", "coordinates": [ 53.387503,-84.129458 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 80, "themax": 80, "themin": 80, "theproduct": 80, "themean": 80, "theconcat": 80, "thecomma": 80 }, "geometry": { "type": "Point", "coordinates": [ 58.273040,-53.030862 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 81, "themax": 81, "themin": 81, "theproduct": 81, "themean": 81, "theconcat": 81, "thecomma": 81 }, "geometry": { "type": "Point", "coordinates": [ 125.294919,18.287339 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 82, "themax": 82, "themin": 82, "theproduct": 82, "themean": 82, "theconcat": 82, "thecomma": 82 }, "geometry": { "type": "Point", "coordinates": [ 31.960448,55.594735 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 83, "themax": 83, "themin": 83, "theproduct": 83, "themean": 83, "theconcat": 83, "thecomma": 83 }, "geometry": { "type": "Point", "coordinates": [ 43.356826,-79.995205 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 84, "themax": 84, "themin": 84, "theproduct": 84, "themean": 84, "theconcat": 84, "thecomma": 84 }, "geometry": { "type": "Point", "coordinates": [ -117.349281,13.354257 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 85, "themax": 85, "themin": 85, "theproduct": 85, "themean": 85, "theconcat": 85, "thecomma": 85 }, "geometry": { "type": "Point", "coordinates": [ 7.392891,-80.387558 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 86, "themax": 86, "themin": 86, "theproduct": 86, "themean": 86, "theconcat": 86, "thecomma": 86 }, "geometry": { "type": "Point", "coordinates": [ -0.255971,-32.692982 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 87, "themax": 87, "themin": 87, "theproduct": 87, "themean": 87, "theconcat": 87, "thecomma": 87 }, "geometry": { "type": "Point", "coordinates": [ 165.528504,-69.862641 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 88, "themax": 88, "themin": 88, "theproduct": 88, "themean": 88, "theconcat": 88, "thecomma": 88 }, "geometry": { "type": "Point", "coordinates": [ -137.105444,-88.260877 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 89, "themax": 89, "themin": 89, "theproduct": 89, "themean": 89, "theconcat": 89, "thecomma": 89 }, "geometry": { "type": "Point", "coordinates": [ 28.112105,24.529585 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 90, "themax": 90, "themin": 90, "theproduct": 90, "themean": 90, "theconcat": 90, "thecomma": 90 }, "geometry": { "type": "Point", "coordinates": [ -29.013503,48.460714 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 91, "themax": 91, "themin": 91, "theproduct": 91, "themean": 91, "theconcat": 91, "thecomma": 91 }, "geometry": { "type": "Point", "coordinates": [ 114.967139,84.177181 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 92, "themax": 92, "themin": 92, "theproduct": 92, "themean": 92, "theconcat": 92, "thecomma": 92 }, "geometry": { "type": "Point", "coordinates": [ -63.363328,58.006985 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 93, "themax": 93, "themin": 93, "theproduct": 93, "themean": 93, "theconcat": 93, "thecomma": 93 }, "geometry": { "type": "Point", "coordinates": [ 169.765226,17.852955 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 94, "themax": 94, "themin": 94, "theproduct": 94, "themean": 94, "theconcat": 94, "thecomma": 94 }, "geometry": { "type": "Point", "coordinates": [ -132.507302,18.086814 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 95, "themax": 95, "themin": 95, "theproduct": 95, "themean": 95, "theconcat": 95, "thecomma": 95 }, "geometry": { "type": "Point", "coordinates": [ -56.678179,-62.556708 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 96, "themax": 96, "themin": 96, "theproduct": 96, "themean": 96, "theconcat": 96, "thecomma": 96 }, "geometry": { "type": "Point", "coordinates": [ 174.715105,-76.783064 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 97, "themax": 97, "themin": 97, "theproduct": 97, "themean": 97, "theconcat": 97, "thecomma": 97 }, "geometry": { "type": "Point", "coordinates": [ -19.142632,85.007238 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 98, "themax": 98, "themin": 98, "theproduct": 98, "themean": 98, "theconcat": 98, "thecomma": 98 }, "geometry": { "type": "Point", "coordinates": [ 58.241524,86.371735 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 99, "themax": 99, "themin": 99, "theproduct": 99, "themean": 99, "theconcat": 99, "thecomma": 99 }, "geometry": { "type": "Point", "coordinates": [ -27.756470,53.336764 ] } }
|
||||
{ "type": "Feature", "properties": { "thesum": 100, "themax": 100, "themin": 100, "theproduct": 100, "themean": 100, "theconcat": 100, "thecomma": 100 }, "geometry": { "type": "Point", "coordinates": [ -123.948513,-81.873970 ] } }
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,39 +0,0 @@
|
||||
{ "type": "Feature", "properties": { "booltype": null, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": "null", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": "", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": 0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": "0", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": "false", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": 1, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": 0.0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": "yes", "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "booltype": [ 2, 3 ], "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": null, "expect": "null" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": 2, "expect": "2" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": 2.5, "expect": "2.5" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": true, "expect": "true" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": false, "expect": "false" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": "something", "expect": "something" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "stringtype": [ 2, 3 ], "expect": "[2,3]" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": null, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": "5", "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": "5.6", "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": 5.6, "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": true, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": false, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": "", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": "yes", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": " 3", "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "inttype": [ 2, 3 ], "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": null, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": "5", "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": "5.6", "expect": 5.6 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": 5.6, "expect": 5.6 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": true, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": false, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": "", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": "yes", "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": " 3", "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
||||
{ "type": "Feature", "properties": { "floattype": [ 2, 3 ], "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
|
@ -1,95 +0,0 @@
|
||||
{ "type": "FeatureCollection", "properties": {
|
||||
"bounds": "0.000000,0.000000,0.000000,0.000000",
|
||||
"center": "0.000000,0.000000,0",
|
||||
"description": "tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"generator_options": "./tippecanoe -q -a@ -f -o tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json.check.mbtiles -z0 -Tinttype:int -Tfloattype:float -Tbooltype:bool -Tstringtype:string tests/attribute-type/in.json",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"booltype\": \"Boolean\", \"expect\": \"Mixed\", \"floattype\": \"Number\", \"inttype\": \"Number\", \"stringtype\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 39,\"geometry\": \"Point\",\"attributeCount\": 5,\"attributes\": [{\"attribute\": \"booltype\",\"count\": 2,\"type\": \"boolean\",\"values\": [false,true]},{\"attribute\": \"expect\",\"count\": 14,\"type\": \"mixed\",\"values\": [0,\"2\",\"2.5\",3,5,5.6,6,\"[2,3]\",\"false\",false,\"null\",\"something\",\"true\",true],\"min\": 0,\"max\": 6},{\"attribute\": \"floattype\",\"count\": 4,\"type\": \"number\",\"values\": [0,3,5,5.6],\"min\": 0,\"max\": 5.6},{\"attribute\": \"inttype\",\"count\": 5,\"type\": \"number\",\"values\": [0,0.000000,3.000000,5,6.000000],\"min\": 0,\"max\": 6},{\"attribute\": \"stringtype\",\"count\": 7,\"type\": \"string\",\"values\": [\"2\",\"2.5\",\"[2,3]\",\"false\",\"null\",\"something\",\"true\"]}]}]}}",
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json.check.mbtiles",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "null", "expect": "null" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "2", "expect": "2" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "2.5", "expect": "2.5" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "true", "expect": "true" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "false", "expect": "false" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "something", "expect": "something" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "stringtype": "[2,3]", "expect": "[2,3]" }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 5, "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 6, "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 6, "expect": 6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 3, "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "inttype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 5, "expect": 5 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 5.6, "expect": 5.6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 5.6, "expect": 5.6 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 3, "expect": 3 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "floattype": 0, "expect": 0 }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
|
||||
] }
|
||||
] }
|
||||
] }
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,249 +0,0 @@
|
||||
scalerank,natscale,labelrank,featurecla,name,namepar,namealt,diffascii,nameascii,adm0cap,capalt,capin,worldcity,megacity,sov0name,sov_a3,adm0name,adm0_a3,adm1name,iso_a2,note,latitude,longitude,changed,namediff,diffnote,pop_max,pop_min,pop_other,rank_max,rank_min,geonameid,meganame,ls_name,ls_match,checkme,min_zoom
|
||||
8,10,3,Admin-0 capital,Vatican City,,,0,Vatican City,1.00000000000,,,1.00000000000,0,Vatican (Holy Sea),VAT,Vatican (Holy See),VAT,Lazio,VA,,41.90001222640,12.44780838890,4.00000000000,0,Changed scale rank.,832,832,562430,2,2,6691831.00000000000,,Vatican City,1,0,7.0
|
||||
7,20,0,Admin-0 capital,San Marino,,,0,San Marino,1.00000000000,,,0.00000000000,0,San Marino,SMR,San Marino,SMR,,SM,,43.91715008450,12.46667028670,0.00000000000,0,,29579,29000,0,7,7,3168070.00000000000,,San Marino,1,5,6.1
|
||||
7,20,0,Admin-0 capital,Vaduz,,,0,Vaduz,1.00000000000,,,0.00000000000,0,Liechtenstein,LIE,Liechtenstein,LIE,,LI,,47.13372377430,9.51666947291,0.00000000000,0,,36281,5342,33009,7,5,3042030.00000000000,,Vaduz,1,0,6.7
|
||||
6,30,8,Admin-0 capital alt,Lobamba,,,0,Lobamba,0.00000000000,1,Legislative and,0.00000000000,0,Swaziland,SWZ,Swaziland,SWZ,Manzini,SZ,,-26.46666746140,31.19999710970,4.00000000000,0,Changed scale rank.,9782,4557,0,5,4,935048.00000000000,,Lobamba,1,5,6.0
|
||||
6,30,8,Admin-0 capital,Luxembourg,,,0,Luxembourg,1.00000000000,,,0.00000000000,0,Luxembourg,LUX,Luxembourg,LUX,Luxembourg,LU,,49.61166037910,6.13000280623,4.00000000000,0,Changed scale rank.,107260,76684,106219,9,8,2960316.00000000000,,Luxembourg,1,0,6.0
|
||||
6,30,0,Admin-0 capital,Palikir,,,0,Palikir,1.00000000000,,,0.00000000000,0,Federated States of Micronesia,FSM,Federated States of Micronesia,FSM,,FM,,6.91664369601,158.14997432400,4.00000000000,0,Changed scale rank.,4645,4645,0,4,4,2081986.00000000000,,Palikir,1,5,6.0
|
||||
6,30,0,Admin-0 capital,Majuro,,,0,Majuro,1.00000000000,,,0.00000000000,0,Marshall Islands,MHL,Marshall Islands,MHL,,MH,,7.10300431122,171.38000017600,4.00000000000,0,Changed scale rank.,25400,20500,0,7,7,2113779.00000000000,,Majuro,1,5,6.0
|
||||
6,30,0,Admin-0 capital,Funafuti,,,0,Funafuti,1.00000000000,,,0.00000000000,0,Tuvalu,TUV,Tuvalu,TUV,,TV,,-8.51665199904,179.21664709400,4.00000000000,0,Population from GeoNames. Changed scale rank.,4749,4749,0,4,4,2110394.00000000000,,Funafuti,0,5,6.0
|
||||
6,30,0,Admin-0 capital,Melekeok,,,0,Melekeok,1.00000000000,,,0.00000000000,0,Palau,PLW,Palau,PLW,,PW,,7.48739617298,134.62654846700,4.00000000000,0,Location adjusted. Changed scale rank.,7026,7026,0,5,5,1559804.00000000000,,Melekeok,1,5,6.0
|
||||
6,30,0,Admin-0 capital alt,Bir Lehlou,,,0,Bir Lehlou,0.00000000000,1,Claimed as inte,0.00000000000,0,Western Sahara,SAH,Western Sahara,SAH,,EH,,26.11916668600,-9.65252221825,4.00000000000,1,Added place.,500,200,0,2,1,-1.00000000000,,,2,0,6.0
|
||||
6,30,0,Admin-0 capital,Monaco,,,0,Monaco,1.00000000000,,,0.00000000000,0,Monaco,MCO,Monaco,MCO,,MC,,43.73964568790,7.40691317347,4.00000000000,0,Location adjusted. Changed scale rank.,36371,36371,102371,7,7,2993458.00000000000,,Monaco,1,0,5.1
|
||||
6,30,0,Admin-0 capital,Tarawa,,,0,Tarawa,1.00000000000,,,0.00000000000,0,Kiribati,KIR,Kiribati,KIR,,KI,,1.33818750562,173.01757082900,4.00000000000,0,Location adjusted. Changed scale rank.,28802,22534,0,7,7,2110079.00000000000,,Tarawa,1,5,6.0
|
||||
6,30,0,Admin-0 capital,Moroni,,,0,Moroni,1.00000000000,,,0.00000000000,0,Comoros,COM,Comoros,COM,,KM,,-11.70415769570,43.24024409870,4.00000000000,0,Changed scale rank.,128698,42872,0,9,7,921772.00000000000,,Moroni,1,5,6.0
|
||||
6,30,0,Admin-0 capital,Andorra,,,0,Andorra,1.00000000000,,,0.00000000000,0,Andorra,AND,Andorra,AND,,AD,,42.50000144350,1.51648596051,4.00000000000,0,Changed scale rank.,53998,22256,53371,8,7,3130067.00000000000,,Andorra,1,5,6.0
|
||||
4,50,8,Admin-0 capital,Port-of-Spain,,,0,Port-of-Spain,1.00000000000,,,0.00000000000,0,Trinidad and Tobago,TTO,Trinidad and Tobago,TTO,Port of Spain,TT,,10.65199708960,-61.51703088540,4.00000000000,0,Changed scale rank.,294934,49031,419082,10,7,3573890.00000000000,,Port-of-Spain,1,5,5.1
|
||||
4,50,0,Admin-0 capital,Kigali,,,0,Kigali,1.00000000000,,,0.00000000000,1,Rwanda,RWA,Rwanda,RWA,Kigali City,RW,,-1.95359006868,30.06053177770,4.00000000000,0,Changed scale rank.,860000,745261,1152904,11,11,202061.00000000000,Kigali,Kigali,1,0,5.1
|
||||
4,50,8,Admin-0 capital,Mbabane,,,0,Mbabane,1.00000000000,,Administrative,0.00000000000,0,Swaziland,SWZ,Swaziland,SWZ,Hhohho,SZ,,-26.31665077840,31.13333451210,4.00000000000,0,Changed scale rank.,90138,76218,89979,8,8,934985.00000000000,,Mbabane,1,0,5.6
|
||||
4,50,5,Admin-0 capital,Juba,,,0,Juba,0.00000000000,,,0.00000000000,0,South Sudan,SSD,South Sudan,SSD,Central Equatoria,SS,,4.82997519828,31.58002559280,20.00000000000,0,Changed country.,111975,111975,111975,9,9,373303.00000000000,,Juba,1,0,5.1
|
||||
4,50,8,Admin-0 capital alt,The Hague,,,0,The Hague,0.00000000000,1,"Official, legis",0.00000000000,0,Kingdom of the Netherlands,NLD,Netherlands,NLD,Zuid-Holland,NL,,52.08003684400,4.26996130231,0.00000000000,0,,1406000,501725,688599,12,11,2747373.00000000000,,The Hague,1,0,5.6
|
||||
4,50,8,Admin-0 capital,Ljubljana,,,0,Ljubljana,1.00000000000,,,0.00000000000,0,Slovenia,SVN,Slovenia,SVN,Osrednjeslovenska,SI,,46.05528830880,14.51496903350,4.00000000000,0,Changed scale rank.,314807,255115,256316,10,10,3196359.00000000000,,Ljubljana,1,0,5.6
|
||||
4,50,7,Admin-0 capital,Bratislava,,,0,Bratislava,1.00000000000,,,0.00000000000,0,Slovakia,SVK,Slovakia,SVK,Bratislavský,SK,,48.15001833000,17.11698075220,4.00000000000,0,Changed scale rank.,423737,373687,361489,10,10,3060972.00000000000,,Bratislava,1,0,5.1
|
||||
4,50,8,Admin-0 capital,Doha,,,0,Doha,1.00000000000,,,0.00000000000,0,Qatar,QAT,Qatar,QAT,Ad Dawhah,QA,,25.28655600890,51.53296789430,4.00000000000,0,Location adjusted. Changed scale rank.,1450000,731310,0,12,11,290030.00000000000,,Doha,1,5,5.6
|
||||
4,50,8,Admin-0 capital,Podgorica,,,0,Podgorica,1.00000000000,,,0.00000000000,0,Montenegro,MNE,Montenegro,MNE,Podgorica,ME,,42.46597251290,19.26630692410,4.00000000000,0,Location adjusted. Changed scale rank.,145850,136473,0,9,9,3193044.00000000000,,Podgorica,1,0,5.6
|
||||
4,50,6,Admin-0 capital alt,Sri Jawewardenepura Kotte,,,0,Sri Jawewardenepura Kotte,0.00000000000,1,Legislative cap,0.00000000000,0,Sri Lanka,LKA,Sri Lanka,LKA,Colombo,LK,,6.90000388481,79.94999304090,4.00000000000,1,Name changed.,115826,115826,2456292,9,9,1238992.00000000000,,Kotte,1,0,5.6
|
||||
4,50,5,Admin-0 capital alt,Baguio City,,,0,Baguio City,0.00000000000,1,,0.00000000000,0,Philippines,PHL,Philippines,PHL,Benguet,PH,,16.42999066060,120.56994258500,40.00000000000,0,Changed scale rank.,447824,272714,164877,10,10,1728930.00000000000,,Baguio City,1,0,5.6
|
||||
4,50,5,Admin-0 capital alt,Dodoma,,,0,Dodoma,0.00000000000,1,Offical capital,0.00000000000,0,United Republic of Tanzania,TZA,Tanzania,TZA,Dodoma,TZ,,-6.18330605177,35.75000362010,4.00000000000,0,Location adjusted.,218269,180541,0,10,9,160196.00000000000,,Dodoma,1,0,5.6
|
||||
4,50,7,Admin-0 capital,Bern,,,0,Bern,1.00000000000,,,0.00000000000,0,Switzerland,CHE,Switzerland,CHE,Bern,CH,,46.91668275870,7.46697546248,4.00000000000,0,Changed scale rank.,275329,121631,267814,10,9,2661552.00000000000,,Bern,1,0,5.6
|
||||
4,50,5,Admin-0 capital alt,Laayoune,,,0,Laayoune,0.00000000000,1,Claimed as capi,0.00000000000,0,Morocco,MAR,Morocco,MAR,Laâyoune - Boujdour - Sakia El Hamra,MA,,27.14998231910,-13.20000594220,0.00000000000,0,,188084,176365,176365,9,9,2462881.00000000000,,Laayoune,1,0,5.6
|
||||
4,50,8,Admin-0 capital,Pristina,,,0,Pristina,1.00000000000,,,0.00000000000,0,Kosovo,KOS,Kosovo,KOS,Pristina,-99,,42.66670961410,21.16598425160,4.00000000000,0,Changed scale rank.,465186,198214,261783,10,9,786714.00000000000,,Pristina,1,0,5.6
|
||||
4,50,8,Admin-0 capital,Roseau,,,0,Roseau,1.00000000000,,,0.00000000000,0,Dominica,DMA,Dominica,DMA,Saint George,DM,,15.30101564430,-61.38701298180,4.00000000000,0,Changed scale rank.,23336,16571,23336,7,6,3575635.00000000000,,Roseau,1,5,5.1
|
||||
4,50,8,Admin-0 capital,Djibouti,,,0,Djibouti,1.00000000000,,,0.00000000000,0,Djibouti,DJI,Djibouti,DJI,Djibouti,DJ,,11.59501446430,43.14800166710,4.00000000000,0,Changed scale rank.,923000,604013,335001,11,11,223817.00000000000,,Djibouti,1,0,5.6
|
||||
4,50,6,Admin-0 capital alt,Putrajaya,,,0,Putrajaya,0.00000000000,1,Administrative,0.00000000000,0,Malaysia,MYS,Malaysia,MYS,Selangor,MY,,2.91401979462,101.70194698000,0.00000000000,0,,67964,50000,956431,8,7,6697380.00000000000,,Putrajaya,1,5,5.6
|
||||
4,50,2,Admin-0 capital alt,Kyoto,,,0,Kyoto,0.00000000000,1,Official capita,0.00000000000,1,Japan,JPN,Japan,JPN,Kyoto,JP,,35.02999228820,135.74999792400,0.00000000000,0,,1805000,1459640,1827367,12,12,1857910.00000000000,Kyoto,Kyoto,1,0,5.1
|
||||
4,50,8,Admin-0 capital,Banjul,,,0,Banjul,1.00000000000,,,0.00000000000,0,"Gambia, The",GMB,The Gambia,GMB,Banjul,GM,,13.45387646030,-16.59170148920,4.00000000000,0,Location adjusted. Changed scale rank.,43094,34589,581300,7,7,2413876.00000000000,,Banjul,1,0,5.6
|
||||
4,50,8,Admin-0 capital,Skopje,,,0,Skopje,1.00000000000,,,0.00000000000,0,Macedonia,MKD,Macedonia,MKD,Centar,MK,,42.00000612290,21.43346146510,4.00000000000,0,Changed scale rank.,494087,474889,491890,10,10,785842.00000000000,,Skopje,1,5,5.6
|
||||
4,50,8,Admin-0 capital,Bridgetown,,,0,Bridgetown,1.00000000000,,,0.00000000000,0,Barbados,BRB,Barbados,BRB,Saint Michael,BB,,13.10200258280,-59.61652673510,4.00000000000,0,Changed scale rank.,191152,96578,191814,9,8,2075807.00000000000,,Bridgetown,1,5,5.6
|
||||
4,50,8,Admin-0 capital alt,Porto-Novo,,,0,Porto-Novo,0.00000000000,1,Official capita,0.00000000000,0,Benin,BEN,Benin,BEN,Ouémé,BJ,,6.48331097302,2.61662552757,0.00000000000,0,,300000,234168,806945,10,10,2392087.00000000000,,Porto-Novo,1,0,5.6
|
||||
4,50,8,Admin-0 capital,Bujumbura,,,0,Bujumbura,1.00000000000,,,0.00000000000,0,Burundi,BDI,Burundi,BDI,Bujumbura Mairie,BI,,-3.37608722037,29.36000606150,4.00000000000,0,Changed scale rank.,331700,331700,1208361,10,10,425378.00000000000,,Bujumbura,1,0,5.6
|
||||
4,50,0,Admin-0 capital,Kingstown,,,0,Kingstown,1.00000000000,,,0.00000000000,0,Saint Vincent and the Grenadines,VCT,Saint Vincent and the Grenadines,VCT,,VC,,13.14827882790,-61.21206242030,4.00000000000,0,Location adjusted. Changed scale rank.,49485,24518,0,7,7,4359981.00000000000,,Kingstown,1,5,5.1
|
||||
4,50,0,Admin-0 capital,Castries,,,0,Castries,1.00000000000,,,0.00000000000,0,Saint Lucia,LCA,Saint Lucia,LCA,,LC,,14.00197348930,-61.00000818040,4.00000000000,0,Changed scale rank.,37963,10634,0,7,6,3028258.00000000000,,Castries,1,5,5.6
|
||||
4,50,0,Admin-0 capital,Basseterre,,,0,Basseterre,1.00000000000,,,0.00000000000,0,Saint Kitts and Nevis,KNA,Saint Kitts and Nevis,KNA,,KN,,17.30203045550,-62.71700931970,4.00000000000,0,Changed scale rank.,21887,15500,21887,7,6,3575551.00000000000,,Basseterre,1,5,5.6
|
||||
4,50,0,Admin-0 capital,Port Louis,,,0,Port Louis,1.00000000000,,,0.00000000000,0,Mauritius,MUS,Mauritius,MUS,,MU,,-20.16663857140,57.49999385460,4.00000000000,0,Changed scale rank.,595491,148416,304613,11,9,934154.00000000000,,Port Louis,1,5,5.6
|
||||
4,50,0,Admin-0 capital,Saint George's,,,0,Saint George's,1.00000000000,,,0.00000000000,0,Grenada,GRD,Grenada,GRD,,GD,,12.05263340170,-61.74164322610,4.00000000000,0,Changed scale rank.,33734,27343,27343,7,7,3579925.00000000000,,Saint Georgee۪s,1,5,5.1
|
||||
4,50,0,Admin-0 capital,Manama,,,0,Manama,1.00000000000,,,0.00000000000,0,Bahrain,BHR,Bahrain,BHR,,BH,,26.23613629050,50.58305171590,4.00000000000,0,Changed scale rank.,563920,157474,563666,11,9,290340.00000000000,,Manama,1,5,5.6
|
||||
4,50,0,Admin-0 capital,Saint John's,,,0,Saint John's,1.00000000000,,,0.00000000000,0,Antigua and Barbuda,ATG,Antigua and Barbuda,ATG,,AG,,17.11803651830,-61.85003381510,4.00000000000,0,Changed scale rank.,35499,24226,0,7,7,3576022.00000000000,,Saint John's,1,5,5.1
|
||||
3,110,8,Admin-0 capital,Montevideo,,,0,Montevideo,1.00000000000,,,0.00000000000,1,Uruguay,URY,Uruguay,URY,Montevideo,UY,,-34.85804156620,-56.17105228840,0.00000000000,0,,1513000,5324,1276128,12,5,5038018.00000000000,Montevideo,Montevideo,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Lomé,,Lome,0,Lome,1.00000000000,,,0.00000000000,1,Togo,TGO,Togo,TGO,Maritime,TG,,6.13193707166,1.22275711936,0.00000000000,0,,1452000,749700,1256715,12,11,2365267.00000000000,Lomi,Lome,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Tunis,,,0,Tunis,1.00000000000,,,0.00000000000,0,Tunisia,TUN,Tunisia,TUN,Tunis,TN,,36.80277813620,10.17967809920,0.00000000000,0,,2412500,728453,1675117,12,11,2464470.00000000000,,Tunis,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Abu Dhabi,,,0,Abu Dhabi,1.00000000000,,,0.00000000000,0,United Arab Emirates,ARE,United Arab Emirates,ARE,Abu Dhabi,AE,,24.46668357240,54.36659338260,0.00000000000,0,,603492,560230,560230,11,11,292968.00000000000,,Abu Dhabi,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Ashgabat,,,0,Ashgabat,1.00000000000,,,0.00000000000,0,Turkmenistan,TKM,Turkmenistan,TKM,Ahal,TM,,37.94999493310,58.38329911180,0.00000000000,0,,727700,577982,556048,11,11,162183.00000000000,,Ashgabat,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Lusaka,,,0,Lusaka,1.00000000000,,,0.00000000000,1,Zambia,ZMB,Zambia,ZMB,Lusaka,ZM,,-15.41664426790,28.28332759470,0.00000000000,0,,1328000,1267440,1240558,12,12,909137.00000000000,Lusaka,Lusaka,1,0,4.0
|
||||
3,110,6,Admin-0 capital,Harare,,,0,Harare,1.00000000000,,,0.00000000000,1,Zimbabwe,ZWE,Zimbabwe,ZWE,Harare,ZW,,-17.81778969440,31.04470943070,0.00000000000,0,,1572000,1542813,1831877,12,12,890299.00000000000,Harare,Harare,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Dili,,,0,Dili,1.00000000000,,,0.00000000000,0,East Timor,TLS,East Timor,TLS,Dili,TL,,-8.55938840855,125.57945593200,0.00000000000,0,,234331,193563,55154,10,9,1645457.00000000000,,Dili,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Port Vila,,,0,Port Vila,1.00000000000,,,0.00000000000,0,Vanuatu,VUT,Vanuatu,VUT,Shefa,VU,,-17.73335040400,168.31664058400,0.00000000000,0,,44040,35901,7702,7,7,2135171.00000000000,,Port-Vila,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Tegucigalpa,,,0,Tegucigalpa,1.00000000000,,,0.00000000000,1,Honduras,HND,Honduras,HND,Francisco Morazán,HN,,14.10204490050,-87.21752933930,0.00000000000,0,,946000,850848,1014546,11,11,3600949.00000000000,Tegucigalpa,Tegucigalpa,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Georgetown,,,0,Georgetown,1.00000000000,,,0.00000000000,0,Guyana,GUY,Guyana,GUY,East Berbice-Corentyne,GY,,6.80197369275,-58.16702864750,0.00000000000,0,,264350,235017,264350,10,10,3378644.00000000000,,Georgetown1,1,5,4.0
|
||||
3,110,8,Admin-0 capital,Reykjavík,,,1,Reykjavik,1.00000000000,,,0.00000000000,0,Iceland,ISL,Iceland,ISL,Suðurnes,IS,,64.15002361970,-21.95001448720,0.00000000000,0,,166212,113906,160116,9,9,3413829.00000000000,,Reykjavik,1,0,3.7
|
||||
3,110,8,Admin-0 capital,Port-au-Prince,,,0,Port-au-Prince,1.00000000000,,,0.00000000000,1,Haiti,HTI,Haiti,HTI,Ouest,HT,,18.54102459610,-72.33603458830,0.00000000000,0,,1998000,1234742,2385397,12,12,3718426.00000000000,Port-au-Prince,Port-au-Prince,1,0,5.0
|
||||
3,110,5,Admin-0 capital,Kampala,,,0,Kampala,1.00000000000,,,0.00000000000,1,Uganda,UGA,Uganda,UGA,Kampala,UG,,0.31665895477,32.58332352570,0.00000000000,0,,1420000,1353189,2153702,12,12,232422.00000000000,Kampala,Kampala,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Paramaribo,,,0,Paramaribo,1.00000000000,,,0.00000000000,0,Suriname,SUR,Suriname,SUR,Paramaribo,SR,,5.83503012992,-55.16703088540,0.00000000000,0,,254169,223757,248161,10,10,3383330.00000000000,,Paramaribo,1,5,5.0
|
||||
3,110,6,Admin-0 capital,Niamey,,,0,Niamey,1.00000000000,,,0.00000000000,1,Niger,NER,Niger,NER,Niamey,NE,,13.51670595190,2.11665604514,0.00000000000,0,,915000,742791,715325,11,11,2440485.00000000000,Niamey,Niamey,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Dushanbe,,,0,Dushanbe,1.00000000000,,,0.00000000000,0,Tajikistan,TJK,Tajikistan,TJK,Tadzhikistan Territories,TJ,,38.56003521630,68.77387935270,0.00000000000,0,,1086244,679400,1081361,12,11,1221874.00000000000,,Dushanbe,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Asunción,,Asuncion,1,Asuncion,1.00000000000,,,0.00000000000,1,Paraguay,PRY,Paraguay,PRY,Asunción,PY,,-25.29640297570,-57.64150516930,0.00000000000,0,,1870000,11693,636771,12,6,1730025.00000000000,Asuncian,Asuncion,1,5,4.0
|
||||
3,110,8,Admin-0 capital,Managua,,,0,Managua,1.00000000000,,,0.00000000000,1,Nicaragua,NIC,Nicaragua,NIC,Managua,NI,,12.15301658010,-86.26849166030,0.00000000000,0,,920000,920000,1088194,11,11,3617763.00000000000,Managua,Managua,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Freetown,,,0,Freetown,1.00000000000,,,0.00000000000,1,Sierra Leone,SLE,Sierra Leone,SLE,Western,SL,,8.47001141249,-13.23421574040,0.00000000000,0,,827000,13768,1074640,11,6,2408770.00000000000,Freetown,Freetown,1,0,5.0
|
||||
3,110,2,Admin-0 capital,Islamabad,,,0,Islamabad,1.00000000000,,,0.00000000000,1,Pakistan,PAK,Pakistan,PAK,F.C.T.,PK,,33.69999595030,73.16663447970,0.00000000000,0,,780000,601600,893673,11,11,1176615.00000000000,Islamabad,Islamabad,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Kathmandu,,,0,Kathmandu,1.00000000000,,,0.00000000000,1,Nepal,NPL,Nepal,NPL,Bhaktapur,NP,,27.71669191390,85.31664221080,0.00000000000,0,,895000,895000,1099610,11,11,1283240.00000000000,Kathmandu,Kathmandu,1,0,5.0
|
||||
3,110,3,Admin-0 capital,Bloemfontein,,,0,Bloemfontein,1.00000000000,,Judicial capita,0.00000000000,0,South Africa,ZAF,South Africa,ZAF,Orange Free State,ZA,,-29.11999387740,26.22991288120,4.00000000000,0,Changed scale rank.,463064,456669,456513,10,10,1018725.00000000000,,Bloemfontein,1,0,5.0
|
||||
3,110,3,Admin-0 capital,Pretoria,,,0,Pretoria,1.00000000000,,Administrative,0.00000000000,1,South Africa,ZAF,South Africa,ZAF,Gauteng,ZA,,-25.70692055380,28.22942907580,0.00000000000,0,,1338000,1338000,1443084,12,12,964137.00000000000,Pretoria,Pretoria,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Port Moresby,,,0,Port Moresby,1.00000000000,,,0.00000000000,0,Papua New Guinea,PNG,Papua New Guinea,PNG,Central,PG,,-9.46470782587,147.19250362100,0.00000000000,0,,283733,251136,251304,10,10,2088122.00000000000,,Port Moresby,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Honiara,,,0,Honiara,1.00000000000,,,0.00000000000,0,Solomon Islands,SLB,Solomon Islands,SLB,Guadalcanal,SB,,-9.43799429509,159.94976573400,0.00000000000,0,,76328,56298,76328,8,8,2108502.00000000000,,Honiara,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Panama City,,Ciudad de Panam,0,Panama City,1.00000000000,,,0.00000000000,1,Panama,PAN,Panama,PAN,Panama,PA,,8.96801719048,-79.53303715180,0.00000000000,0,,1281000,408168,939725,12,10,3703443.00000000000,Ciudad de Panam,Panama City1,1,0,5.0
|
||||
3,110,5,Admin-0 capital,Rabat,,,0,Rabat,1.00000000000,,,0.00000000000,1,Morocco,MAR,Morocco,MAR,Rabat - Salé - Zemmour - Zaer,MA,,34.02529909160,-6.83613082013,0.00000000000,0,,1705000,1655753,2029349,12,12,2538475.00000000000,Rabat,Rabat,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Chișinău,,,0,Chisinau,1.00000000000,,,0.00000000000,0,Moldova,MDA,Moldova,MDA,Chisinau,MD,,47.00502361970,28.85771113970,0.00000000000,0,,688134,635994,664472,11,11,618426.00000000000,,Chisinau,1,5,5.0
|
||||
3,110,6,Admin-0 capital,Maputo,,,0,Maputo,1.00000000000,,,0.00000000000,1,Mozambique,MOZ,Mozambique,MOZ,Maputo,MZ,,-25.95527748740,32.58916296260,0.00000000000,0,,1446000,1191613,1365454,12,12,1040652.00000000000,Maputo,Maputo,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Mogadishu,,Muqdisho,0,Mogadishu,1.00000000000,,,0.00000000000,1,Somalia,SOM,Somalia,SOM,Banaadir,SO,,2.06668133433,45.36667761110,0.00000000000,0,,1100000,875388,849392,12,11,53654.00000000000,Muqdisho,Mogadishu,1,5,4.0
|
||||
3,110,8,Admin-0 capital,Muscat,,,0,Muscat,1.00000000000,,,0.00000000000,0,Oman,OMN,Oman,OMN,Muscat,OM,,23.61332480770,58.59331213260,0.00000000000,0,,734697,586861,586861,11,11,287286.00000000000,,Muscat,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Colombo,,,0,Colombo,1.00000000000,,"De facto, admin",0.00000000000,0,Sri Lanka,LKA,Sri Lanka,LKA,Colombo,LK,,6.93196575818,79.85775060930,0.00000000000,0,,217000,217000,2490974,10,10,3465927.00000000000,,Colombo,1,5,5.0
|
||||
3,110,7,Admin-0 capital,Ulaanbaatar,,,0,Ulaanbaatar,1.00000000000,,,0.00000000000,1,Mongolia,MNG,Mongolia,MNG,Ulaanbaatar,MN,,47.91667339990,106.91661576200,0.00000000000,0,,885000,769612,765359,11,11,2028462.00000000000,Ulaanbaatar,Ulaanbaatar,1,0,4.0
|
||||
3,110,6,Admin-0 capital,Windhoek,,,0,Windhoek,1.00000000000,,,0.00000000000,0,Namibia,NAM,Namibia,NAM,Khomas,NA,,-22.57000608440,17.08354610050,0.00000000000,0,,268132,262796,262796,10,10,3352136.00000000000,,Windhoek,1,0,5.0
|
||||
3,110,2,Admin-0 capital,Abuja,,,0,Abuja,1.00000000000,,Official and ad,0.00000000000,1,Nigeria,NGA,Nigeria,NGA,Federal Capital Territory,NG,,9.08333314914,7.53332800155,4.00000000000,0,Changed scale rank.,1576000,162135,0,12,9,2322794.00000000000,Abuja,Abuja,1,5,4.0
|
||||
3,110,8,Admin-0 capital,Bissau,,,0,Bissau,1.00000000000,,,0.00000000000,0,Guinea Bissau,GNB,Guinea Bissau,GNB,Bissau,GW,,11.86502382300,-15.59836084130,0.00000000000,0,,403339,388028,403339,10,10,2374775.00000000000,,Bissau,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Amman,,,0,Amman,1.00000000000,,,0.00000000000,1,Jordan,JOR,Jordan,JOR,Amman,JO,,31.95002524720,35.93329992550,0.00000000000,0,,1060000,1060000,2633729,12,12,250441.00000000000,Amman,Amman,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Vilnius,,,0,Vilnius,1.00000000000,,,0.00000000000,0,Lithuania,LTU,Lithuania,LTU,Vilniaus,LT,,54.68336631180,25.31663529330,0.00000000000,0,,542366,507029,494356,11,11,593116.00000000000,,Vilnius,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Riga,,,0,Riga,1.00000000000,,,0.00000000000,0,Latvia,LVA,Latvia,LVA,Riga,LV,,56.95002382320,24.09996537140,0.00000000000,0,,742572,705033,0,11,11,456172.00000000000,,Riga,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Bishkek,,,0,Bishkek,1.00000000000,,,0.00000000000,1,Kyrgyzstan,KGZ,Kyrgyzstan,KGZ,Bishkek,KG,,42.87307944650,74.58520422250,0.00000000000,0,,837000,804212,781714,11,11,1528675.00000000000,Bishkek,Bishkek,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Maseru,,,0,Maseru,1.00000000000,,,0.00000000000,0,Lesotho,LSO,Lesotho,LSO,Maseru,LS,,-29.31667437870,27.48327307000,0.00000000000,0,,361324,118355,356225,10,9,932505.00000000000,,Maseru,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Antananarivo,,,0,Antananarivo,1.00000000000,,,0.00000000000,1,Madagascar,MDG,Madagascar,MDG,Antananarivo,MG,,-18.91663735060,47.51662390010,0.00000000000,0,,1697000,1391433,1844658,12,12,1070940.00000000000,Antananarivo,Antananarivo,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Quito,,,0,Quito,1.00000000000,,,0.00000000000,1,Ecuador,ECU,Ecuador,ECU,Pichincha,EC,,-0.21498818065,-78.50005110850,0.00000000000,0,,1701000,1399814,1435528,12,12,3652462.00000000000,Quito,Quito,1,0,4.0
|
||||
3,110,8,Admin-0 capital,San José,,San Jose,1,San Jose,1.00000000000,,,0.00000000000,1,Costa Rica,CRI,Costa Rica,CRI,San José,CR,,9.93501242974,-84.08405135270,0.00000000000,0,,1284000,1724,1434681,12,3,3669623.00000000000,San Josi,San Jose1,1,5,5.0
|
||||
3,110,8,Admin-0 capital,San Salvador,,,0,San Salvador,1.00000000000,,,0.00000000000,1,El Salvador,SLV,El Salvador,SLV,San Salvador,SV,,13.71000164690,-89.20304122080,0.00000000000,0,,1433000,2807,2139587,12,4,1690681.00000000000,San Salvador,San Salvador,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Kingston,,,0,Kingston,1.00000000000,,,0.00000000000,0,Jamaica,JAM,Jamaica,JAM,Kingston,JM,,17.97707662380,-76.76743371370,4.00000000000,0,Location adjusted.,937700,664973,18171,11,11,3489854.00000000000,,Kingston1,1,5,5.0
|
||||
3,110,7,Admin-0 capital,Ndjamena,,N'Djamnna,0,Ndjamena,1.00000000000,,,0.00000000000,1,Chad,TCD,Chad,TCD,Hadjer-Lamis,TD,,12.11309653620,15.04914831410,0.00000000000,0,,989000,681387,686347,11,11,2427123.00000000000,N'Djam-na,Ndjamena,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Malabo,,,0,Malabo,1.00000000000,,,0.00000000000,0,Equatorial Guinea,GNQ,Equatorial Guinea,GNQ,Bioko Norte,GQ,,3.75001527803,8.78327754582,4.00000000000,0,Location adjusted.,155963,155963,0,9,9,2309527.00000000000,,Malabo,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Asmara,,,0,Asmara,1.00000000000,,,0.00000000000,0,Eritrea,ERI,Eritrea,ERI,Anseba,ER,,15.33333925270,38.93332352580,0.00000000000,0,,620802,563930,587094,11,11,343300.00000000000,,Asmara,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Zagreb,,,0,Zagreb,1.00000000000,,,0.00000000000,0,Croatia,HRV,Croatia,HRV,Grad Zagreb,HR,,45.80000673330,15.99999466820,0.00000000000,0,,722526,698966,690638,11,11,3186886.00000000000,,Zagreb,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Tallinn,,,0,Tallinn,1.00000000000,,,0.00000000000,0,Estonia,EST,Estonia,EST,Harju,EE,,59.43387737950,24.72804072950,0.00000000000,0,,394024,340027,317949,10,10,588409.00000000000,,Tallinn,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Lilongwe,,,0,Lilongwe,1.00000000000,,,0.00000000000,0,Malawi,MWI,Malawi,MWI,Lilongwe,MW,,-13.98329506550,33.78330196000,0.00000000000,0,,646750,646750,1061388,11,11,927967.00000000000,,Lilongwe,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Guatemala,,Ciudad de Guatemala (Guatemala City),0,Guatemala,1.00000000000,,,0.00000000000,1,Guatemala,GTM,Guatemala,GTM,Guatemala,GT,,14.62113466280,-90.52696557790,0.00000000000,0,,1024000,994938,2391150,12,11,3598132.00000000000,Ciudad de Guatemala (Guatemala City),Guatemala,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Libreville,,,0,Libreville,1.00000000000,,,0.00000000000,0,Gabon,GAB,Gabon,GAB,Estuaire,GA,,0.38538860972,9.45796504582,0.00000000000,0,,578156,483355,483522,11,10,2399697.00000000000,,Libreville,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Suva,,,0,Suva,1.00000000000,,,0.00000000000,0,Fiji,FJI,Fiji,FJI,Central,FJ,,-18.13301593140,178.44170731500,4.00000000000,0,Location adjusted.,175399,88271,0,9,8,2198148.00000000000,,Suva,1,0,5.0
|
||||
3,110,3,Admin-0 capital alt,Valparaíso,,Valparaiso,1,Valparaiso,0.00000000000,1,Legislative cap,0.00000000000,1,Chile,CHL,Chile,CHL,Valparaíso,CL,,-33.04776446660,-71.62101363290,4.00000000000,0,Changed scale rank.,854000,15938,130815,11,6,3445575.00000000000,Valpara so,Valparaiso2,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Nouakchott,,,0,Nouakchott,1.00000000000,,,0.00000000000,0,Mauritania,MRT,Mauritania,MRT,Nouakchott,MR,,18.08642702120,-15.97534041490,0.00000000000,0,,742144,661400,742144,11,11,2377450.00000000000,,Nouakchott,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Bamako,,,0,Bamako,1.00000000000,,,0.00000000000,1,Mali,MLI,Mali,MLI,Bamako,ML,,12.65001466770,-8.00003910464,0.00000000000,0,,1494000,1297281,1301407,12,12,2460596.00000000000,Bamako,Bamako,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Beirut,,Bayrut,0,Beirut,1.00000000000,,,0.00000000000,1,Lebanon,LBN,Lebanon,LBN,Beirut,LB,,33.87197511700,35.50970821000,0.00000000000,0,,1846000,1712125,1661980,12,12,276781.00000000000,Bayrut,Beirut,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Tbilisi,,T'Bilisi,0,Tbilisi,1.00000000000,,,0.00000000000,1,Georgia,GEO,Georgia,GEO,Tbilisi,GE,,41.72500998850,44.79079544960,0.00000000000,0,,1100000,1005257,977179,12,12,611717.00000000000,Tbilisi,Tbilisi,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Astana,,,0,Astana,1.00000000000,,,0.00000000000,0,Kazakhstan,KAZ,Kazakhstan,KAZ,Aqmola,KZ,,51.18112530430,71.42777420950,0.00000000000,0,,345604,325021,317445,10,10,1526273.00000000000,,Astana,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Vientiane,,,0,Vientiane,1.00000000000,,,0.00000000000,0,Laos,LAO,Laos,LAO,Vientiane [prefecture],LA,,17.96669272760,102.59998002000,0.00000000000,0,,754000,570348,469811,11,11,1651944.00000000000,,Vientiane,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Brazzaville,,,0,Brazzaville,1.00000000000,,,0.00000000000,1,Congo (Brazzaville),COG,Congo (Brazzaville),COG,Pool,CG,,-4.25918577181,15.28468949250,0.00000000000,0,,1355000,1163890,1174778,12,12,2260535.00000000000,Brazzaville,Brazzaville,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Conakry,,,0,Conakry,1.00000000000,,,0.00000000000,1,Guinea,GIN,Guinea,GIN,Conakry,GN,,9.53152284641,-13.68023502750,0.00000000000,0,,1494000,1494000,1498020,12,12,2422465.00000000000,Conakry,Conakry,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Yamoussoukro,,,0,Yamoussoukro,1.00000000000,1,Official capita,0.00000000000,0,Ivory Coast,CIV,Ivory Coast,CIV,Lacs,CI,,6.81838096000,-5.27550256491,4.00000000000,0,Changed scale rank.,206499,194530,206499,10,9,2279755.00000000000,,Yamoussoukro,1,0,5.0
|
||||
3,110,2,Admin-0 capital,Ottawa,,Ottawa-Gatineau,0,Ottawa,1.00000000000,,,0.00000000000,1,Canada,CAN,Canada,CAN,Ontario,CA,,45.41669679670,-75.70001530120,0.00000000000,0,,1145000,812129,872781,12,11,6094817.00000000000,Ottawa-Gatineau,Ottawa,1,5,3.0
|
||||
3,110,8,Admin-0 capital,Belgrade,Beograd,,0,Belgrade,1.00000000000,,,0.00000000000,1,Republic of Serbia,SRB,Serbia,SRB,Grad Beograd,RS,,44.81864544580,20.46799068060,0.00000000000,0,,1099000,1099000,1271541,12,12,792680.00000000000,Beograd,Belgrade,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Bandar Seri Begawan,,,0,Bandar Seri Begawan,1.00000000000,,,0.00000000000,0,Brunei,BRN,Brunei,BRN,Brunei and Muara,BN,,4.88333111462,114.93328405700,0.00000000000,0,,296500,140000,222513,10,9,1820906.00000000000,,Bandar Seri Begawan,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Sucre,,,0,Sucre,1.00000000000,,Official (const,0.00000000000,0,Bolivia,BOL,Bolivia,BOL,Chuquisaca,BO,,-19.04097084670,-65.25951562670,0.00000000000,0,,224838,221736,221736,10,10,3903987.00000000000,,Sucre,1,0,4.7
|
||||
3,110,8,Admin-0 capital,Belmopan,,,0,Belmopan,1.00000000000,,,0.00000000000,0,Belize,BLZ,Belize,BLZ,Cayo,BZ,,17.25203350720,-88.76707299980,0.00000000000,0,,15220,13381,15220,6,6,3582672.00000000000,,Belmopan,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Bangui,,,0,Bangui,1.00000000000,,,0.00000000000,0,Central African Republic,CAF,Central African Republic,CAF,Bangui,CF,,4.36664430635,18.55828812530,0.00000000000,0,,831925,622771,782274,11,11,2389853.00000000000,,Bangui,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Yaounde,,Yaounde,0,Yaounde,1.00000000000,,,0.00000000000,1,Cameroon,CMR,Cameroon,CMR,Centre,CM,,3.86670066214,11.51665075550,0.00000000000,0,,1611000,1060587,1060747,12,12,2220957.00000000000,Yaound,Yaounde,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Tirana,,,0,Tirana,1.00000000000,,,0.00000000000,0,Albania,ALB,Albania,ALB,Durrës,AL,,41.32754070950,19.81888301460,0.00000000000,0,,895350,421286,517792,11,10,3183875.00000000000,,Tirana,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Yerevan,,,0,Yerevan,1.00000000000,,,0.00000000000,1,Armenia,ARM,Armenia,ARM,Erevan,AM,,40.18115073550,44.51355139040,0.00000000000,0,,1102000,1093485,1154748,12,12,616052.00000000000,Yerevan,Yerevan,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Baku,,,0,Baku,1.00000000000,,,0.00000000000,1,Azerbaijan,AZE,Azerbaijan,AZE,Baki,AZ,,40.39527203270,49.86221716190,0.00000000000,0,,2122300,1892000,1518801,12,12,587084.00000000000,Baku,Baku,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Phnom Penh,,Phnum Penh,0,Phnom Penh,1.00000000000,,,0.00000000000,1,Cambodia,KHM,Cambodia,KHM,Phnom Penh,KH,,11.55003012990,104.91663448000,0.00000000000,0,,1466000,1466000,1604086,12,12,1821306.00000000000,Phnum Penh,Phnom Penh,1,5,5.0
|
||||
3,110,6,Admin-0 capital,La Paz,,,0,La Paz,1.00000000000,,Administrative,0.00000000000,1,Bolivia,BOL,Bolivia,BOL,La Paz,BO,,-16.49797361370,-68.14998519050,0.00000000000,0,,1590000,812799,4400,12,11,3911925.00000000000,La Paz,La Paz3,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Cotonou,,,0,Cotonou,1.00000000000,,"De facto, admin",0.00000000000,1,Benin,BEN,Benin,BEN,Ouémé,BJ,,6.40000856417,2.51999059918,0.00000000000,0,,762000,690584,1060640,11,11,2394819.00000000000,Cotonou,Cotonou,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Sofia,,,0,Sofia,1.00000000000,,,0.00000000000,1,Bulgaria,BGR,Bulgaria,BGR,Grad Sofiya,BG,,42.68334942530,23.31665401070,0.00000000000,0,,1185000,874827,871735,12,11,727011.00000000000,Sofia,Sofia,1,0,5.0
|
||||
3,110,6,Admin-0 capital,Minsk,,,0,Minsk,1.00000000000,,,0.00000000000,1,Belarus,BLR,Belarus,BLR,Minsk,BY,,53.89997743640,27.56662715530,0.00000000000,0,,1805000,1577138,1557919,12,12,625144.00000000000,Minsk,Minsk,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Thimphu,,,0,Thimphu,1.00000000000,,,0.00000000000,0,Bhutan,BTN,Bhutan,BTN,Thimphu,BT,,27.47298585920,89.63901403700,4.00000000000,0,Location adjusted.,98676,79185,0,8,8,1252416.00000000000,,Thimphu,1,0,5.0
|
||||
3,110,7,Admin-0 capital,Gaborone,,,0,Gaborone,1.00000000000,,,0.00000000000,0,Botswana,BWA,Botswana,BWA,South-East,BW,,-24.64631345740,25.91194779330,0.00000000000,0,,208411,159243,158896,10,9,933773.00000000000,,Gaborone,1,0,5.0
|
||||
3,110,3,Admin-0 capital,Canberra,,,0,Canberra,1.00000000000,,,0.00000000000,0,Australia,AUS,Australia,AUS,Australian Capital Territory,AU,,-35.28302854540,149.12902624400,4.00000000000,0,Location adjusted.,327700,234032,0,10,10,2172517.00000000000,,Canberra,1,0,4.0
|
||||
3,110,8,Admin-0 capital,Ouagadougou,,,0,Ouagadougou,1.00000000000,,,0.00000000000,1,Burkina Faso,BFA,Burkina Faso,BFA,Kadiogo,BF,,12.37031597790,-1.52472375630,0.00000000000,0,,1149000,835457,713874,12,11,2357048.00000000000,Ouagadougou,Ouagadougou,1,0,5.0
|
||||
3,110,8,Admin-0 capital,Sarajevo,,,0,Sarajevo,1.00000000000,,,0.00000000000,0,Bosnia and Herzegovina,BIH,Bosnia and Herzegovina,BIH,Sarajevo,BA,,43.85002239900,18.38300166700,0.00000000000,0,,696731,628902,627065,11,11,3191281.00000000000,,Sarajevo,1,5,5.0
|
||||
3,110,5,Admin-0 capital,Naypyidaw,,Nay Pyi Taw,0,Naypyidaw,1.00000000000,,,0.00000000000,1,Myanmar,MMR,Myanmar,MMR,Mandalay,MM,,19.76655702610,96.11861852920,4.00000000000,0,Location adjusted.,930000,194824,0,11,9,6611854.00000000000,Nay Pyi Taw,Naypyidaw,1,0,5.0
|
||||
3,110,0,Admin-0 capital,Nukualofa,,,0,Nukualofa,1.00000000000,,,0.00000000000,0,Tonga,TON,Tonga,TON,,TO,,-21.13851235670,-175.22056447800,4.00000000000,0,Location adjusted.,42620,23658,42620,7,7,4032402.00000000000,,Nukualofa,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Hargeysa,,,0,Hargeysa,1.00000000000,,,0.00000000000,0,Somaliland,SOL,Somaliland,SOL,,-99,,9.56002239882,44.06531001670,4.00000000000,0,Changed scale rank.,477876,247018,247018,10,10,57289.00000000000,,Hargeysa,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Victoria,,,0,Victoria,1.00000000000,,,0.00000000000,0,Seychelles,SYC,Seychelles,SYC,,SC,,-4.61663165397,55.44998978560,0.00000000000,0,,33576,22881,33737,7,7,241131.00000000000,,Victoria4,1,5,5.0
|
||||
3,110,0,Admin-0 capital,São Tomé,,,1,Sao Tome,1.00000000000,,,0.00000000000,0,Sao Tome and Principe,STP,Sao Tome and Principe,STP,,ST,,0.33340211883,6.73332515323,0.00000000000,0,,88219,56166,88219,8,8,3388092.00000000000,,Sao Tome,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Apia,,,0,Apia,1.00000000000,,,0.00000000000,0,Samoa,WSM,Samoa,WSM,,WS,,-13.84154504240,-171.73864160900,4.00000000000,0,Location adjusted.,61916,37708,0,8,7,3689793.00000000000,,Apia,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Valletta,,,0,Valletta,1.00000000000,,,0.00000000000,0,Malta,MLT,Malta,MLT,,MT,,35.89973248190,14.51471065130,0.00000000000,0,,368250,6966,336174,10,5,2562305.00000000000,,Valletta,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Malé,,,1,Male,1.00000000000,,,0.00000000000,0,Maldives,MDV,Maldives,MDV,,MV,,4.16670818981,73.49994746800,0.00000000000,0,,112927,103693,0,9,9,3174186.00000000000,,Male,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Jerusalem,,,0,Jerusalem,1.00000000000,,De facto capita,0.00000000000,0,Israel,IS1,Israel,ISR,Jerusalem,IL,,31.77840781560,35.20662593460,0.00000000000,0,,1029300,801000,1072567,12,11,281184.00000000000,,Jerusalem,1,0,3.7
|
||||
3,110,0,Admin-0 capital,Praia,,,0,Praia,1.00000000000,,,0.00000000000,0,Cape Verde,CPV,Cape Verde,CPV,,CV,,14.91669801730,-23.51668888500,0.00000000000,0,,113364,88859,89205,9,8,3374333.00000000000,,Praia,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Nassau,,,0,Nassau,1.00000000000,,,0.00000000000,0,"Bahamas, The",BHS,The Bahamas,BHS,,BS,,25.08339011540,-77.35004378430,0.00000000000,0,,227940,160966,0,10,9,3571824.00000000000,,Nassau,1,5,5.0
|
||||
3,110,0,Admin-0 capital,Nicosia,,,0,Nicosia,1.00000000000,,Capital of both,0.00000000000,0,Cyprus,CYP,Cyprus,CYP,,CY,,35.16667645170,33.36663488640,0.00000000000,0,,224300,200452,222985,10,10,146268.00000000000,,Nicosia,1,5,5.0
|
||||
3,110,8,Admin-0 capital,Wellington,,,0,Wellington,1.00000000000,,,0.00000000000,0,New Zealand,NZL,New Zealand,NZL,Manawatu-Wanganui,NZ,Wellington metropolitan area,-41.29998785369,174.78326585928,0.00000000000,0,,393400,393400,0,10,9,2144168.00000000000,,Wellington,1,0,4.0
|
||||
2,200,5,Admin-0 capital,Hanoi,,H,0,Hanoi,1.00000000000,,,0.00000000000,1,Vietnam,VNM,Vietnam,VNM,Thái Nguyên,VN,,21.03332724910,105.85001420000,5.00000000000,0,Changed scale rank.,4378000,1431270,5466347,12,12,1581130.00000000000,Hh Noi,Hanoi,1,0,4.0
|
||||
2,200,5,Admin-0 capital,Ankara,,,0,Ankara,1.00000000000,,,0.00000000000,1,Turkey,TUR,Turkey,TUR,Ankara,TR,,39.92723858550,32.86439164100,5.00000000000,0,Changed scale rank.,3716000,3307379,3267576,12,12,323786.00000000000,Ankara,Ankara,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Budapest,,,0,Budapest,1.00000000000,,,1.00000000000,1,Hungary,HUN,Hungary,HUN,Budapest,HU,,47.50000632640,19.08332067740,4.00000000000,0,Changed scale rank.,1679000,1679000,1718895,12,12,3054643.00000000000,Budapest,Budapest,1,0,4.7
|
||||
2,200,6,Admin-0 capital,Sanaa,,Sana'a',0,Sanaa,1.00000000000,,,0.00000000000,1,Yemen,YEM,Yemen,YEM,Amanat Al Asimah,YE,,15.35473329570,44.20659338260,5.00000000000,0,Changed scale rank.,2008000,1835853,1742507,12,12,71137.00000000000,Sana'a',Sanaa,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Bucharest,Bucuresti,,0,Bucharest,1.00000000000,,,1.00000000000,1,Romania,ROU,Romania,ROU,Bucharest,RO,,44.43337180490,26.09994665400,4.00000000000,0,Changed scale rank.,1942000,1742194,1636574,12,12,683506.00000000000,Bucuresti,Bucharest,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Damascus,,Dimashq,0,Damascus,1.00000000000,,,0.00000000000,1,Syria,SYR,Syria,SYR,Damascus,SY,,33.50003399560,36.29999588900,5.00000000000,0,Changed scale rank.,2466000,2466000,3344577,12,12,170654.00000000000,Dimashq,Damascus,1,0,4.7
|
||||
2,200,6,Admin-0 capital,Lisbon,Lisboa,,0,Lisbon,1.00000000000,,,1.00000000000,1,Portugal,PRT,Portugal,PRT,Lisboa,PT,,38.72272287790,-9.14486630549,4.00000000000,0,Location adjusted. Changed scale rank.,2812000,517802,1795582,12,11,2267057.00000000000,Lisboa,Lisbon,1,0,4.0
|
||||
2,200,5,Admin-0 capital,Khartoum,,Al-Khartum,0,Khartoum,1.00000000000,,,0.00000000000,1,Sudan,SDN,Sudan,SDN,Khartoum,SD,,15.58807822570,32.53417923860,5.00000000000,0,Changed scale rank.,4754000,1974647,2325931,12,12,379252.00000000000,Al-Khartum,Khartoum,1,0,4.0
|
||||
2,200,7,Admin-0 capital,Oslo,,,0,Oslo,1.00000000000,,,1.00000000000,1,Kingdom of Norway,NOR,Norway,NOR,Oslo,NO,,59.91669028640,10.74997920600,4.00000000000,0,Changed scale rank.,835000,580000,701804,11,11,3143244.00000000000,Oslo,Oslo,1,0,4.0
|
||||
2,200,5,Admin-0 capital,Warsaw,Warszawa,,0,Warsaw,1.00000000000,,,1.00000000000,1,Poland,POL,Poland,POL,Masovian,PL,,52.25000062980,20.99999955110,4.00000000000,0,Changed scale rank.,1707000,1702139,2012431,12,12,756135.00000000000,Warszawa,Warsaw,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Pyongyang,,P'yongyang,0,Pyongyang,1.00000000000,,,0.00000000000,1,"Korea, North",PRK,North Korea,PRK,P'yongyang,KP,,39.01943869940,125.75469071400,5.00000000000,0,Changed scale rank.,3300000,2498797,2483216,12,12,1871859.00000000000,P'yongyang,Pyongyang,1,0,4.7
|
||||
2,200,5,Admin-0 capital,Dar es Salaam,,,0,Dar es Salaam,1.00000000000,,De facto capita,0.00000000000,1,United Republic of Tanzania,TZA,Tanzania,TZA,Dar-Es-Salaam,TZ,,-6.80001259474,39.26834183630,5.00000000000,0,Changed scale rank.,2930000,2698652,2757835,12,12,160263.00000000000,Dar es Salaam,Dar es Salaam,1,0,4.0
|
||||
2,200,8,Admin-0 capital,Dublin,,,0,Dublin,1.00000000000,,,1.00000000000,1,Ireland,IRL,Ireland,IRL,Dublin,IE,,53.33306113600,-6.24890568178,0.00000000000,0,,1059000,968976,22478,12,11,2964574.00000000000,Dublin,Dublin2,1,0,4.0
|
||||
2,200,8,Admin-0 capital,Monrovia,,,0,Monrovia,1.00000000000,,,0.00000000000,1,Liberia,LBR,Liberia,LBR,Montserrado,LR,,6.31055665987,-10.80475162910,0.00000000000,0,,1041000,785662,806416,12,11,2274895.00000000000,Monrovia,Monrovia,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Kuala Lumpur,,,0,Kuala Lumpur,1.00000000000,,Official and le,1.00000000000,1,Malaysia,MYS,Malaysia,MYS,Selangor,MY,,3.16666587210,101.69998327500,0.00000000000,0,,1448000,1448000,2667990,12,12,1735161.00000000000,Kuala Lumpur,Kuala Lumpur,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Havana,,La Habana,0,Havana,1.00000000000,,,0.00000000000,1,Cuba,CUB,Cuba,CUB,Ciudad de la Habana,CU,,23.13195884090,-82.36418217130,5.00000000000,0,Changed scale rank.,2174000,1990917,1930305,12,12,3553478.00000000000,La Habana,Havana,1,0,4.0
|
||||
2,200,7,Admin-0 capital,Prague,Praha,,0,Prague,1.00000000000,,,1.00000000000,1,Czech Republic,CZE,Czech Republic,CZE,Prague,CZ,,50.08333701490,14.46597977570,4.00000000000,0,Changed scale rank.,1162000,2087,1088042,12,4,4548393.00000000000,Praha,Prague,1,0,4.7
|
||||
2,200,8,Admin-0 capital,Kuwait,,Al Kuwayt|Kuwait City,0,Kuwait,1.00000000000,,,0.00000000000,1,Kuwait,KWT,Kuwait,KWT,Al Kuwayt,KW,,29.36971763000,47.97830114620,5.00000000000,0,Changed scale rank.,2063000,60064,1682968,12,8,285787.00000000000,Al Kuwayt (Kuwait City),Kuwait,1,5,4.0
|
||||
2,200,8,Admin-0 capital,Santo Domingo,,,0,Santo Domingo,1.00000000000,,,0.00000000000,1,Dominican Republic,DOM,Dominican Republic,DOM,Distrito Nacional,DO,,18.47007285460,-69.90008508470,5.00000000000,0,Changed scale rank.,2154000,2873,3322037,12,4,3668373.00000000000,Santo Domingo,Santo Domingo,1,5,4.0
|
||||
2,200,6,Admin-0 capital,Accra,,,0,Accra,1.00000000000,,,0.00000000000,1,Ghana,GHA,Ghana,GHA,Greater Accra,GH,,5.55003460583,-0.21671574035,5.00000000000,0,Changed scale rank.,2121000,1963264,2334371,12,12,2306104.00000000000,Accra,Accra,1,0,4.0
|
||||
2,200,7,Admin-0 capital,Tripoli,,,0,Tripoli,1.00000000000,,,0.00000000000,1,Libya,LBY,Libya,LBY,Tajura' wa an Nawahi al Arba,LY,,32.89250001940,13.18001175810,5.00000000000,0,Changed scale rank.,2189000,229398,1149981,12,10,-1.00000000000,Tarabulus,Tripoli1,1,0,4.0
|
||||
2,200,8,Admin-0 capital alt,Tel Aviv-Yafo,,Tel Aviv-Jaffa,0,Tel Aviv-Yafo,0.00000000000,1,While Jerulsale,0.00000000000,1,Israel,IS1,Israel,ISR,Tel Aviv,IL,,32.07999147440,34.77001175820,4.00000000000,0,Changed scale rank.,3112000,378358,2306851,12,10,293394.00000000000,Tel Aviv-Yafo,Tel Aviv-Yafo,1,0,4.0
|
||||
2,200,7,Admin-0 capital,Helsinki,,,0,Helsinki,1.00000000000,,,1.00000000000,1,Finland,FIN,Finland,FIN,Southern Finland,FI,,60.17556337400,24.93412634150,4.00000000000,0,Changed scale rank.,1115000,558457,762958,12,11,658225.00000000000,Helsinki,Helsinki,1,0,4.0
|
||||
2,200,8,Admin-0 capital,København,Copenhagen,,1,Kobenhavn,1.00000000000,,,1.00000000000,1,Denmark,DNK,Denmark,DNK,Hovedstaden,DK,,55.67856419040,12.56348574730,0.00000000000,0,,1085000,1085000,1038288,12,12,2618425.00000000000,K,Copenhagen,1,0,4.0
|
||||
2,200,8,Admin-0 capital,Abidjan,,,0,Abidjan,1.00000000000,,"De facto, admin",0.00000000000,1,Ivory Coast,CIV,Ivory Coast,CIV,Lagunes,CI,,5.31999696749,-4.04004825989,5.00000000000,0,Changed scale rank.,3802000,3190395,3181637,12,12,2293538.00000000000,Abidjan,Abidjan,1,0,4.0
|
||||
2,200,1,Admin-0 capital,Brasília,,Brasilia,0,Brasilia,1.00000000000,,,0.00000000000,1,Brazil,BRA,Brazil,BRA,Distrito Federal,BR,,-15.78334023150,-47.91605228840,5.00000000000,0,Changed scale rank.,3716996,2562963,1772679,12,12,3469058.00000000000,Brasglia,Brasilia,1,0,3.7
|
||||
2,200,8,Admin-0 capital,Brussels,,Bruxelles-Brussel,0,Brussels,1.00000000000,,,1.00000000000,1,Belgium,BEL,Belgium,BEL,Brussels,BE,,50.83331707670,4.33331660830,0.00000000000,0,,1743000,1019022,1490164,12,12,2800866.00000000000,Bruxelles-Brussel,Brussels,1,5,4.7
|
||||
2,200,2,Admin-0 capital,Dhaka,,,0,Dhaka,1.00000000000,,,0.00000000000,1,Bangladesh,BGD,Bangladesh,BGD,Dhaka,BD,,23.72305971170,90.40857946670,5.00000000000,0,Changed scale rank.,12797394,7000940,14995538,14,13,1185241.00000000000,Dhaka,Dhaka,1,0,4.0
|
||||
2,200,6,Admin-0 capital,Luanda,,,0,Luanda,1.00000000000,,,0.00000000000,1,Angola,AGO,Angola,AGO,Luanda,AO,,-8.83828611363,13.23442704130,5.00000000000,0,Changed scale rank.,5172900,1951272,1951272,13,12,2240449.00000000000,Luanda,Luanda,1,0,4.0
|
||||
2,200,5,Admin-0 capital,Algiers,,El Djazacr,0,Algiers,1.00000000000,,,0.00000000000,1,Algeria,DZA,Algeria,DZA,Alger,DZ,,36.76306479800,3.05055252952,5.00000000000,0,Changed scale rank.,3354000,1977663,3332619,12,12,2507480.00000000000,El Djazasr,Algiers,1,5,4.0
|
||||
2,200,5,Admin-0 capital,Rangoon,,Yangon,0,Rangoon,0.00000000000,,Former capital,0.00000000000,1,Myanmar,MMR,Myanmar,MMR,Yangon,MM,,16.78335410460,96.16667761130,5.00000000000,0,Changed scale rank.,4088000,3301820,3124090,12,12,1298824.00000000000,Yangon,Rangoon,1,0,4.0
|
||||
1,300,1,Populated place,San Francisco,,San Francisco-Oakland,0,San Francisco,0.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,California,US,,37.74000775050,-122.45997766300,0.00000000000,0,,3450000,732072,27400,12,11,5391959.00000000000,San Francisco-Oakland,San Francisco1,1,0,2.7
|
||||
1,300,1,Admin-1 capital,Denver,,Denver-Aurora,0,Denver,0.00000000000,,,0.00000000000,1,United States,USA,United States of America,USA,Colorado,US,,39.73918804840,-104.98401595200,5.00000000000,0,Changed scale rank.,2313000,1548599,1521278,12,12,5419384.00000000000,Denver-Aurora,Denver,1,0,3.7
|
||||
1,300,1,Populated place,Houston,,,0,Houston,0.00000000000,,,0.00000000000,1,United States,USA,United States of America,USA,Texas,US,,29.81997438460,-95.33997929050,5.00000000000,0,Changed scale rank.,4459000,3647574,3607616,12,12,4699066.00000000000,Houston,Houston,1,0,3.0
|
||||
1,300,1,Populated place,Miami,,,0,Miami,0.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,Florida,US,,25.78761069640,-80.22410608080,0.00000000000,0,,5585000,382894,1037811,13,10,4164138.00000000000,Miami,Miami,1,0,2.1
|
||||
1,300,1,Admin-1 capital,Atlanta,,,0,Atlanta,0.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,Georgia,US,,33.83001385400,-84.39994938330,0.00000000000,0,,4506000,422908,2874096,12,10,4180439.00000000000,Atlanta,Atlanta,1,0,3.0
|
||||
1,300,1,Populated place,Chicago,,,0,Chicago,0.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,Illinois,US,,41.82999066070,-87.75005497410,0.00000000000,0,,8990000,2841952,3635101,13,12,4887398.00000000000,Chicago,Chicago,1,0,3.0
|
||||
1,300,6,Admin-0 capital,Caracas,,,0,Caracas,1.00000000000,,,1.00000000000,1,Venezuela,VEN,Venezuela,VEN,Distrito Capital,VE,,10.50099855440,-66.91703719240,4.00000000000,0,Changed scale rank.,2985000,1815679,2764555,12,12,3646738.00000000000,Caracas,Caracas,1,0,3.0
|
||||
1,300,5,Admin-0 capital,Kiev,,Kyiv,0,Kiev,1.00000000000,,,0.00000000000,1,Ukraine,UKR,Ukraine,UKR,Kiev,UA,,50.43336732900,30.51662796910,5.00000000000,0,Changed scale rank.,2709000,1662508,1611692,12,12,703448.00000000000,Kyiv,Kiev,1,0,3.7
|
||||
1,300,8,Admin-1 capital,Dubai,Dubayy,,0,Dubai,0.00000000000,,,1.00000000000,1,United Arab Emirates,ARE,United Arab Emirates,ARE,Dubay,AE,,25.22999615380,55.27997432340,1.00000000000,1,Name changed.,1379000,1137347,1166878,12,12,292223.00000000000,Dubayy,Dubayy,1,0,3.7
|
||||
1,300,6,Admin-0 capital,Tashkent,,,0,Tashkent,1.00000000000,,,0.00000000000,1,Uzbekistan,UZB,Uzbekistan,UZB,Tashkent,UZ,,41.31170188300,69.29493281950,5.00000000000,0,Changed scale rank.,2184000,1978028,2806287,12,12,1512569.00000000000,Tashkent,Tashkent,1,0,3.7
|
||||
1,300,3,Admin-0 capital,Madrid,,,0,Madrid,1.00000000000,,,1.00000000000,1,Kingdom of Spain,ESP,Spain,ESP,Comunidad de Madrid,ES,,40.40002626450,-3.68335168600,0.00000000000,0,,5567000,50437,3673427,13,8,3117735.00000000000,Madrid,Madrid,1,0,3.0
|
||||
1,300,7,Admin-1 capital,Geneva,,,0,Geneva,0.00000000000,,,1.00000000000,0,Switzerland,CHE,Switzerland,CHE,Genève,CH,,46.21000754710,6.14002803409,4.00000000000,0,Changed scale rank.,1240000,192385,508284,12,9,2660646.00000000000,,Geneva,1,0,3.7
|
||||
1,300,7,Admin-0 capital,Stockholm,,,0,Stockholm,1.00000000000,,,1.00000000000,1,Sweden,SWE,Sweden,SWE,Stockholm,SE,,59.35075995430,18.09733473280,4.00000000000,0,Location adjusted.,1264000,1253309,0,12,12,2673730.00000000000,Stockholm,Stockholm,1,0,3.0
|
||||
1,300,5,Admin-0 capital,Bangkok,,Krung Thep,0,Bangkok,1.00000000000,,,1.00000000000,1,Thailand,THA,Thailand,THA,Bangkok Metropolis,TH,,13.74999920550,100.51664465200,0.00000000000,0,,6704000,5104476,5082758,13,13,1609350.00000000000,Krung Thep,Bangkok,1,0,3.0
|
||||
1,300,5,Admin-0 capital,Lima,,,0,Lima,1.00000000000,,,0.00000000000,1,Peru,PER,Peru,PER,Lima,PE,,-12.04801267610,-77.05006209480,5.00000000000,0,Changed scale rank.,8012000,6758234,6068380,13,13,3936456.00000000000,Lima,Lima2,1,0,3.0
|
||||
1,300,8,Admin-0 capital,Dakar,,,0,Dakar,1.00000000000,,,0.00000000000,1,Senegal,SEN,Senegal,SEN,Dakar,SN,,14.71583172500,-17.47313012840,5.00000000000,0,Changed scale rank.,2604000,2476400,2470140,12,12,2253354.00000000000,Dakar,Dakar,1,0,3.0
|
||||
1,300,3,Admin-0 capital,Johannesburg,,,0,Johannesburg,0.00000000000,,,1.00000000000,1,South Africa,ZAF,South Africa,ZAF,Gauteng,ZA,,-26.17004474000,28.03000972360,4.00000000000,0,Changed feature class.,3435000,2026469,3852246,12,12,993800.00000000000,Johannesburg,Johannesburg,1,0,3.0
|
||||
1,300,8,Admin-0 capital,Amsterdam,,,0,Amsterdam,1.00000000000,,De facto capita,1.00000000000,1,Kingdom of the Netherlands,NLD,Netherlands,NLD,Noord-Holland,NL,,52.34996868810,4.91664017601,0.00000000000,0,,1031000,741636,962488,12,11,2759794.00000000000,Amsterdam,Amsterdam,1,0,3.7
|
||||
1,300,5,Admin-1 capital,Casablanca,,Dar-el-Beida,0,Casablanca,0.00000000000,,,1.00000000000,1,Morocco,MAR,Morocco,MAR,Grand Casablanca,MA,,33.59997621560,-7.61636743309,4.00000000000,0,Changed scale rank.,3181000,3144909,3718797,12,12,2553604.00000000000,Dar-el-Beida,Casablanca,1,0,3.7
|
||||
1,300,3,Admin-0 capital,Seoul,,,0,Seoul,1.00000000000,,,1.00000000000,1,"Korea, South",KOR,South Korea,KOR,Seoul,KR,,37.56634909980,126.99973099700,0.00000000000,0,,9796000,9796000,12018058,13,13,1835848.00000000000,Seoul,Seoul,1,0,3.0
|
||||
1,300,5,Admin-0 capital,Manila,,,0,Manila,1.00000000000,,"Official, de fa",1.00000000000,1,Philippines,PHL,Philippines,PHL,Metropolitan Manila,PH,,14.60415895480,120.98221716200,0.00000000000,0,,11100000,3077575,2381280,14,12,1701668.00000000000,Manila,Manila,1,0,2.7
|
||||
1,300,2,Admin-1 capital,Monterrey,,,0,Monterrey,0.00000000000,,,0.00000000000,1,Mexico,MEX,Mexico,MEX,Nuevo León,MX,,25.66999513650,-100.32998478400,5.00000000000,0,Changed scale rank.,3712000,1122874,3225636,12,12,3995465.00000000000,Monterrey,Monterrey,1,0,3.7
|
||||
1,300,3,Admin-0 capital,Berlin,,,0,Berlin,1.00000000000,,,1.00000000000,1,Germany,DEU,Germany,DEU,Berlin,DE,,52.52181866360,13.40154862330,0.00000000000,0,,3406000,3094014,3013258,12,12,2950159.00000000000,Berlin,Berlin,1,0,2.7
|
||||
1,300,1,Admin-1 capital,Ürümqi,,rumqi|Wulumqi,0,Urumqi,0.00000000000,,,0.00000000000,1,China,CHN,China,CHN,Xinjiang Uygur,CN,,43.80501222640,87.57500565490,5.00000000000,0,Changed scale rank.,2151000,1508225,2044401,12,12,1529102.00000000000,Cramqi (Wulumqi),Urumqi,1,0,3.7
|
||||
1,300,1,Admin-1 capital,Chengdu,,,0,Chengdu,0.00000000000,,,0.00000000000,1,China,CHN,China,CHN,Sichuan,CN,,30.67000001930,104.07001949000,5.00000000000,0,Changed scale rank.,4123000,3950437,11622929,12,12,1815286.00000000000,Chengdu,Chengdu,1,0,3.0
|
||||
1,300,2,Admin-1 region capital,Ōsaka,,Osaka-Kobe,0,Osaka,0.00000000000,,,1.00000000000,1,Japan,JPN,Japan,JPN,Osaka,JP,,34.75003521630,135.46014481500,4.00000000000,0,Changed feature to Admin-0 region capital.,11294000,2592413,9630783,14,12,1853909.00000000000,Osaka-Kobe,Osaka,1,5,3.0
|
||||
1,300,3,Admin-0 capital,Kinshasa,,,0,Kinshasa,1.00000000000,,,0.00000000000,1,Congo (Kinshasa),COD,Congo (Kinshasa),COD,Kinshasa City,CD,,-4.32972410189,15.31497188180,5.00000000000,0,Changed scale rank.,7843000,5565703,4738154,13,13,2314302.00000000000,Kinshasa,Kinshasa,1,0,3.0
|
||||
1,300,1,Admin-0 capital,New Delhi,,,0,New Delhi,1.00000000000,,,1.00000000000,0,India,IND,India,IND,Delhi,IN,,28.60002300920,77.19998002010,0.00000000000,0,,317797,317797,8060107,10,10,1261481.00000000000,,New Delhi,1,0,2.1
|
||||
1,300,1,Admin-1 capital,Bangalore,,Bengaluru,0,Bangalore,0.00000000000,,,0.00000000000,1,India,IND,India,IND,Karnataka,IN,,12.96999513650,77.56000972380,3.00000000000,1,Name changed. Changed scale rank.,6787000,5104047,8102712,13,13,1277333.00000000000,Bangalore,Bangalore,1,0,3.7
|
||||
1,300,6,Admin-0 capital,Athens,Athenai,Athinai,0,Athens,1.00000000000,,,1.00000000000,1,Greece,GRC,Greece,GRC,Attiki,GR,,37.98332623190,23.73332108430,4.00000000000,0,Changed scale rank.,3242000,729137,112572,12,11,264371.00000000000,Athnnai,Athens2,1,0,3.7
|
||||
1,300,5,Admin-0 capital,Baghdad,,,0,Baghdad,1.00000000000,,,0.00000000000,1,Iraq,IRQ,Iraq,IRQ,Baghdad,IQ,,33.33864849750,44.39386877320,5.00000000000,0,Changed scale rank.,5054000,5054000,4959534,13,13,98182.00000000000,Baghdad,Baghdad,1,0,3.7
|
||||
1,300,3,Admin-0 capital,Addis Ababa,,,0,Addis Ababa,1.00000000000,,,0.00000000000,1,Ethiopia,ETH,Ethiopia,ETH,Addis Ababa,ET,,9.03331036268,38.70000443400,5.00000000000,0,Changed scale rank.,3100000,2757729,3013653,12,12,344979.00000000000,Addis Ababa,Addis Ababa,1,5,3.0
|
||||
1,300,5,Admin-0 capital,Tehran,,,0,Tehran,1.00000000000,,,0.00000000000,1,Iran,IRN,Iran,IRN,Tehran,IR,,35.67194276840,51.42434403360,5.00000000000,0,Changed scale rank.,7873000,7153309,8209012,13,13,112931.00000000000,Tehran,Tehran,1,0,3.0
|
||||
1,300,2,Populated place,Vancouver,,,0,Vancouver,0.00000000000,,,0.00000000000,1,Canada,CAN,Canada,CAN,British Columbia,CA,,49.27341658410,-123.12164421800,5.00000000000,0,Changed scale rank.,2313328,603502,482002,12,11,6173331.00000000000,Vancouver,Vancouver2,1,0,2.1
|
||||
1,300,2,Admin-1 capital,Toronto,,,0,Toronto,0.00000000000,,,1.00000000000,1,Canada,CAN,Canada,CAN,Ontario,CA,,43.69997987780,-79.42002079440,0.00000000000,0,,5213000,3934421,3749229,13,12,6167865.00000000000,Toronto,Toronto,1,0,2.1
|
||||
1,300,3,Admin-0 capital,Buenos Aires,,,0,Buenos Aires,1.00000000000,,,1.00000000000,1,Argentina,ARG,Argentina,ARG,Ciudad de Buenos Aires,AR,,-34.60250160850,-58.39753137370,0.00000000000,0,,12795000,10929146,10271457,14,14,3435910.00000000000,Buenos Aires,Buenos Aires,1,0,2.1
|
||||
1,300,5,Admin-0 capital,Kabul,,,0,Kabul,1.00000000000,,,0.00000000000,1,Afghanistan,AFG,Afghanistan,AFG,Kabul,AF,,34.51669028630,69.18326004930,5.00000000000,0,Changed scale rank.,3277000,3043532,3475519,12,12,1138958.00000000000,Kabul,Kabul,1,0,3.7
|
||||
1,300,7,Admin-0 capital,Vienna,Wien,,0,Vienna,1.00000000000,,,1.00000000000,1,Austria,AUT,Austria,AUT,Wien,AT,,48.20001527820,16.36663895540,0.00000000000,0,,2400000,1731000,1480886,12,12,2761369.00000000000,Wien,Vienna,1,0,3.7
|
||||
1,300,3,Admin-1 capital,Melbourne,,,0,Melbourne,0.00000000000,,,1.00000000000,1,Australia,AUS,Australia,AUS,Victoria,AU,,-37.82003131230,144.97501623500,4.00000000000,0,Changed feature class. Changed scale rank.,4170000,93625,1805353,12,8,2158177.00000000000,Melbourne,Melbourne2,1,0,3.0
|
||||
1,300,8,Admin-0 capital,Taipei,,,0,Taipei,1.00000000000,,,1.00000000000,1,Taiwan,TWN,Taiwan,TWN,Taipei City,TW,,25.03583333333,121.56833333333,1.00000000000,0,Corrected coordinates.,6900273,2618772,5698241,13,12,1668341.00000000000,Taipei,Taipei,1,0,3.7
|
||||
1,300,8,Admin-1 capital,Auckland,,,0,Auckland,0.00000000000,,,1.00000000000,1,New Zealand,NZL,New Zealand,NZL,Auckland,NZ,Auckland metropolitan area,-36.84805489493,174.76302698708,4.00000000000,0,Changed scale rank.,1377200,395982,0,12,10,2193733.00000000000,Auckland,Auckland,1,0,3.0
|
||||
0,600,1,Populated place,Los Angeles,,Los Angeles-Long Beach-Santa Ana,0,Los Angeles,0.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,California,US,,33.98997825020,-118.17998051100,0.00000000000,0,,12500000,3694820,142265,14,12,5368361.00000000000,Los Angeles-Long Beach-Santa Ana,Los Angeles1,1,0,2.0
|
||||
0,600,1,Admin-0 capital,"Washington, D.C.",,Washington D.C.,0,"Washington, D.C.",1.00000000000,,,1.00000000000,1,United States,USA,United States of America,USA,District of Columbia,US,,38.89954937650,-77.00941858080,0.00000000000,0,,4338000,552433,2175991,12,11,4140963.00000000000,"Washington, D.C.","Washington, D.C.",1,5,2.1
|
||||
0,600,1,Populated place,New York,,New York-Newark,0,New York,0.00000000000,,UN Headquarters,1.00000000000,1,United States,USA,United States of America,USA,New York,US,,40.74997906400,-73.98001692880,0.00000000000,0,,19040000,8008278,9292603,14,13,5128581.00000000000,New York-Newark,New York,1,0,1.7
|
||||
0,600,5,Admin-0 capital,London,,,0,London,1.00000000000,,,1.00000000000,1,United Kingdom,GBR,United Kingdom,GBR,Westminster,GB,,51.49999472970,-0.11672184386,0.00000000000,0,,8567000,7421209,326670,13,13,2643743.00000000000,London,London2,1,5,1.7
|
||||
0,600,5,Admin-1 capital,Istanbul,,,0,Istanbul,0.00000000000,,,1.00000000000,1,Turkey,TUR,Turkey,TUR,Istanbul,TR,,41.10499615380,29.01000158560,0.00000000000,0,,10061000,9945610,9651488,14,13,745044.00000000000,Istanbul,Istanbul,1,0,3.0
|
||||
0,600,5,Admin-0 capital,Riyadh,,Ar-Riyadh,0,Riyadh,1.00000000000,,,1.00000000000,1,Saudi Arabia,SAU,Saudi Arabia,SAU,Ar Riyad,SA,,24.64083314920,46.77274165730,4.00000000000,0,Changed scale rank.,4465000,4205961,5148778,12,12,108410.00000000000,Ar-Riyadh,Riyadh,1,0,3.7
|
||||
0,600,3,Admin-0 capital,Cape Town,,,0,Cape Town,1.00000000000,1,Legislative cap,1.00000000000,1,South Africa,ZAF,South Africa,ZAF,Western Cape,ZA,,-33.92001096720,18.43498815780,4.00000000000,0,Changed scale rank.,3215000,2432858,2401318,12,12,3369157.00000000000,Cape Town,Cape Town,1,0,1.7
|
||||
0,600,2,Admin-0 capital,Moscow,Moskva,,0,Moscow,1.00000000000,,,1.00000000000,1,Russia,RUS,Russia,RUS,Moskva,RU,,55.75216412260,37.61552282590,0.00000000000,0,,10452000,10452000,10585385,14,14,524901.00000000000,Moskva,Moscow,1,0,1.7
|
||||
0,600,2,Admin-0 capital,Mexico City,,Ciudad de M,0,Mexico City,1.00000000000,,,1.00000000000,1,Mexico,MEX,Mexico,MEX,Distrito Federal,MX,,19.44244244280,-99.13098820170,0.00000000000,0,,19028000,10811002,10018444,14,14,3530597.00000000000,Ciudad de Mdxico,Mexico City,1,0,2.1
|
||||
0,600,2,Admin-0 capital alt,Lagos,,,0,Lagos,0.00000000000,1,Former capital,1.00000000000,1,Nigeria,NGA,Nigeria,NGA,Lagos,NG,,6.44326165348,3.39153107121,4.00000000000,0,Location adjusted. Changed scale rank.,9466000,1536,6567892,13,3,2332459.00000000000,Lagos,Lagos,1,0,2.0
|
||||
0,600,3,Admin-0 capital,Rome,,,0,Rome,1.00000000000,,,1.00000000000,1,Italy,ITA,Italy,ITA,Lazio,IT,,41.89595562650,12.48325842150,0.00000000000,0,,3339000,35452,2050212,12,7,3169070.00000000000,Rome,Rome,1,0,2.7
|
||||
0,600,1,Admin-0 capital,Beijing,,,0,Beijing,1.00000000000,,,1.00000000000,1,China,CHN,China,CHN,Beijing,CN,,39.92889223130,116.38828568400,0.00000000000,0,,11106000,7480601,9033231,14,13,1816670.00000000000,Beijing,Beijing,1,0,1.7
|
||||
0,600,5,Admin-0 capital,Nairobi,,,0,Nairobi,1.00000000000,,,1.00000000000,1,Kenya,KEN,Kenya,KEN,Nairobi,KE,,-1.28334674185,36.81665685910,4.00000000000,0,Changed scale rank.,3010000,2750547,3400962,12,12,184745.00000000000,Nairobi,Nairobi,1,0,2.0
|
||||
0,600,1,Admin-0 capital,Jakarta,,,0,Jakarta,1.00000000000,,,1.00000000000,1,Indonesia,IDN,Indonesia,IDN,Jakarta Raya,ID,,-6.17441770541,106.82943762100,0.00000000000,0,,9125000,8540121,9129613,13,13,1642911.00000000000,Jakarta,Jakarta,1,0,2.1
|
||||
0,600,5,Admin-0 capital,Bogota,,Bogota,0,Bogota,1.00000000000,,,1.00000000000,1,Colombia,COL,Colombia,COL,Bogota,CO,,4.59642356253,-74.08334395520,0.00000000000,0,,7772000,6333661,5754084,13,13,3688689.00000000000,Bogota,Bogota,1,0,2.1
|
||||
0,600,3,Admin-0 capital,Cairo,,Al-Qahirah,0,Cairo,1.00000000000,,,1.00000000000,1,Egypt,EGY,Egypt,EGY,Al Qahirah,EG,,30.04996034650,31.24996821970,0.00000000000,0,,11893000,7734614,13720557,14,13,360630.00000000000,Al-Qahirah,Cairo,1,5,1.7
|
||||
0,600,1,Admin-1 capital,Shanghai,,,0,Shanghai,0.00000000000,,,1.00000000000,1,China,CHN,China,CHN,Shanghai,CN,,31.21645245260,121.43650467800,0.00000000000,0,,14987000,14608512,16803572,14,14,1796236.00000000000,Shanghai,Shanghai,1,0,2.0
|
||||
0,600,2,Admin-0 capital,Tokyo,,,0,Tokyo,1.00000000000,,De facto capita,1.00000000000,1,Japan,JPN,Japan,JPN,Tokyo,JP,,35.68501690580,139.75140742900,0.00000000000,0,,35676000,8336599,12945252,14,13,1850147.00000000000,Tokyo,Tokyo,1,0,1.7
|
||||
0,600,1,Admin-1 capital,Mumbai,Bombay,,0,Mumbai,0.00000000000,,,1.00000000000,1,India,IND,India,IND,Maharashtra,IN,,19.01699037570,72.85698929740,0.00000000000,0,,18978000,12691836,12426085,14,14,1275339.00000000000,Mumbai,Mumbai,1,0,1.7
|
||||
0,600,3,Admin-0 capital,Paris,,,0,Paris,1.00000000000,,,1.00000000000,1,French Republic,FRA,France,FRA,Île-de-France,FR,,48.86669293120,2.33333532574,0.00000000000,0,,9904000,11177,7142744,13,6,2988507.00000000000,Paris,Paris,1,0,1.7
|
||||
0,600,3,Admin-0 capital,Santiago,,,0,Santiago,1.00000000000,,"Official, admin",1.00000000000,1,Chile,CHL,Chile,CHL,Región Metropolitana de Santiago,CL,,-33.45001381550,-70.66704085460,4.00000000000,0,Changed scale rank.,5720000,46611,3066651,13,7,3449741.00000000000,Santiago,Santiago3,1,0,2.0
|
||||
0,600,1,Admin-1 capital,Kolkata,Calcutta,,0,Kolkata,0.00000000000,,,0.00000000000,1,India,IND,India,IND,West Bengal,IN,,22.49496929830,88.32467565810,4.00000000000,1,Name changed. Changed scale rank.,14787000,4631392,7783716,14,12,1275004.00000000000,Kolkata,Calcutta,1,0,3.7
|
||||
0,600,1,Admin-1 capital,Rio de Janeiro,,,0,Rio de Janeiro,0.00000000000,,,1.00000000000,1,Brazil,BRA,Brazil,BRA,Rio de Janeiro,BR,,-22.92502317420,-43.22502079420,0.00000000000,0,,11748000,2010175,1821489,14,12,3451190.00000000000,Rio de Janeiro,Rio de Janeiro,1,0,1.7
|
||||
0,600,1,Admin-1 capital,São Paulo,,Sao Paulo|Sio Paulo,0,Sao Paulo,0.00000000000,,,1.00000000000,1,Brazil,BRA,Brazil,BRA,São Paulo,BR,,-23.55867958700,-46.62501998040,0.00000000000,0,,18845000,10021295,11522944,14,14,3448439.00000000000,S,Sao Paolo,1,0,3.0
|
||||
0,600,3,Admin-1 capital,Sydney,,,0,Sydney,0.00000000000,,,1.00000000000,1,Australia,AUS,Australia,AUS,New South Wales,AU,,-33.92001096720,151.18517980900,4.00000000000,0,Changed feature class.,4630000,3641422,2669348,12,12,2147714.00000000000,Sydney,Sydney1,1,0,
|
||||
0,600,0,Admin-0 capital,Singapore,,,0,Singapore,1.00000000000,,,1.00000000000,1,Singapore,SGP,Singapore,SGP,,SG,,1.29303346649,103.85582067800,0.00000000000,0,,5183700,3289529,3314179,13,12,1880252.00000000000,Singapore,Singapore,1,5,2.1
|
||||
0,600,0,Admin-0 region capital,Hong Kong,,,0,Hong Kong,0.00000000000,,,1.00000000000,1,China,CHN,Hong Kong S.A.R.,HKG,,HK,,22.30498089500,114.18500931700,0.00000000000,0,,7206000,4551579,4549026,13,12,1819729.00000000000,Hong Kong,Hong Kong,1,0,3.0
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
0,600,0,Admin-0 region capital,Hong Kong,,,0,Hong Kong,0.00000000000,,,1.00000000000,1,China,CHN,Hong Kong S.A.R.,HKG,,HK,,nan,114.18500931700,0.00000000000,0,,7206000,4551579,4549026,13,12,1819729.00000000000,Hong Kong,Hong Kong,1,0,3.0
|
||||
0,600,0,Admin-0 region capital,Hong Kong,,,0,Hong Kong,0.00000000000,,,1.00000000000,1,China,CHN,Hong Kong S.A.R.,HKG,,HK,,inf,114.18500931700,0.00000000000,0,,7206000,4551579,4549026,13,12,1819729.00000000000,Hong Kong,Hong Kong,1,0,3.0
|
||||
0,600,0,Admin-0 region capital,Hong Kong,,,0,Hong Kong,0.00000000000,,,1.00000000000,1,China,CHN,Hong Kong S.A.R.,HKG,,HK,,22.30498089500,nan,0.00000000000,0,,7206000,4551579,4549026,13,12,1819729.00000000000,Hong Kong,Hong Kong,1,0,3.0
|
||||
0,600,0,Admin-0 region capital,Hong Kong,,,0,Hong Kong,0.00000000000,,,1.00000000000,1,China,CHN,Hong Kong S.A.R.,HKG,,HK,,22.30498089500,inf,0.00000000000,0,,7206000,4551579,4549026,13,12,1819729.00000000000,Hong Kong,Hong Kong,1,0,3.0
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -3,8 +3,7 @@
|
||||
"center": "-135.000000,75.782195,2",
|
||||
"description": "tests/curve/out/-z2.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"generator_options": "./tippecanoe -q -a@ -f -o tests/curve/out/-z2.json.check.mbtiles -z2 tests/curve/in.json",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 2,\"geometry\": \"Polygon\",\"attributeCount\": 0,\"attributes\": []}]}}",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ] }",
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2.json.check.mbtiles",
|
||||
@ -31,7 +30,7 @@
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.008789, 83.004844 ], [ -82.001953, 82.003058 ], [ -106.040039, 70.005567 ], [ -103.007812, 32.026706 ], [ -92.724609, 0.000000 ], [ -91.625977, -3.513421 ], [ -108.632812, -3.513421 ], [ -109.731445, 0.000000 ], [ -118.037109, 26.037042 ], [ -117.026367, 71.002660 ], [ -99.008789, 83.004844 ] ] ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 3.515625, 83.004844 ], [ 3.515625, 80.004799 ], [ -88.022461, 80.004799 ], [ -119.003906, 71.002660 ], [ -115.751953, 0.000000 ], [ -115.620117, -3.513421 ], [ -139.042969, -3.513421 ], [ -139.042969, 74.007440 ], [ -101.030273, 83.004844 ], [ 3.515625, 83.004844 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.000000, 83.004844 ], [ 3.515625, 80.004799 ], [ -88.022461, 80.004799 ], [ -119.003906, 71.002660 ], [ -115.751953, 0.000000 ], [ -115.620117, -3.513421 ], [ -139.042969, -3.513421 ], [ -139.042969, 74.007440 ], [ -101.030273, 83.004844 ], [ 0.000000, 83.004844 ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
,
|
||||
@ -97,7 +96,7 @@
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -91.757812, 82.591775 ], [ -90.000000, 82.489081 ], [ -82.001953, 82.000000 ], [ -90.000000, 79.134119 ], [ -91.757812, 78.376004 ], [ -91.757812, 82.591775 ] ] ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 1.757812, 83.002167 ], [ 1.757812, 80.000984 ], [ -88.000488, 80.000984 ], [ -90.000000, 79.576460 ], [ -91.757812, 79.191956 ], [ -91.757812, 83.002167 ], [ 1.757812, 83.002167 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.000000, 83.002167 ], [ 1.757812, 80.000984 ], [ -88.000488, 80.000984 ], [ -90.000000, 79.576460 ], [ -91.757812, 79.191956 ], [ -91.757812, 83.002167 ], [ 0.000000, 83.002167 ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
,
|
||||
@ -111,7 +110,7 @@
|
||||
,
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 2, "x": 2, "y": 0 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 91.757812, 83.002167 ], [ 91.757812, 80.000984 ], [ -1.757812, 80.000984 ], [ -1.757812, 83.002167 ], [ 91.757812, 83.002167 ] ] ] } }
|
||||
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0.000000, 83.002167 ], [ 91.757812, 80.000984 ], [ -1.757812, 80.000984 ], [ -1.757812, 83.002167 ], [ 0.000000, 83.002167 ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
,
|
||||
|
@ -3,8 +3,7 @@
|
||||
"center": "-135.000000,75.782195,2",
|
||||
"description": "tests/curve/out/-z2_--no-clipping.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"generator_options": "./tippecanoe -q -a@ -f -o tests/curve/out/-z2_--no-clipping.json.check.mbtiles -z2 --no-clipping tests/curve/in.json",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 2,\"geometry\": \"Polygon\",\"attributeCount\": 0,\"attributes\": []}]}}",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ] }",
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2_--no-clipping.json.check.mbtiles",
|
||||
|
@ -3,8 +3,7 @@
|
||||
"center": "45.000000,33.256630,2",
|
||||
"description": "tests/curve/out/-z2_--no-duplication.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"generator_options": "./tippecanoe -q -a@ -f -o tests/curve/out/-z2_--no-duplication.json.check.mbtiles -z2 --no-duplication tests/curve/in.json",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 2,\"geometry\": \"Polygon\",\"attributeCount\": 0,\"attributes\": []}]}}",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 2, \"fields\": {} } ] }",
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2_--no-duplication.json.check.mbtiles",
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user