mbtiles

package
v0.0.0-...-4d82cb5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UNKNOWN = iota
	GZIP
	ZLIB
	PNG
	JPG
	WEBP
)

List of possible formats

Variables

View Source
var ErrEmptyTileData = errors.New("tile is empty")

ErrEmptyTileData error

View Source
var ErrUnknownTileFormat = errors.New("could not detect tile format")

ErrUnknownTileFormat an error of unknown tile format

View Source
var TypeFormatPatterns = map[TileFormat][]byte{
	GZIP: []byte("\x1f\x8b"),
	ZLIB: []byte("\x78\x9c"),
	PNG:  []byte("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"),
	JPG:  []byte("\xFF\xD8\xFF"),
	WEBP: []byte("\x52\x49\x46\x46"),
}

TypeFormatPatterns of any possible tile

Functions

func ConvertMVTLayerToFeatureCollection

func ConvertMVTLayerToFeatureCollection(layer *mvt.Layer) *geojson.FeatureCollection

ConvertMVTLayerToFeatureCollection to be exported as GeoJSON

func ExportGeoJSON

func ExportGeoJSON(layer *mvt.Layer) error

ExportGeoJSON layer

Types

type Exporter

type Exporter struct {
	Manager

	TilesCount int
	// contains filtered or unexported fields
}

Exporter of mbtiles

func NewExporter

func NewExporter(importPath string, settings ExporterSettings) (*Exporter, error)

NewExporter creates a new sitemap exporter.

func (*Exporter) Export

func (ex *Exporter) Export() error

Export tiles

func (*Exporter) GetMeta

func (ex *Exporter) GetMeta() (*Meta, error)

GetMeta data from database file

type ExporterSettings

type ExporterSettings struct {
	Path       string
	Decompress bool
	BaseUrl    string
}

ExporterSettings groups all cfg for NewExporter

type Manager

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

func NewManager

func NewManager(path string) (*Manager, error)

func (*Manager) GetTile

func (m *Manager) GetTile(z int64, x int64, y int64) ([]byte, error)

GetTile data only a pbf image

func (*Manager) GetTiles

func (m *Manager) GetTiles() ([]*Tile, error)

GetTiles list

func (*Manager) Search

func (m *Manager) Search(query string, maxResults int) ([]*geojson.Feature, error)

Search features where subject has a query

func (*Manager) WalkThroughLayers

func (m *Manager) WalkThroughLayers(callback func(layer *mvt.Layer) bool, zoomLevel int) error

WalkThroughLayers and decode tile by the way

func (*Manager) WalkThroughPlaces

func (m *Manager) WalkThroughPlaces(callback func(subj string, cls string, feature *geojson.Feature) bool) error

WalkThroughPlaces and call callback if something was found

func (*Manager) WalkThroughTiles

func (m *Manager) WalkThroughTiles(callback func(tile *Tile) bool, zoom int) error

WalkThroughTiles and call back by each tile

type Meta

type Meta struct {
	// The human-readable name of the tile set.
	Name string `json:"name,omitempty"`

	// Tile set big description
	Description string `json:"description,omitempty"`

	// Tile set file name or relative path to the file.
	Basename string `json:"basename,omitempty"`

	// Tile set version.
	Version string `json:"version,omitempty"`

	// The file format of the tile data: `pbf`, `jpg`, `png`, `webp`, or an IETF media type for other formats.
	// `pbf` as a format refers to gzip-compressed vector tile data in Mapbox Vector Tile format.
	Format string `json:"format,omitempty"`

	// ???
	Type string `json:"type,omitempty"`

	// ???
	Scale int `json:"scale,omitempty"`

	// The lowest zoom level for which the tile set provides data
	MinZoom int `json:"minzoom,omitempty"`

	// The highest zoom level for which the tileset provides data
	MaxZoom int `json:"maxzoom,omitempty"`

	// The longitude, latitude, and zoom level of the default view of the map.
	// Example: -122.1906,37.7599,11
	Center []float64 `json:"center,omitempty" mapstructure:"-"`

	// The maximum extent of the rendered map area.
	// Bounds must define an area covered by all zoom levels.
	// The bounds are represented as WGS 84 latitude and longitude values, in the OpenLayers Bounds format (left, bottom, right, top).
	// For example, the bounds of the full Earth, minus the poles, would be: -180.0,-85,180,85.
	Bounds []float64 `json:"bounds,omitempty" mapstructure:"-"`

	// The `JSON` object in the json row MUST contain a `vector_layers` key, whose value is an array of JSON objects.
	// Each of those JSON objects describes one layer of vector tile data, and MUST contain the following key-value pairs:
	VectorLayers []VectorLayer `json:"vector_layers,omitempty"`

	// ???
	Profile string `json:"profile,omitempty"`

	// PBF's URL template. Example: ["http://localhost/tiles/{z}/{x}/{y}.pbf"]
	Tiles []string `json:"tiles,omitempty"`

	// ???
	TileJson string `json:"tile-json,omitempty"`

	// Example: "xyz"
	Scheme string `json:"scheme,omitempty"`

	// Database raw json contains vector layer info
	// The JSON object in the json row MUST contain a vector_layers key, whose value is an array of JSON objects.
	// Each of those JSON objects describes one layer of vector tile data, and MUST contain the following key-value pairs:
	JSON string `json:"-" mapstructure:"-"`

	//  An attribution string, which explains in English (and HTML) the sources of data and/or style for the map.
	Attribution string `json:"attribution,omitempty"`
}

Meta of data. The metadata table MAY contain additional rows for tile sets that implement UTFGrid-based interaction or for other purposes. see: https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md

type Place

type Place struct {
	ID         interface{}
	Type       string
	Geometry   *orb.Geometry
	Properties *geojson.Properties

	Class     string `json:"class" mapstructure:"class"`
	NameLatin string `json:"name:latin" mapstructure:"name:latin"`
}

type Tile

type Tile struct {
	RowID     int    `db:"ROWID"`
	ZoomLevel int64  `db:"zoom_level" geo:"z"`
	Column    int64  `db:"tile_column" geo:"x"`
	Row       int64  `db:"tile_row" geo:"y"`
	Data      []byte `db:"tile_data"`

	// Internal Number
	Number int
}

Tile represents a tile from MB Tiles file

func (*Tile) DetectTileFormat

func (t *Tile) DetectTileFormat() (TileFormat, error)

DetectTileFormat by data prefix

func (*Tile) GetFileName

func (t *Tile) GetFileName() int64

GetFileName XYZtoEPSG

func (*Tile) GetFormat

func (t *Tile) GetFormat() (TileFormat, error)

GetFormat of a tile

func (*Tile) GetPath

func (t *Tile) GetPath() string

GetPath of tile

func (*Tile) GetProtobuf

func (t *Tile) GetProtobuf() ([]byte, error)

func (*Tile) IsEmpty

func (t *Tile) IsEmpty() bool

IsEmpty data?

type TileFormat

type TileFormat int

TileFormat of a tile

func DetectTileFormat

func DetectTileFormat(data []byte) (TileFormat, error)

DetectTileFormat by data slice

type VectorLayer

type VectorLayer struct {
	// The layer ID, which is referred to as the name of the layer in the Mapbox Vector Tile spec.
	ID string `json:"id,omitempty" `

	// The lowest zoom level for which the tile set provides data
	MinZoom int `json:"minzoom,omitempty"`

	// The highest zoom level for which the tileset provides data
	MaxZoom int `json:"maxzoom,omitempty"`

	Fields map[string]string `json:"fields,omitempty"`
}

VectorLayer for style

Jump to

Keyboard shortcuts

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