MVT Wrangler
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.
Overview
MVT Wrangler reads PMTiles files (containing MVT data) and outputs filtered PMTiles 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
Features
- 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
Installation
Prerequisites
- Rust (if you don't have it, rustup is the easiest way to install)
Building from Source
The compiled binary will be available at target/release/mvt-wrangler.
Usage
Basic Syntax
Arguments
input: Path to the input PMTiles fileoutput: Path for the output PMTiles file (will be overwritten if it exists)--filter/-f: Optional path to a GeoJSON filter file--name/-n: Set TileJSONname--description/-N: Set TileJSONdescription--attribution/-A: Set TileJSONattribution
Examples
Simple Conversion (No Filtering)
With Filtering
Override Metadata
# Set display name, description and attribution
Dynamic Filtering
The tool supports sophisticated filtering through GeoJSON filter files. See FILTERING.md for complete documentation.
Quick Filter Example
Create a filter file remove-parks.geojson:
Then apply it:
Filter Capabilities
- 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
- Comparison operators (
Filter Expression Examples
Remove Features by Type
Remove Features with Specific Attributes
Remove Tags by Key Pattern
Complex Logical Conditions
Performance
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
Output Format
The output PMTiles file follows the PMTiles specification.
This tool uses the pmtiles-rs library. When pmtiles-rs gains support for pmtiles writing, this tool will also switch to pmtiles output.
Use Cases
Data Cleaning
Remove unwanted features or properties from vector tiles:
# Remove all POI features globally
Privacy Compliance
Strip personally identifiable information:
# Remove all name tags starting with personal prefixes
Data Optimization
Reduce tile size by removing unnecessary attributes:
# Keep only essential properties for rendering
Requirements
- Input files must be valid PMTiles with MVT tile type
- Filter files must be valid GeoJSON FeatureCollections
License
This project is licensed under the MIT License. See the LICENSE file for details.