Skip to main content

MapBox Mbtiles Utilities

Project description

Mapbox MBtiles Utilities

A Python 2.7 and 3 library for working with Mabox mbtiles v1.1

Build Status Coverage Status

Features

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.

Installation

pip install pymbtiles

To install from master branch on GitHub using pip:

pip install git+https://github.com/consbio/pymbtiles.git#egg=pymbtiles --upgrade

Usage

Python API

open for reading and read a tile:

from pymbtiles import MBTiles
with 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, Tile

tiles = (
    Tile(z=1, x=0, y=0, tile_data=first_tile),
    ...
)

with MBtiles('my.mbtiles', mode='w') as out:
    out.write_tiles(tiles)

Use r+ mode to read and write.

Metadata is stored in the meta attribute of the mbtiles instance:

with MBtiles('my.mbtiles') as src:
    metadata = src.meta

This metadata is stored in the metadata table in the mbtiles file, and contains a number of records required or optional under the mbtiles 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 new dict object:

with MBtiles('my.mbtiles', 'w') as out:
    out.meta = my_metadata_dict

Note:

  • tiles are output to mbtiles format in xyz tile scheme.

Possibly useful:

  • mbtileserver: a lightweight Go tile server
  • tpkutils: a library for converting ArcGIS tile cache to mbtiles

Changes :

0.3.0

  • all write-like operations for metadata and tiles are now overwrite by default

Credits:

Inspired by:

SQL for creating mbtiles database derived from node-mbtiles

License:

See LICENSE.md

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

pymbtiles-0.3.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

pymbtiles-0.3.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pymbtiles-0.3.1.tar.gz.

File metadata

  • Download URL: pymbtiles-0.3.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pymbtiles-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cdd517f2f42177197e6ad3e25d69a37d6269e2fca64e64adaf1ba6da1c73a1c4
MD5 3c00492628e8e500e791b8d9594ebb5f
BLAKE2b-256 3873f174cec456d69d79997928cc50bc414833375a5471113d27f65d6dc1a006

See more details on using hashes here.

Provenance

File details

Details for the file pymbtiles-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pymbtiles-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pymbtiles-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 309487de7fcb5d217067cac296c3e3812020aa133f43a34ed1d8d293dfee0b64
MD5 b6e43abdd18b80ee7ecf8c5252f81098
BLAKE2b-256 0ab47df5aa849a3c41115cd78e1633c4a91add6e5f3981572019939a53f96f57

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page