Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geometalab/geojson2vt
Converts GeoJSON to vector tiles :scissors: :earth_americas:
https://github.com/geometalab/geojson2vt
Last synced: 25 days ago
JSON representation
Converts GeoJSON to vector tiles :scissors: :earth_americas:
- Host: GitHub
- URL: https://github.com/geometalab/geojson2vt
- Owner: geometalab
- License: isc
- Created: 2020-04-08T10:48:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T19:48:10.000Z (over 3 years ago)
- Last Synced: 2024-09-17T14:09:40.280Z (3 months ago)
- Language: Python
- Homepage:
- Size: 280 KB
- Stars: 44
- Watchers: 8
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-vector-tiles - geojson2vt - Python port of [geojson-vt](https://github.com/mapbox/geojson-vt) to convert GeoJSON into vector tiles. (Parsers & Generators)
README
[![Build Status](https://travis-ci.org/geometalab/geojson2vt.svg?branch=master)](https://travis-ci.org/geometalab/geojson2vt)
# geojson2vt
Python port of [JS GeoJSON-VT](https://github.com/mapbox/geojson-vt) to convert GeoJSON into vector tiles. :scissors: :earth_americas:Further, it provides the ability to convert the generate vector tiles to separate GeoJSONs (`vt2geojson`).
### Usage
#### geojson2vt
```python
# build an initial index of tiles
tile_index = geojson2vt(geojson, {})# request a particular tile
features = tile_index.get_tile(z, x, y).get('features')# show an array of tile coordinates created so far
print(tile_index.tile_coords) # [{'z': 0, 'x': 0, 'y': 0}, ...]
```##### Options
You can fine-tune the results with an options object,
although the defaults are sensible and work well for most use cases.```python
tile_index = geojson2vt(data, {
'maxZoom': 14, # max zoom to preserve detail on; can't be higher than 24
'tolerance': 3, # simplification tolerance (higher means simpler)
'extent': 4096, # tile extent (both width and height)
'buffer': 64, # tile buffer on each side
'lineMetrics': False, # whether to enable line metrics tracking for LineString/MultiLineString features
'promoteId': None, # name of a feature property to promote to feature.id. Cannot be used with `generateId`
'generateId': False, # whether to generate feature ids. Cannot be used with `promoteId`
'indexMaxZoom': 5, # max zoom in the initial tile index
'indexMaxPoints': 100000 # max number of points per tile in the index
}, logging.INFO)
```By default, tiles at zoom levels above `indexMaxZoom` are generated on the fly, but you can pre-generate all possible tiles for `data` by setting `indexMaxZoom` and `maxZoom` to the same value, setting `indexMaxPoints` to `0`, and then accessing the resulting tile coordinates from the `tile_coords` property of `tile_index`.
The `promoteId` and `generateId` options ignore existing `id` values on the feature objects.
geojson2vt only operates on zoom levels up to 24.
#### vt2geojson
```python
# build an initial index of tiles
tile_index = geojson2vt(geojson_data, {})# get a specific tile
vector_tile = tile_index.get_tile(z, x, y)# convert a specific vector tile to GeoJSON
geojson = vt2geojson(vector_tile)
```### Install
`geojson2vt` is available on [PyPi](https://pypi.org/project/geojson2vt/).
Install using pip.
```bash
pip install geojson2vt
```Import `geojson2vt`
```python
from geojson2vt.geojson2vt import geojson2vt
```## Acknowledgements
All the credit belongs to the collaborators of [JS GeoJSON-VT](https://github.com/mapbox/geojson-vt).## Notes
Currently, geojson2vt isn't written in a very pythonic way. This is due to the fact of the port from geojson-vt.
Further development could lead to a more pythonic maner for a more seamless Python usage. :snake: