Show HN: A tool to post-process MVT vector tiles quickly

1 day ago 5

A high-performance Rust tool for processing and transforming Mapbox Vector Tiles (MVT) with advanced filtering capabilities. Apply sophisticated spatial and attribute-based filters to slim down your tiles.

For example, I'm a big fan of Protomaps' tiles generated from OpenStreetMap, but when serving tiles to Japanese customers, there are a couple things that need to be tweaked (sensitive areas, removing data that won't be shown anyways, etc..). Instead of downloading and reprocessing all the tiles from scratch, this tool takes in an already-built PMTiles archive, applies the desired filters, and outputs the filtered tiles.

MVT Wrangler reads PMTiles files (containing MVT data) and outputs filtered MBTiles databases. It provides a powerful filtering system that allows you to:

  • Remove entire features based on attributes or geometry types
  • Strip specific tags/properties from features
  • Apply filters spatially using GeoJSON geometries
  • Process tiles efficiently with parallel processing
  • Spatial Filtering: Filter features based on spatial intersection with GeoJSON geometries
  • Attribute Filtering: Remove features or tags based on complex expressions
  • High Performance: Parallel tile processing with optimized database writes
  • Flexible Expressions: Maplibre-style filter expressions for complex filtering logic
  • Rust (if you don't have it, rustup is the easiest way to install)
git clone https://github.com/KotobaMedia/mvt-wrangler.git cd mvt-wrangler cargo build --release

The compiled binary will be available at target/release/mvt-wrangler.

mvt-wrangler <input.pmtiles> <output.mbtiles> [--filter <filter.geojson>]
  • input: Path to the input PMTiles file
  • output: Path for the output MBTiles file (will be overwritten if it exists)
  • --filter / -f: Optional path to a GeoJSON filter file

Simple Conversion (No Filtering)

mvt-wrangler input.pmtiles output.mbtiles
mvt-wrangler input.pmtiles output.mbtiles --filter my-filter.geojson

The tool supports sophisticated filtering through GeoJSON filter files. See FILTERING.md for complete documentation.

Create a filter file remove-parks.geojson:

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[ [-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90] ]] }, "properties": { "id": "global-park-filter", "description": "Remove all park features worldwide", "layers": { "*": { "feature": [ "in", ["tag", "kind"], ["literal", ["park", "recreation_ground"]] ] } } } } ] }

Then apply it:

mvt-wrangler input.pmtiles clean-output.mbtiles --filter remove-parks.geojson
  • Spatial Scope: Filters only apply to features intersecting the filter geometry
  • Layer Targeting: Apply different rules to different MVT layers
  • Feature Removal: Drop entire features based on conditions
  • Tag Stripping: Remove specific properties/tags from features
  • Expression Language: Rich filtering expressions supporting:
    • Comparison operators (==, !=, <, >, etc.)
    • Logical operators (any, all, none, not)
    • String operations (starts-with, ends-with, regex-match, regex-capture)
    • Membership tests (in)
    • Geometry type checks
    • And much more

Filter Expression Examples

["==", ["type"], "Point"]

Remove Features with Specific Attributes

["in", ["tag", "amenity"], ["literal", ["parking", "fuel"]]]

Remove Tags by Key Pattern

["starts-with", ["key"], "name:"]

Complex Logical Conditions

["all", ["==", ["type"], "LineString"], ["in", ["tag", "highway"], ["literal", ["residential", "tertiary"]]] ]

The tool is optimized for processing large tile sets:

  • Parallel Processing: Utilizes all CPU cores for tile transformation
  • Optimized Database: Uses SQLite performance pragmas for fast writes
  • Memory Efficient: Streams tiles without loading entire datasets
  • Progress Tracking: Real-time progress indication for long operations

The output MBTiles file follows the MBTiles specification.

This tool uses the pmtiles-rs library. When pmtiles-rs gains support for pmtiles writing, this tool will also switch to pmtiles output.

Remove unwanted features or properties from vector tiles:

# Remove all POI features globally mvt-wrangler source.pmtiles clean.mbtiles --filter remove-pois.geojson

Strip personally identifiable information:

# Remove all name tags starting with personal prefixes mvt-wrangler source.pmtiles anonymized.mbtiles --filter remove-personal-names.geojson

Reduce tile size by removing unnecessary attributes:

# Keep only essential properties for rendering mvt-wrangler full.pmtiles minimal.mbtiles --filter essential-only.geojson
  • Input files must be valid PMTiles with MVT tile type
  • Filter files must be valid GeoJSON FeatureCollections

This project is licensed under the MIT License. See the LICENSE file for details.

Read Entire Article