Skip to main content

Python library for encoding mapbox vector tiles into tile_pbf

Project description

vt2pbf

Python port of JS vt-pbf to Encode Mapbox vector tiles to binary protobufs in python. Right now available only version 2 of mapbox vector tiles spec

Install

vt2pbf is available on PyPi.

Install using pip.

pip install vt2pbf

Import vt2pbf

from vt2pbf import vt2pbf

Usage

Firstly you need to make a vector tile. You can do it by your own or use some libraries to convert, for example geojson into vector tiles using python port of geojson-vt library - geojson2vt

After you can easily encode your vector tile into pbf:

# build an initial index of tiles
tile_index = geojson2vt(geojson, {})

# request a particular tile
vector_tile = tile_index.get_tile(z, x, y)

# encode vector tile into pbf
pbf = vt2pbf(vector_tile)
print(pbf) # b'\x1a\xfb\x01\n\x0cgeojsonLayer\...'

vt2pbf takes two additional arguments:

  • layer_name is a name of encoded layer, default='geojsonLayer',
  • extend is definition of the extent of the tile, default=4096

Additional usage

You also can encode any custom information in pbf by Mapbox vector tiles spec

from vt2pbf import Tile


tile = Tile(extend=extend)
tile.add_layer(layer_name, features=features)  # features in vector_tile format (close to vector_tile['features'])
tile.add_layer(other_layer_name, features=features)
pbf_string = tile.serialize_to_bytestring()
print(pbf_string) # b'\x1a\xfb\x01\n\x0cgeojsonLayer\...'

In addition you can parse encoded data from bytestring using:

from vt2pbf import parse_from_string

pbf_string = b'\x1a\xfb\x01\n\x0cgeojsonLayer\...'
tile = parse_from_string(pbf_string)
print(tile.tile_pbf)
# layers {
#   name: "geojsonLayer"
#   features {
#     tags: 0
#     ...

Right now you cannot add some additional layers or info to parsed tile, but it will be available in future

Acknowledgements

All the credit of tile encoding belongs to the collaborators of JS vt-pbf.

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

vt2pbf-0.2.0.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

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

vt2pbf-0.2.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file vt2pbf-0.2.0.tar.gz.

File metadata

  • Download URL: vt2pbf-0.2.0.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vt2pbf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eaa5cfb25c981b902e8a88f2cac85c0f64ba352415b5af6933386a5707c9b9ad
MD5 a47c57f4330f4a1813e70f2483545d25
BLAKE2b-256 686292d46b1fd3110e77d8f46410e9e138febe0da511e5dc1d65be7cf60e0d22

See more details on using hashes here.

Provenance

The following attestation bundles were made for vt2pbf-0.2.0.tar.gz:

Publisher: publish.yml on DenysMoskalenko/vt2pbf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vt2pbf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: vt2pbf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vt2pbf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79a2301ef849f82a24275d33f6e8fd265345d09ab92e54682cfe161b55fffe00
MD5 33e3b030dcc7116e31dd5f7825c59ca3
BLAKE2b-256 bc98e27d76a1f5120f705bfb2c7dbc5c8cb0f0226c712933e02976150f4c7d3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for vt2pbf-0.2.0-py3-none-any.whl:

Publisher: publish.yml on DenysMoskalenko/vt2pbf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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