- Notifications
You must be signed in to change notification settings - Fork7
Python utilities for Mapbox mbtiles files
License
consbio/pymbtiles
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Python 2.7 and 3 library for working withMabox mbtiles v1.1
Provides a lighweight Python API for reading and writing mbtiles files.
Mabox mbtiles v1.1 allow you to store geographic data as rendered image tiles or as vector tiles, along with associated metadata.
pip install pymbtiles
To install from master branch on GitHub using pip:
pip install git+https://github.com/consbio/pymbtiles.git#egg=pymbtiles --upgrade
open for reading and read a tile:
from pymbtiles import MBtileswith MBtiles('my.mbtiles') as src: tile_data = src.read_tile(z=0, x=0, y=0)
returns tile data in bytes.
open for writing (existing file will be overwritten):
with MBtiles('my.mbtiles', mode='w') as out: out.write_tile(z=0, x=0, y=0, tile_data)
or write a bunch of tiles at once:
from pymbtiles import MBtiles, Tiletiles = ( Tile(z=1, x=0, y=0, tile_data=first_tile), ...)with MBtiles('my.mbtiles', mode='w') as out: out.write_tiles(tiles)
User+
mode to read and write.
Metadata is stored in themeta
attribute of the mbtiles instance:
with MBtiles('my.mbtiles') as src: metadata = src.meta
This metadata is stored in themetadata
table in the mbtiles file, and containsa number of records required or optional under thembtiles specification .
To update metadata:
with MBtiles('my.mbtiles', 'r+') as out: out.meta['some_key'] = 'some_value'
You can set several values at once by passing in a newdict
object:
with MBtiles('my.mbtiles', 'w') as out: out.meta = my_metadata_dict
To list available tiles in the tileset:
with MBtiles('my.mbtiles') as src: for tile_coords in src.list_tiles(): # [TileCoordinate(z, x, y)...] ...
WARNING: for large tilesets, this can exceed available memory.
To list available tilesets for large tilesets, use:
with MBtiles('my.mbtiles') as src: for batch in src.list_tiles_batched(): for tile_coords in batch: # [TileCoordinate(z, x, y)...] ...
Theops
module providesextend
,union
, anddifference
functions to perform set operations on tilesets.
Extend a tileset with new tiles from a second:
extend(source_filename, target_filename)
Create a new tileset with unique tiles combined from both left and right tilesets:
union(left_filename, right_filename, out_filename)
Create a new tileset from the tileset in the left tileset not present in the right tileset:
difference(left_filename, right_filename, out_filename)
Tiles are output to mbtiles format in xyz tile scheme.
mbtileserver
: a lightweight Go tile servertpkutils
: a library for converting ArcGIS tile cache to mbtiles
- added
zoom_range
,row_range
,col_range
to provide basic information about tiles available in the tileset
- added
list_tiles
to list tiles andlist_tiles_batch
to list tiles in batches - added
ops
module withextend
,union
,difference
functions
- all write-like operations for metadata and tiles are now overwrite by default
Inspired by:
SQL for creating mbtiles database derived fromnode-mbtiles
See LICENSE.md
About
Python utilities for Mapbox mbtiles files