mbtiles

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package mbtiles contains some code parts borrowed from github.com/consbio/mbtileserver which is released under ISC.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTileFormat        = errors.New("invalid or unknown tile format")
	ErrUnknownTileFormatPattern = errors.New("unknown tile format pattern")
	ErrInvalidLayerType         = errors.New("invalid or unknown layer type")
	ErrTilesetNotFound          = errors.New("tileset not found")
	ErrTileNotFound             = errors.New("tile not found")
	ErrNoUTFGrid                = errors.New("tileset does not contain UTF grids")
	ErrInvalidTileCoord         = errors.New("tile coordinates are not valid")
)

Functions

func LoadTilesets

func LoadTilesets(path string) error

LoadTilesets creates a Tileset of all MBTiles in the specified directory and adds them to the internal map

Types

type Attribute

type Attribute struct {
	Name   string        `json:"attribute"`
	Count  int           `json:"count"`
	Type   string        `json:"type"`
	Values []interface{} `json:"values"`
}

type Layer

type Layer struct {
	Name           string      `json:"layer"`
	Count          int64       `json:"count"`
	Geometry       string      `json:"geometry"`
	AttributeCount int         `json:"attributeCount"`
	Attributes     []Attribute `json:"attributes,omitempty"`
}

type LayerData

type LayerData struct {
	VectorLayers *[]VectorLayer `json:"vector_layers,omitempty"`
	TileStats    *TileStats     `json:"tilestats,omitempty"`
}

type LayerType

type LayerType int

LayerType represents the MBTiles layer type

const (
	BaseLayer LayerType = iota
	Overlay
)

func (*LayerType) MarshalJSON

func (t *LayerType) MarshalJSON() ([]byte, error)

func (LayerType) String

func (t LayerType) String() string

String returns a string representing the LayerType

func (*LayerType) UnmarshalJSON

func (t *LayerType) UnmarshalJSON(b []byte) error

type Metadata

type Metadata struct {
	Name        string     `json:"name"`
	Format      TileFormat `json:"format"`
	Bounds      [4]float64 `json:"bounds,omitempty"`
	Center      [3]float64 `json:"center,omitempty"`
	MinZoom     int        `json:"minzoom,omitempty"`
	MaxZoom     int        `json:"maxzoom,omitempty"`
	Description string     `json:"description,omitempty"`
	Version     string     `json:"version,omitempty"`
	Type        LayerType  `json:"type,omitempty"`
	Attribution string     `json:"attribution,omitempty"`
	LayerData   *LayerData `json:"layerData,omitempty"`
}

type TileCoord

type TileCoord struct {
	Z    uint8
	X, Y uint64
}

func ParseTileCoord

func ParseTileCoord(z, x, y string) (tc *TileCoord, err error)

ParseTileCoord parses and returns TileCoord coordinates and an optional extension from the three parameters. The parameter z is interpreted as the web mercator zoom level, it is supposed to be an unsigned integer that will fit into 8 bit. The parameters x and y are interpreted as longitude and latitude tile indices for that zoom level, both are supposed be integers in the integer interval [0,2^z). Additionally, y may also have an optional filename extension (e.g. "42.png") which is removed before parsing the number, and returned, too. In case an error occured during parsing or if the values are not in the expected interval, the returned error is non-nil.

type TileFormat

type TileFormat int

TileFormat represents the format of a tile

const (
	UNKNOWN TileFormat = iota
	PBF
	PNG
	JPG
	WEBP
	GZIP
	ZLIB
)

func (TileFormat) ContentType

func (f TileFormat) ContentType() string

ContentType returns the MIME content type of the TileFormat

func (*TileFormat) MarshalJSON

func (f *TileFormat) MarshalJSON() ([]byte, error)

func (TileFormat) String

func (f TileFormat) String() string

String returns a string representing the TileFormat

func (*TileFormat) UnmarshalJSON

func (f *TileFormat) UnmarshalJSON(b []byte) error

type TileStats

type TileStats struct {
	LayerCount int     `json:"layerCount"`
	Layers     []Layer `json:"layers"`
}

type Tileset

type Tileset struct {
	Filename           string
	Format             TileFormat
	Timestamp          time.Time
	UTFGrid            bool
	UTFGridCompression TileFormat
	// contains filtered or unexported fields
}

Tileset represents an MBTiles instance

func GetTileset

func GetTileset(id string) (*Tileset, error)

GetTileset returns a Tileset by the given ID

func NewTileset

func NewTileset(file string) (*Tileset, error)

NewTileset creates a new Tileset by the given MBTiles file

func (*Tileset) Close

func (ts *Tileset) Close() error

Close closes the database connection of the Tileset

func (*Tileset) ContentType

func (ts *Tileset) ContentType() string

ContentType returns the content-type string of the TileFormat of the Tileset.

func (*Tileset) GetGrid

func (ts *Tileset) GetGrid(tc *TileCoord) ([]byte, error)

GetGrid reads a UTFGrid with identifiers z, x, y into []byte. This merges in grid key data. The data is returned in the original compression encoding (zlib or gzip)

func (*Tileset) GetMetadata

func (ts *Tileset) GetMetadata() (*Metadata, error)

GetMetadata reads the metadata table into Metadata, casting their values into the appropriate type

func (*Tileset) GetTile

func (ts *Tileset) GetTile(tc *TileCoord) ([]byte, error)

GetTile reads a tile with tile identifiers z, x, y into []byte.

type VectorLayer

type VectorLayer struct {
	ID          string                 `json:"id"`
	Fields      map[string]interface{} `json:"fields"`
	Description string                 `json:"description,omitempty"`
	MinZoom     int                    `json:"minzoom,omitempty"`
	MaxZoom     int                    `json:"maxzoom,omitempty"`
}

Jump to

Keyboard shortcuts

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