Skip to main content

Fetch and decode vector tiles

Project description

vtdecode

This project centers around decoding Vector Tile formats (protobuf) files and converting them to JSON. It uses the same backend for decoding Vertex Tile files, and provides multiple entrypoints for fetching those files.

Installation

This package is available on PyPI.

pip install vtdecode

It provides three commands: vtdecode, vtdecode-mapbox and vtdecode-mapillary

Entrypoints

vtdecode

Decodes a Vertex-Tile Protobuf on the local machine, and saves it to a JSON file containing GeoJSON.

usage: main.py [-h] -i INPUT_FILE -o OUTPUT_FILE [-x TILE_X] [-y TILE_Y] [-z TILE_Z] [--json-indent JSON_INDENT] [--layer LAYER] [--split-layers]

Convert Vector Tile Protobuf files to GeoJSON, and saves it to a *.json file.

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_FILE, --input INPUT_FILE
                        Input file
  -o OUTPUT_FILE, --output OUTPUT_FILE
                        Output file
  -x TILE_X             X coordinate of tile
  -y TILE_Y             Y coordinate of tile
  -z TILE_Z             Zoom level of tile
  --json-indent JSON_INDENT
                        JSON file indentation. 0 or negative numbers generate dense JSON file.
  --layer LAYER         Only decode layer with given name. Outputs Pure GeoJSON.
  --split-layers        Split layers into separate GeoJSON files. Outputs Pure GeoJSON.

X, Y, and Zoom levels represent the tile coordinates as specified in https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames. This information is necessary to calculate the actual latitude and longitude of point coordinates.

When not using the --layer or --split-layer options, the output file will contain multiple GeoJSON features, denoted by their keys. When using the --layer LAYER_NAME option, only a single layer will be exported, and the output will be a single GeoJSON FeatureCollection. When using the --split-layer option, multiple files will be generated (suffixed with the layer name), each containing a single layer in GeoJSON FeatureCollection.

Example usage: vtdecode --input sample_14_8185_5449.pbf -x 8185 -y 5449 -z 14 --output-file sample_14_8185_5449.json.

vtdecode-mapillary, vtdecode-mapbox

Fetch data from Mapillary or Mapbox, convert them to GeoJSON, and put them into a folder.

Fetching a range of tiles: If all of --start-x, --start-y, --end-x, --end-y is provided, the URL will be treated as a template, replace {x} and {y}, and fetch all tiles within the specified range.

When fetching a range of tiles, you must use --output-dir to specify an output directory.

Fetching a single tile: If any of--start-x, --start-y, --end-x, --end-y is not provided, the URL will be treated as a pure URL and only a single file will be fetched.

When fetching a single tile, you can either use --output-dir to specify a directory or --output to specify an output filename. When both is provided, --output is preferred.

usage: mapillary.py [-h] --url URL [--start-x START_X] [--start-y START_Y] [--end-x END_X] [--end-y END_Y] [--json-indent JSON_INDENT] [--output-dir OUTPUT_DIR] [--split-layers] [--output OUTPUT]

Fetch multiple tiles from mapillary.com and convert to GeoJSON.

optional arguments:
  -h, --help            show this help message and exit
  --url URL             URL template of tiles to fetch. {x} and {y} in the template will be replaced.
  --start-x START_X     X coordinate of first tile
  --start-y START_Y     Y coordinate of first tile
  --end-x END_X         X coordinate of last tile (inclusive)
  --end-y END_Y         Y coordinate of last tile (inclusive)
  --json-indent JSON_INDENT
                        JSON file indentation. 0 or negative numbers generate dense JSON file.
  --output-dir OUTPUT_DIR
                        Output directory
  --split-layers        Split layers into separate GeoJSON files. Outputs Pure GeoJSON.
  --output OUTPUT       Output file

Example usage:

Fetching a range of tiles: vtdecode-mapillary --url "https://tiles.mapillary.com/maps/vtp/mly_map_feature_traffic_sign/2/14/{x}/{y}?access_token=<YOUR_API_KEY>" --start-x 2744 --end-x 2748 --start-y 6520 --end-y 6524 --output-dir "./traffic-signs" --json-indent 4

Note that the Mapillary URL must resemble https://tiles.mapillary.com/maps/vtp/<feature-type>/2/<zoom-level>/{x}/{y}******. The program will try to parse the string and find object type and tile coordinates. Zoom level should be fixed and directly encoded in the URL.

Fetching a single tile: vtdecode-mapillary --url https://tiles.mapillary.com/maps/vtp/mly_map_feature_traffic_sign/2/14/2745/6520?access_token=<YOUR_API_KEY> --output-file traffic-signs-14-2745-6520.json.

Here the URL is treated as fixed.

Output Format

A Vertex Tile file may contain multiple layers, each layer containing a FeatureCollection GeoJSON object. However, there can only be one FeatureCollection in each GeoJSON file.

Therefore, when none of --layer or --split-layers is provided, all generated GeoJSON objects will be put into a single JSON file. The generated JSON object will contain keys that correspond to layer names, and values as the GeoJSON object.

For example, parsing a terrain file from mapbox generates a JSON file like this:

{
    "landcover": <A GeoJSON object>,
    "hillshade": <A GeoJSON object>,
    "contour": <A GeoJSON object>
}

This behavior can be avoided if you use the --layer or --split-layers switch. For example, if you used --layer landcover, the output JSON file will be a pure GeoJSON that contains only the landcover layer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vtdecode-1.2.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vtdecode-1.2.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file vtdecode-1.2.1.tar.gz.

File metadata

  • Download URL: vtdecode-1.2.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.11

File hashes

Hashes for vtdecode-1.2.1.tar.gz
Algorithm Hash digest
SHA256 66a8275ed72545f07ebbdd6a37d5be927f3d3ab4fef7d65c844f435a29390c7c
MD5 0579388c2afeeec7f5558930764db3bc
BLAKE2b-256 8b564349f82975c4b6dd04f2b8ceaa777153276006fb83ac05a1382a20c0f5e8

See more details on using hashes here.

File details

Details for the file vtdecode-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: vtdecode-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.11

File hashes

Hashes for vtdecode-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d0d97426069a1ae346aeb3b78da53c543359b0a5193263b8cf3c6653b638025
MD5 92704e1b933bf80b4f0000bd683e1cad
BLAKE2b-256 b75defcf986ce8420d900e07e69057886a16b21fabcf6882973a00b8b8bd3346

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page