tileutils

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: BSD-3-Clause Imports: 14 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 BytesBufferPool added in v2.1.0

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

BytesBufferPool provides reusable buffers for a single worker (no synchronization needed)

func NewBytesBufferPool added in v2.1.0

func NewBytesBufferPool(maxPoolSize, maxBufferSize int) *BytesBufferPool

NewBytesBufferPool creates a new worker-local buffer pool

func (*BytesBufferPool) Get added in v2.1.0

func (p *BytesBufferPool) Get() *bytes.Buffer

Get returns a clean buffer from the pool or creates a new one

func (*BytesBufferPool) Put added in v2.1.0

func (p *BytesBufferPool) Put(buf *bytes.Buffer)

Put returns a buffer to the pool after resetting it

func (*BytesBufferPool) Stats added in v2.1.0

func (p *BytesBufferPool) Stats() PoolStats

Stats returns usage statistics for the pool

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 PoolStats added in v2.1.0

type PoolStats struct {
	Created    int64   // Total buffers created
	Reused     int64   // Total buffer reuses
	Active     int64   // Buffers currently in pool
	ReuseRatio float64 // Ratio of reused vs created
}

PoolStats contains buffer pool usage statistics

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 WorkerGzipCompressor added in v2.1.0

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

WorkerGzipCompressor provides optimized gzip compression using a worker-local buffer pool

func NewWorkerGzipCompressor added in v2.1.0

func NewWorkerGzipCompressor(level int) *WorkerGzipCompressor

NewWorkerGzipCompressor creates a new worker-local gzip compressor

func (*WorkerGzipCompressor) Compress added in v2.1.0

func (c *WorkerGzipCompressor) Compress(data []byte, buf *bytes.Buffer) (*bytes.Buffer, error)

Compress compresses data using the provided buffer and reused writer. Returns a buffer, which will almost certainly be the buffer provided as input.

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