mbtiles

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 14 Imported by: 4

README

MBTiles Reader for Go

A simple Go-based mbtiles reader.

Build Status Coverage Status GoDoc Go Report Card

Supports JPG, PNG, WebP, and vector tile tilesets created according to the mbtiles specification.

Example:

// Open an mbtiles file
db, err := mbtiles.Open("testdata/geography-class-jpg.mbtiles")
if err != nil { ... }
defer db.Close()

// read a tile into a byte slice
var data []byte
err = db.ReadTile(0, 0, 0, &data)
if err != nil { ... }

Credits:

This was adapted from the mbtiles package in mbtileserver to use the crawshaw.io/sqlite SQLite library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMBtiles

func FindMBtiles(path string) ([]string, error)

FindMBtiles recursively finds all mbtiles files within a given path.

Types

type MBtiles

type MBtiles struct {
	// contains filtered or unexported fields
}

MBtiles provides a basic handle for an mbtiles file.

func Open

func Open(path string) (*MBtiles, error)

Open opens an MBtiles file for reading, and validates that it has the correct structure.

func (*MBtiles) Close

func (db *MBtiles) Close()

Close closes a MBtiles file

func (*MBtiles) GetFilename

func (db *MBtiles) GetFilename() string

func (*MBtiles) GetTileFormat

func (db *MBtiles) GetTileFormat() TileFormat

GetTileFormat returns the TileFormat of the mbtiles file.

func (*MBtiles) GetTileSize added in v0.2.0

func (db *MBtiles) GetTileSize() uint32

GetTileSize returns the tile size in pixels of the mbtiles file, if detected. Returns 0 if tile size is not detected.

func (*MBtiles) GetTimestamp

func (db *MBtiles) GetTimestamp() time.Time

Timestamp returns the time stamp of the mbtiles file.

func (*MBtiles) ReadMetadata

func (db *MBtiles) ReadMetadata() (map[string]interface{}, error)

ReadMetadata reads the metadata table into a map, casting their values into the appropriate type

func (*MBtiles) ReadTile

func (db *MBtiles) ReadTile(z int64, x int64, y int64, data *[]byte) error

ReadTile reads a tile for z, x, y into the provided *[]byte. data will be nil if the tile does not exist in the database

type TileFormat

type TileFormat uint8

TileFormat defines the tile format of tiles an mbtiles file. Supported image formats:

  • PNG
  • JPG
  • WEBP
  • PBF (vector tile protocol buffers)

Tiles may be compressed, in which case the type is one of:

  • GZIP (assumed to be GZIP'd PBF data)
  • ZLIB
const (
	UNKNOWN TileFormat = iota // UNKNOWN TileFormat cannot be determined from first few bytes of tile
	GZIP                      // encoding = gzip
	ZLIB                      // encoding = deflate
	PNG
	JPG
	PBF
	WEBP
)

TileFormat enum values

func (TileFormat) MimeType

func (t TileFormat) MimeType() string

MimeType returns the MIME content type for the TileFormat

func (TileFormat) String

func (t TileFormat) String() string

String returns a string representing the TileFormat.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL