tileutils

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package tileutils provides types and functions for working with slippy map tiles, MBTiles, and TileJSON

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMetadataJSON

func CreateMetadataJSON(tj *TileJSON) *mbtiles.MetadataJson

CreateMetadataJSON generates a mbtiles MetadataJson object based on the TileJSON input

func Gzip

func Gzip(data []byte) ([]byte, error)

Gzip is a utility function to zip up a tile for storage

func ParseTileJSON

func ParseTileJSON(filename string) (*TileJSON, ZoomLayerInfo, error)

func RoundRobinTiles

func RoundRobinTiles(input []TileCoords, numWorkers int) [][]TileCoords

RoundRobinTiles assigns tiles to workers in round robin fashion

Types

type BoundingBox

type BoundingBox struct {
	Left   float64
	Right  float64
	Top    float64
	Bottom float64
}

BoundingBox is a lat/lon set of coordinates for a bounding box

type CreateMetadataOptions

type CreateMetadataOptions struct {
	Filename string
	Version  string
	Format   MbTilesFormat
}

type DummyWriter

type DummyWriter struct{}

DummyWriter doesn't do anything. It outputs info about the tile to be written to stdout. It doesn't actually write any tiles.

func (*DummyWriter) New

func (fw *DummyWriter) New() (TileWriter, func(), error)

func (*DummyWriter) Write

func (fw *DummyWriter) Write(z, x, y int, tileData []byte) error

type FileWriter

type FileWriter struct {
	Path string
}

FileWriter writes tiles out to a directory structure. The directories are organized under the Path provided, like Path/{z}/{x}/{y}.mvt

func (*FileWriter) New

func (fw *FileWriter) New() (TileWriter, func(), error)

func (*FileWriter) Write

func (fw *FileWriter) Write(z, x, y int, tileData []byte) error

type MbTilesFormat

type MbTilesFormat string
const (
	MbTilesFormatPbf  MbTilesFormat = "pbf"
	MbTilesFormatJpg  MbTilesFormat = "jpg"
	MbTilesFormatPng  MbTilesFormat = "png"
	MbTilesFormatWebP MbTilesFormat = "webp"
)

type MbTilesMetadata

type MbTilesMetadata map[string]string

func CreateMetadata

func CreateMetadata(tj *TileJSON, opts CreateMetadataOptions) MbTilesMetadata

CreateMetadata generates the (name,value) metadata pairs for .mbtiles files. Since name is required, it falls back to the filename if not provided. format is also required, so it falls back to pbf if not provided.

type MbTilesWriter

type MbTilesWriter struct {
	Filename string
	Writer   *mbtiles.Writer
}

MbTilesWriter outputs tiles to a mbtiles file.

Parameters:

  • Filename: the output file to be written
  • Writer: an instance of mbtiles.Writer to be used when writing the tiles

func (*MbTilesWriter) BulkWrite

func (w *MbTilesWriter) BulkWrite(data []mbtiles.TileData) error

func (*MbTilesWriter) BulkWriteMetadata

func (w *MbTilesWriter) BulkWriteMetadata(meta MbTilesMetadata) error

func (*MbTilesWriter) New

func (w *MbTilesWriter) New() (TileWriter, func(), error)

func (*MbTilesWriter) Write

func (w *MbTilesWriter) Write(z, x, y int, tileData []byte) error

func (*MbTilesWriter) WriteMetadata

func (w *MbTilesWriter) WriteMetadata(name, value string) error

type TileBulkWriter

type TileBulkWriter interface {
	// BulkWrite commits a slice of tiles
	BulkWrite(data []mbtiles.TileData) error
}

TileBulkWriter extends the TileWriter interface to include the ability to write out tiles in bulk

type TileCoords

type TileCoords struct {
	Z int
	X int
	Y int
}

func ListTiles

func ListTiles(zooms []int, tj *TileJSON) []TileCoords

ListTiles returns a list of all the tiles within the given zooms based on the TileJSON

func TilesFromFile

func TilesFromFile(filename string) ([]TileCoords, error)

TilesFromFile reads the tile coordinates to generate from a file

type TileJSON

type TileJSON struct {
	Attribution  string        `json:"attribution,omitempty"`
	Name         string        `json:"name"`
	Description  string        `json:"description"`
	Version      string        `json:"version,omitempty"`
	MinZoom      int           `json:"minzoom"`
	MaxZoom      int           `json:"maxzoom"`
	Bounds       []float64     `json:"bounds,omitempty"`
	Center       []float64     `json:"center,omitempty"`
	VectorLayers []VectorLayer `json:"vector_layers"`
}

type TileWriter

type TileWriter interface {
	// New creates a new TileWriter for this type
	New() (TileWriter, func(), error)
	// Write commits a tile with tileData at the Z/X/Y coordinate
	Write(z, x, y int, tileData []byte) error
}

TileWriter abstracts how to write out tiles, allowing for different formats and implementations

type VectorLayer

type VectorLayer struct {
	ID      string        `json:"id"`
	Queries []VectorQuery `json:"queries"`
}

type VectorQuery

type VectorQuery struct {
	MinZoom int    `json:"minzoom"`
	MaxZoom int    `json:"maxzoom"`
	SQL     string `json:"sql"`
}

type ZoomLayerInfo

type ZoomLayerInfo map[int]map[string][]string

ZoomLayerInfo is a mapped index of queries at each zoom. map[int] where int is the zoom level. map[string][]string where string1 is the layer name/id and []string is the list of queries.

Jump to

Keyboard shortcuts

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