pm

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pm provides high-level API for reading and writing tiles, metadata and headers in PMTiles format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileAccessFunc

type FileAccessFunc func(offset, length uint64) ([]byte, error)

FileAccessFunc is a function to access file data (local or remote). It must ensure that there are no partial reads. TODO(eak1mov): specify behavior for zero-length reads

type HeaderMetadata

type HeaderMetadata struct {
	TileCompression spec.Compression
	TileType        spec.TileType
	MinZoom         uint8
	MaxZoom         uint8
	MinLonE7        int32
	MinLatE7        int32
	MaxLonE7        int32
	MaxLatE7        int32
	CenterZoom      uint8
	CenterLonE7     int32
	CenterLatE7     int32
}

func (*HeaderMetadata) CopyFromHeader

func (m *HeaderMetadata) CopyFromHeader(header *spec.Header)

func (*HeaderMetadata) CopyToHeader

func (m *HeaderMetadata) CopyToHeader(header *spec.Header)

type Reader

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

Reader implements tile.Reader and tile.LocationReader interfaces for PMTiles format.

func NewFileReader

func NewFileReader(filePath string) (*Reader, error)

NewFileReader opens a local PMTiles file and returns a Reader for it.

The returned Reader must be closed after use to release file resources.

func NewReader

func NewReader(fileAccess FileAccessFunc) (*Reader, error)

NewReader creates a Reader using a custom file access function. This is useful for remote or in-memory access.

func (*Reader) Close added in v0.2.0

func (r *Reader) Close() error

func (*Reader) HeaderMetadata

func (r *Reader) HeaderMetadata() HeaderMetadata

HeaderMetadata returns the metadata from the PMTiles header.

func (*Reader) ReadLocation

func (r *Reader) ReadLocation(tileID tile.ID) (tile.Location, error)

func (*Reader) ReadMetadata

func (r *Reader) ReadMetadata() ([]byte, error)

ReadMetadata reads and returns the raw metadata from the PMTiles file.

func (*Reader) ReadTile

func (r *Reader) ReadTile(tileID tile.ID) ([]byte, error)

ReadTile reads a single tile from the PMTiles file.

It returns the tile data or an error if the tile cannot be read. If the tile does not exist, it returns an empty slice with no error.

The caller is responsible for decompressing the data if needed (see TileCompression from HeaderMetadata).

func (*Reader) VisitLocations added in v0.2.0

func (r *Reader) VisitLocations(visitor func(tile.ID, tile.Location) error) error

func (*Reader) VisitTiles

func (r *Reader) VisitTiles(visitor func(tile.ID, []byte) error) error

type Writer

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

Writer implements tile.Writer interface for PMTiles format.

func NewWriter

func NewWriter(filePath string, opts ...WriterOption) (*Writer, error)

NewWriter creates a new Writer for writing to a PMTiles file. It always creates a new file and does not support appending to an existing one.

Finalize() must be called to complete writing. Failure to do so will result in a corrupted file.

On any error during writing, the file may be left in an invalid state. Close() should always be called to release file resources.

func (*Writer) Close added in v0.2.0

func (w *Writer) Close() error

func (*Writer) Finalize

func (w *Writer) Finalize() error

Finalize completes the writing process by flushing buffers, writing headers, and creating indexes. It must be called before Close.

After Finalize is called, WriteTile must not be called again. If Finalize returns an error, the output file may be left in a corrupted state.

func (*Writer) WriteTile

func (w *Writer) WriteTile(tileID tile.ID, tileData []byte) error

WriteTile writes a single tile to the PMTiles file.

The caller is responsible for compressing the data according to TileCompression.

type WriterOption added in v0.2.0

type WriterOption func(*writerConfig)

func WithHeaderMetadata added in v0.2.0

func WithHeaderMetadata(headerMetadata HeaderMetadata) WriterOption

func WithLogger added in v0.2.0

func WithLogger(logger *log.Logger) WriterOption

WithLogger sets custom logger, otherwise log messages are discarded.

func WithMetadata added in v0.2.0

func WithMetadata(metadata []byte) WriterOption

Directories

Path Synopsis
Package spec provides low-level implementation of the PMTiles v3 specification, including serialization/deserialization of headers and directories.
Package spec provides low-level implementation of the PMTiles v3 specification, including serialization/deserialization of headers and directories.

Jump to

Keyboard shortcuts

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