mvt-tools

0.3.9

Vector tiles reader/writer for Swift
Outdooractive/mvt-tools

What's New

0.3.9

2022-06-22T15:25:21Z

Adds mvttool, a command line tool for working with vector tiles.

Currently supported actions:

  • Dump the tile as a GeoJSON FeatureCollection
  • Show some information about the tile (layers, feature count, etc.)
  • Search in tiles, either around a coordinate or with a search term (will search in the property values)

MVTTools

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

Installation with Swift Package Manager

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

Features

  • Load and write Mapnik Vector Tiles from/to disk or data objects
  • 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.

Usage

Load

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)!

print(tile.isIndexed)
print(tile.layerNames.sorted())

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

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

Write

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()
...

Contributing

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

Links

License

MIT

Author

Thomas Rasch, Outdooractive

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Wed Jun 29 2022 08:41:56 GMT-0500 (GMT-05:00)