Skip to main content

MapBox Mbtiles Utilities

Project description

A Python 3.x (only!) library for working with Mabox mbtiles v1.1

Build Status Coverage Status

Python 2.7.x is not supported at this time due to different sqlite3 API.

Goals

  • Provide a very lightweight API for reading / writing mbtiles files

Installation

For now, while this is under active development, install from master branch on GitHub using pip:

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

Once functionality stabilizes, it will be added to PyPi

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.

Credits:

Tile package format is described here.

Inspired by: * mbutil * node-mbtiles

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.1.0.tar.gz (5.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pymbtiles-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymbtiles-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ebc5985153f93638385104d6fe70250039e617e59e31fd19309b6a479b623400
MD5 725d7b16b2ff3119ab1a5afdbf12b49a
BLAKE2b-256 6381b0996ce2bf7f4ada1473395fed7481527b3d5b0479db6740012790697c6a

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