tippecanoe

repository·main·Indexed 23 days ago

https://github.com/felt/tippecanoe

A tool for building highly performant vector tilesets from large collections of GeoJSON, FlatGeobuf, or CSV features. It creates scale-independent views that preserve data density and texture from global to local zoom levels, supporting output to .mbtiles, .pmtiles, or directories.

Tokens
13K
Snippets
17
Records
77
Agent score
68%

What's inside tippecanoe

  1. Overview of tile-join

    main
    tile-join is a utility for copying, merging, and augmenting vector tilesets (.mbtiles or .pmtiles). It can merge multiple source tilesets into one and join new attributes from a CSV file to existing features based on a matching key.
  2. Use the GeoJSON extension for zoom and layer control

    main

    You can control the visibility and organization of individual features within a tileset by adding a tippecanoe object directly to the GeoJSON Feature. This object takes precedence over CLI flags like --layer.

    Supported keys in the tippecanoe object:

    • minzoom: The minimum zoom level at which the feature is included. Specifying this prevents the feature from being dropped by dot-dropping (-r).
    • maxzoom: The maximum zoom level at which the feature is included.
    • layer: The name of the layer this feature belongs to.

    Note: The tippecanoe object must be a sibling to properties and geometry within the Feature object, not inside properties.

  3. Use pre- and post-filters for feature transformation

    main

    You can run shell commands to filter or transform features as tiles are being assembled using -C (prefilter) and -c (postfilter).

    Filter Mechanics:

    • Features are passed via stdin as newline-delimited GeoJSON objects.
    • The filter must write the resulting GeoJSON features to stdout.
    • The shell command receives three arguments: $1 (zoom), $2 (X), and $3 (Y).

    Filter Types:

    • Prefilter (-C): Runs at highest resolution, before simplification, topology repair, or dropping. It receives features with the tippecanoe element (which may include index, sequence, extent, and dropped). You must pass the tippecanoe element through to maintain internal operations.
    • Postfilter (-c): Runs at tile resolution, after simplification and cleaning.
  4. Quickstart: Recommended options for unknown datasets

    main

    If you are unsure which options to use, start with this command to automatically select a maximum zoom level and drop the least visible features to keep tile sizes manageable:

    tippecanoe -zg -o out.mbtiles --drop-densest-as-needed in.geojson
    • -zg: Automatically chooses a maximum zoom level sufficient for the data's precision.
    • --drop-densest-as-needed: Drops the least visible features at each zoom level to prevent tiles from becoming too large.
    tippecanoe -zg -o out.mbtiles --drop-densest-as-needed in.geojson
  5. Run tippecanoe using Docker

    main

    You can build and run a tippecanoe environment using Docker to avoid local dependency issues. The following commands build the image from the current directory and run a conversion task, mounting a local directory to /data inside the container.

    $ docker build -t tippecanoe:latest .
    $ docker run -it --rm \
      -v /tiledata:/data \
      tippecanoe:latest \
      tippecanoe --output=/data/output.mbtiles /data/example.geojson
  6. Selectively remove and replace features in a tileset

    main

    You can update a tileset by selectively removing specific features and replacing them with new ones using tile-join. This process involves:

    1. Creating an initial tileset from your source data.
    2. Using tile-join with a filter (-j) to create a copy of the tileset that excludes the features you want to replace.
    3. Creating a new tileset containing only the replacement features.
    4. Merging the filtered tileset and the new tileset into a final version.

    Note: When performing these operations, use the -z flag to explicitly specify the same maxzoom for all tilesets to ensure they are compatible.

    Example: Replacing Alameda County Census tracts

    # 1. 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
    
    # 2. Create a copy of the tileset, minus Alameda County (FIPS code 001)
    # The -j flag uses a filter to exclude features where COUNTYFP00 == 001
    tile-join -j '{"*":["none",["==","COUNTYFP00","001"]]}' -f -o tracts-filtered.mbtiles tracts.mbtiles
    
    # 3. 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
    
    # 4. Merge the filtered tileset and the new tracts into a final tileset
    tile-join -o tracts-final.mbtiles tracts-filtered.mbtiles tracts-added.mbtiles
    # 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 new tracts into a final tileset
    tile-join -o tracts-final.mbtiles tracts-filtered.mbtiles tracts-added.mbtiles
  7. Install tippecanoe on Linux

    main

    To build tippecanoe from source on Linux, you must install gcc, g++, make, libsqlite3-dev, and zlib1g-dev.

    Note: Tippecanoe requires C++11 or newer. If your default g++ is older, you may need to install a newer version (e.g., g++-5) and set the CXX environment variable.

  8. Configure zoom levels and layers via GeoJSON extension

    main

    You can control feature visibility and layer naming directly within your source GeoJSON by adding a tippecanoe object to each feature. This object must be a sibling to properties and geometry (not inside properties).

    Supported keys in the tippecanoe object:

    • minzoom: The minimum zoom level at which the feature is included.
    • maxzoom: The maximum zoom level at which the feature is included.
    • layer: The name of the layer this feature belongs to (overrides --layer).

    If your source data has these values inside properties, use ndjson-cli to move them into the tippecanoe object before running tippecanoe.

  9. Configure parallel threads via TIPPECANOE_MAX_THREADS

    main
    Tippecanoe uses as many parallel threads as there are available CPUs. To limit or increase the number of threads used during processing, set the TIPPECANOE_MAX_THREADS environment variable.
  10. Recommended starting options for tippecanoe

    main

    If you are unsure which options to use, start with this pattern to ensure a good balance between detail and tile size:

    $ tippecanoe -zg -o out.mbtiles --drop-densest-as-needed in.geojson
    • -zg: Automatically chooses a maximum zoom level high enough to reflect the precision of the original data.
    • --drop-densest-as-needed: If tiles are too large, Tippecanoe drops the least visible features at each zoom level to keep tile sizes manageable.
  11. Configure feature dropping and zoom levels

    main

    When generating tiles, you can control how features are simplified or dropped across different zoom levels using the following parameters:

    • --maxzoom (-z): The highest zoom level in the tile set.
    • --minzoom (-Z): The lowest zoom level in the tile set.
    • --basezoom (-B): The zoom level at which feature dropping begins.
    • --drop-rate (-r): The rate at which features are dropped. Note that -r requires either -zg (guess max zoom) or --smallest-maximum-zoom-guess to function correctly.

    Example of setting a max zoom and a drop rate:

    tippecanoe -z 14 -r 0.5 input.json
  12. Install tippecanoe

    main

    Tippecanoe can be installed on macOS using Homebrew or built from source on Ubuntu.

    macOS (Homebrew):

    $ brew install tippecanoe

    Ubuntu (Source):

    $ git clone https://github.com/felt/tippecanoe.git
    $ cd tippecanoe
    $ make -j
    $ make install
    $ brew install tippecanoe