heightmap

package
v0.0.0-...-8fdb973 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const NoElevationData int16 = -32768

NoElevationData marks a Point.Elevation whose value could not be read (missing DEM file, coordinate outside coverage, decode error, etc). It reuses the void value SRTM HGT files already use for "no data" so it can never be confused with a valid elevation, including sea level (0).

Variables

View Source
var ErrTileNotCached = errors.New("tile is not cached")

ErrTileNotCached is returned by getTileFromDisk when the requested tile has not been generated yet, as opposed to some other read failure.

Functions

This section is empty.

Types

type Format

type Format string

Format is an output image encoding. The zero value is PNG, so callers that do not set a format keep the original behavior.

const (
	FormatPNG     Format = ""
	FormatJPEG    Format = "jpg"
	FormatTIFF    Format = "tiff"
	FormatGeoTIFF Format = "geotiff"
	// FormatPNG16 is a 16-bit grayscale PNG holding elevation in whole meters
	// (1 unit = 1 m). Negative elevations clamp to 0, no-data becomes 0.
	FormatPNG16 Format = "png16"
	// FormatDEM is a single-band Float32 GeoTIFF holding elevation in meters,
	// with no-data set to NoElevationData (-32768).
	FormatDEM Format = "dem"
)

func ParseFormat

func ParseFormat(s string) (Format, bool)

ParseFormat maps a file extension (with or without a leading dot) or a format name to a Format. Returns false for unsupported values.

func (Format) ContentType

func (f Format) ContentType() string

ContentType returns the HTTP media type.

func (Format) Extension

func (f Format) Extension() string

Extension returns the file extension, without dot.

func (Format) IsElevation

func (f Format) IsElevation() bool

IsElevation reports whether the format encodes elevation values instead of the colored gradient image.

type Generator

type Generator struct {
	ElevationDataset *hgt.DataDir
	SrtmDownloader   *srtm.Downloader
	Dir              string
	// contains filtered or unexported fields
}

Generator HeightmapGenerator Generate heightmaps based on a digital elevation model (DEM) dataset

func (*Generator) CreateHeightMapImage

func (t *Generator) CreateHeightMapImage(ctx context.Context, lat, lon float64, side float64,
	conf ResolutionConfig) ([]byte, error)

func (*Generator) GenerateAllTilesInZoomLevel

func (t *Generator) GenerateAllTilesInZoomLevel(ctx context.Context, zoomLevel int) (TileGenerationResult, error)

GenerateAllTilesInZoomLevel generates every tile of an OSM zoom level. Tiles are enumerated and dispatched incrementally, bounded by maxConcurrentTileGeneration in-flight goroutines at a time, instead of materializing all 4^zoomLevel tiles in memory up front. A single tile's failure is logged, counted in the returned result, and does not abort the rest of the batch. The returned error is only set for a structural rejection (an invalid zoom level) that means no work was attempted at all; once the batch starts, its outcome - including a partial failure or an early stop from ctx being canceled - is fully described by the returned TileGenerationResult. Canceling ctx stops new tiles from being dispatched and, via GetTileHeightmap -> CreateHeightMapImage -> createHeightProfile, interrupts tiles already in progress too.

func (*Generator) GetPointsElevations

func (t *Generator) GetPointsElevations(points []Point) []Point

func (*Generator) GetTileHeightmap

func (t *Generator) GetTileHeightmap(ctx context.Context, z, x, y, resolution int) ([]byte, error)

GetTileHeightmap Generate a heightmap with the same size of an OpenStreetMap (OSM) tile. Concurrent requests for the same (x, y, z, resolution) tile are serialized so the expensive generation only happens once: the second request blocks on the per-tile lock, then finds the first request's result already on disk.

func (*Generator) GetTileHeightmapFormat

func (t *Generator) GetTileHeightmapFormat(ctx context.Context, z, x, y, resolution int, format Format) ([]byte, error)

GetTileHeightmapFormat is GetTileHeightmap with a selectable output format. Each format is cached separately on disk.

type GeoReference

type GeoReference struct {
	Lat, Lon                   float64
	PixelSizeLat, PixelSizeLon float64
}

GeoReference places an image on the WGS84 (EPSG:4326) grid. Lat/Lon are the upper-left corner; PixelSizeLat/PixelSizeLon are degrees per pixel.

type Point

type Point struct {
	X, Y      int
	Lat, Lon  float64
	Elevation int16
}

Point Elevation of a specific geographic point represented by latitude and longitude (WGS84) X and Y represents a point in the heightmap image

type ResolutionConfig

type ResolutionConfig struct {
	Width                            int
	Height                           int
	ForceInterpolation               bool
	IgnoreWhenOriginalImageIsSmaller bool
	// Format is the output encoding. Zero value is PNG.
	Format Format
}

type TileGenerationResult

type TileGenerationResult struct {
	Total     int  `json:"total"`
	Succeeded int  `json:"succeeded"`
	Failed    int  `json:"failed"`
	Canceled  bool `json:"canceled,omitempty"`
}

TileGenerationResult summarizes the outcome of a GenerateAllTilesInZoomLevel batch. Total is the intended batch size (4^zoomLevel), known upfront. Succeeded and Failed only count tiles actually attempted, so Succeeded+Failed <= Total; when the batch was canceled partway through (Canceled == true), the gap between Total and Succeeded+Failed is the number of tiles that were never even dispatched.

Jump to

Keyboard shortcuts

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