{"id":13784383,"url":"https://github.com/DenysMoskalenko/vt2pbf","last_synced_at":"2025-05-11T19:32:53.237Z","repository":{"id":57663608,"uuid":"479349337","full_name":"DenysMoskalenko/vt2pbf","owner":"DenysMoskalenko","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-16T09:01:05.000Z","size":30,"stargazers_count":14,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-09T13:47:22.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DenysMoskalenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-08T10:39:36.000Z","updated_at":"2024-07-23T02:51:18.000Z","dependencies_parsed_at":"2023-02-10T02:15:53.723Z","dependency_job_id":null,"html_url":"https://github.com/DenysMoskalenko/vt2pbf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DenysMoskalenko%2Fvt2pbf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DenysMoskalenko%2Fvt2pbf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DenysMoskalenko%2Fvt2pbf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DenysMoskalenko%2Fvt2pbf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DenysMoskalenko","download_url":"https://codeload.github.com/DenysMoskalenko/vt2pbf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225086610,"owners_count":17418763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T19:00:41.759Z","updated_at":"2024-11-17T20:31:52.609Z","avatar_url":"https://github.com/DenysMoskalenko.png","language":"Python","funding_links":[],"categories":["Parsers \u0026 Generators"],"sub_categories":[],"readme":"# vt2pbf\nPython port of [JS vt-pbf](https://github.com/mapbox/vt-pbf) to Encode [Mapbox vector tiles](https://github.com/mapbox/vector-tile-spec) to binary protobufs in python.\nRight now available only version 2 of mapbox vector tiles spec\n\n### Install\n`vt2pbf` is available on [PyPi](https://pypi.org/project/vt2pbf/).  \n\nInstall using pip.\n```bash\npip install vt2pbf\n```\n\nImport `vt2pbf`\n```python\nfrom vt2pbf import vt2pbf\n```\n\n### Usage\nFirstly you need to make a vector tile. You can do it by your own or use some libraries to convert,\nfor example geojson into vector tiles using python port of [geojson-vt](https://github.com/mapbox/geojson-vt)\nlibrary - [geojson2vt](https://github.com/geometalab/geojson2vt)\n\nAfter you can easily encode your vector tile into pbf:\n```python\n# build an initial index of tiles\ntile_index = geojson2vt(geojson, {})\n\n# request a particular tile\nvector_tile = tile_index.get_tile(z, x, y)\n\n# encode vector tile into pbf\npbf = vt2pbf(vector_tile)\nprint(pbf) # b'\\x1a\\xfb\\x01\\n\\x0cgeojsonLayer\\...'\n```\n\n`vt2pbf` takes two additional arguments:\n- `layer_name` is a name of encoded layer, `default='geojsonLayer'`,\n- `extend` is definition of the extent of the tile, `default=4096`\n\n### Additional usage\nYou also can encode  any custom information in pbf by [Mapbox vector tiles spec](https://github.com/mapbox/vector-tile-spec)\n```python\nfrom vt2pbf import Tile\n\n\ntile = Tile(extend=extend)\ntile.add_layer(layer_name, features=features)  # features in vector_tile format (close to vector_tile['features'])\ntile.add_layer(other_layer_name, features=features)\npbf_string = tile.serialize_to_bytestring()\nprint(pbf_string) # b'\\x1a\\xfb\\x01\\n\\x0cgeojsonLayer\\...'\n```\n\nIn addition you can parse encoded data from bytestring using:\n```python\nfrom vt2pbf import parse_from_string\n\npbf_string = b'\\x1a\\xfb\\x01\\n\\x0cgeojsonLayer\\...'\ntile = parse_from_string(pbf_string)\nprint(tile.tile_pbf)\n# layers {\n#   name: \"geojsonLayer\"\n#   features {\n#     tags: 0\n#     ...\n```\nRight now you cannot add some additional layers or info to parsed tile, but it will be available in future\n\n\n## Acknowledgements\nAll the credit of tile encoding belongs to the collaborators of [JS vt-pbf](https://github.com/mapbox/vt-pbf).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDenysMoskalenko%2Fvt2pbf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDenysMoskalenko%2Fvt2pbf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDenysMoskalenko%2Fvt2pbf/lists"}