Documentation
¶
Index ¶
- Constants
- Variables
- type Format
- type Generator
- func (t *Generator) CreateHeightMapImage(ctx context.Context, lat, lon float64, side float64, conf ResolutionConfig) ([]byte, error)
- func (t *Generator) GenerateAllTilesInZoomLevel(ctx context.Context, zoomLevel int) (TileGenerationResult, error)
- func (t *Generator) GetPointsElevations(points []Point) []Point
- func (t *Generator) GetTileHeightmap(ctx context.Context, z, x, y, resolution int) ([]byte, error)
- func (t *Generator) GetTileHeightmapFormat(ctx context.Context, z, x, y, resolution int, format Format) ([]byte, error)
- type GeoReference
- type Point
- type ResolutionConfig
- type TileGenerationResult
Constants ¶
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 ¶
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 ¶
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 ¶
ContentType returns the HTTP media type.
func (Format) IsElevation ¶
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 (*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 (*Generator) GetTileHeightmap ¶
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.
type GeoReference ¶
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 ¶
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 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.