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_nameis a name of encoded layer,default='geojsonLayer',extendis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vt2pbf-0.2.1.tar.gz.
File metadata
- Download URL: vt2pbf-0.2.1.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdd11440d2ca818c95ac367c6f8b4e8bd1000222a26d795b414b3aa42de6a499
|
|
| MD5 |
f30f08ea2dbde04e8373c21a03977582
|
|
| BLAKE2b-256 |
2305e90b6d95610262ac6fd7aa8f1e4335df2cde3fa43b297b49929280795e98
|
Provenance
The following attestation bundles were made for vt2pbf-0.2.1.tar.gz:
Publisher:
publish.yml on DenysMoskalenko/vt2pbf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vt2pbf-0.2.1.tar.gz -
Subject digest:
bdd11440d2ca818c95ac367c6f8b4e8bd1000222a26d795b414b3aa42de6a499 - Sigstore transparency entry: 648642274
- Sigstore integration time:
-
Permalink:
DenysMoskalenko/vt2pbf@9b8e3a508add3986907379837416c0c5370f61c6 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/DenysMoskalenko
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b8e3a508add3986907379837416c0c5370f61c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file vt2pbf-0.2.1-py3-none-any.whl.
File metadata
- Download URL: vt2pbf-0.2.1-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a29431d7f307f49753c6509ef20fc9b037289e29c8ad32c65626612680687124
|
|
| MD5 |
6c5b45c400f44e0f5466023b05f578af
|
|
| BLAKE2b-256 |
8a6d6ed21b200eb94628944e60dd2dccee3a0578f09fb82bd238f3fa35a72acc
|
Provenance
The following attestation bundles were made for vt2pbf-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on DenysMoskalenko/vt2pbf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vt2pbf-0.2.1-py3-none-any.whl -
Subject digest:
a29431d7f307f49753c6509ef20fc9b037289e29c8ad32c65626612680687124 - Sigstore transparency entry: 648642297
- Sigstore integration time:
-
Permalink:
DenysMoskalenko/vt2pbf@9b8e3a508add3986907379837416c0c5370f61c6 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/DenysMoskalenko
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b8e3a508add3986907379837416c0c5370f61c6 -
Trigger Event:
push
-
Statement type: