Swiftpack.co - Outdooractive/mvt-tools as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Outdooractive.
Outdooractive/mvt-tools v1.2.7
Mapnik vector tiles (mvt) reader/writer for Swift
⭐️ 2
🕓 7 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Outdooractive/mvt-tools.git", from: "v1.2.7")


Mapnik vector tiles (MVT) reader/writer for Swift.

Installation with Swift Package Manager

dependencies: [
    .package(url: "https://github.com/Outdooractive/mvt-tools", from: "1.0.0"),
targets: [
    .target(name: "MyTarget", dependencies: [
        .product(name: "MVTTools", package: "mvt-tools"),

Command line tool

You can install the command line tool mvt locally to /usr/local/bin with

# ./install_mvt.sh

# mvt -h
OVERVIEW: A utility for inspecting and working with vector tiles.

USAGE: mvt <subcommand>

  dump (default)          Print the vector tile as GeoJSON
  info                    Print information about the vector tile
  merge                   Merge two or more vector tiles
  query                   Query the features in a vector tile
  export                  Export the vector tile as GeoJSON
  import                  Import some GeoJSONs to a vector tile


  • Load and write Mapnik Vector Tiles from/to disk or data objects (also handles gzipped input)
  • Export options: Zipped, buffered (in pixels or extents), simplified (in meters or extents)
  • Can dump a tile as a GeoJSON object
  • Supported projections: EPSG:4326, EPSG:3857 or none (uses the tile's coordinate space)
  • Fast search (supports indexing), either within a bounding box or with center and radius
  • Extract selected layers into a new tile
  • Merge two tiles into one
  • Can extract some infos from tiles like feature count, etc.
  • Command line tool



import MVTTools

// Load
let mvtData = Data(contentsOf: URL(fileURLWithPath: "14_8716_8015.vector.mvt"))!
let tile = VectorTile(data: mvtData, x: 8716, y: 8015, z: 14, indexed: .hilbert)!


let tileAsGeoJsonData: Data? = tile.toGeoJson(prettyPrinted: true)

let result = tile.query(at: Coordinate3D(latitude: 3.870163, longitude: 11.518585), tolerance: 100.0)


import MVTTools

var tile = VectorTile(x: 8716, y: 8015, z: 14)!
var feature = Feature(Point(Coordinate3D(latitude: 3.870163, longitude: 11.518585)))
feature.properties = [
    "test": 1,
    "test2": 5.567,
    "test3": [1, 2, 3],
    "test4": [
        "sub1": 1,
        "sub2": 2

tile.setFeatures([feature], for: "test")

// Also have a look at ``VectorTileExportOptions``
let tileData = tile.data()


Please create an issue or open a pull request with a fix

Dependencies (for development)

brew install protobuf swift-protobuf swiftlint

TODOs and future improvements





Thomas Rasch, Outdooractive


Stars: 2
Last commit: 7 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

8 weeks ago

Bugfix: Query bounding boxes in the western hemisphere where inverted and therefore the search often returned wrong results

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics