Documentation
¶
Index ¶
- func DrawEdges(img *image.RGBA, g hmz2ele.Grid, edges []RiverEdge, pixelAreaM2 float64, ...)
- func DrawLinks(img *image.RGBA, h *Hydrology, links []Link, scale int)
- func PixelFromLonLat(hm *dem2hm.HeightMap16, lon, lat float64) (x, y float64, err error)
- func Version() semver.Version
- type Barrier
- type EdgeJSON
- type GridInfo
- type HeightmapInfo
- type Hydrology
- type HydrologyInfo
- type Lines
- type Link
- type LinkJSON
- type RiverEdge
- type Rivers
- type Stats
- type VertexJSON
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrawEdges ¶
DrawEdges draws the snapped river edges onto a preview, wider for larger drainage areas.
func DrawLinks ¶
DrawLinks draws the full-resolution links onto a preview, one preview pixel per covered cell.
func PixelFromLonLat ¶
func PixelFromLonLat(hm *dem2hm.HeightMap16, lon, lat float64) (x, y float64, err error)
PixelFromLonLat returns the continuous raster coordinates of a longitude and latitude in the heightmap: the inverse of HeightMap16.LonLat.
Types ¶
type Barrier ¶
Barrier is a wall along a line between two points, used to undo earthworks such as a canal cut. Valid pixels within barrierRadius of the line are raised to at least Height meters.
func ParseBarrier ¶
ParseBarrier parses "lon1,lat1,lon2,lat2,height".
type EdgeJSON ¶
type EdgeJSON struct {
Col int `json:"col"`
Row int `json:"row"`
Side hmz2ele.Side `json:"side"`
From VertexJSON `json:"from"`
To VertexJSON `json:"to"`
DrainageKm2 float64 `json:"drainage_km2"`
}
EdgeJSON is one hex edge carrying a river. The edge is identified by the hex that owns it and the side; water flows from From to To. DrainageKm2 is the area of source ground draining through the edge.
type GridInfo ¶
type GridInfo struct {
ApothemPx int `json:"apothem_px"`
SidePx float64 `json:"side_px"`
Columns int `json:"columns"`
Rows int `json:"rows"`
}
GridInfo identifies the hex grid the rivers were snapped to.
type HeightmapInfo ¶
type HeightmapInfo struct {
FileName string `json:"file_name"`
Metadata dem2hm.Metadata `json:"metadata"`
}
HeightmapInfo identifies the heightmap the rivers were extracted from.
type Hydrology ¶
type Hydrology struct {
Width, Height int
// Elev holds the depression-filled elevations in meters.
Elev []int16
// Dir holds each pixel's flow direction code.
Dir []uint8
// Acc holds each pixel's drainage area in pixels, counting itself.
Acc []uint32
// FilledPixels is the number of pixels raised by depression filling.
FilledPixels int
// FlatPixels is the number of pixels that had no downhill neighbor
// after filling and were routed by flat resolution.
FlatPixels int
}
Hydrology is the drainage of a heightmap: filled elevations, a flow direction for every valid pixel, and the number of pixels that drain through each pixel.
func Compute ¶
Compute fills depressions in elev, in place, and computes flow directions and drainage area. Valid pixels on the raster edge or next to a no-data pixel drain off the map.
func (*Hydrology) Downstream ¶
Downstream returns the pixel that pixel i drains into, or -1 if it drains off the map or is no-data.
type HydrologyInfo ¶
type HydrologyInfo struct {
ThresholdKm2 float64 `json:"threshold_km2"`
PixelAreaM2 float64 `json:"pixel_area_m2"`
ThresholdPixels uint32 `json:"threshold_pixels"`
Barriers []string `json:"barriers"`
Method string `json:"method"`
}
HydrologyInfo records the settings used to extract the rivers.
type Lines ¶
type Lines struct {
Hmz2rivVersion string `json:"hmz2riv_version"`
Links []LinkJSON `json:"links"`
}
Lines holds the full-resolution river links, as written to JSON.
type Link ¶
type Link struct {
// Pixels lists raster pixel indexes from upstream to downstream.
Pixels []int32
// Mouth reports whether the link ends where the river leaves the map.
Mouth bool
}
Link is one stretch of river: from a source or a confluence down to the next confluence, or to where the river leaves the map. Consecutive links share the confluence pixel.
type LinkJSON ¶
type LinkJSON struct {
Mouth bool `json:"mouth"`
DrainageKm2 float64 `json:"drainage_km2"`
Points [][2]int `json:"points"`
}
LinkJSON is one link as raster pixel coordinates, upstream to downstream.
type RiverEdge ¶
RiverEdge is one hex edge carrying a river, with the direction of flow and the drainage area, in pixels, where the river leaves the edge.
func Snap ¶
Snap moves each link onto a chain of hex edges and returns the edges of the resulting river network, ordered by owner row, column, and side.
Links are snapped in decreasing order of drainage area at their downstream end, so every river is placed before its tributaries. Each river pixel moves to its nearest vertex; gaps between consecutive vertices are filled with the shortest path along hex edges, and loops are cut out. A link stops at the first vertex already in the network, which is where it joins the river it flows into.
type Rivers ¶
type Rivers struct {
Hmz2rivVersion string `json:"hmz2riv_version"`
Heightmap HeightmapInfo `json:"heightmap"`
Grid GridInfo `json:"grid"`
Hydrology HydrologyInfo `json:"hydrology"`
Stats Stats `json:"stats"`
Edges []EdgeJSON `json:"edges"`
}
Rivers is the river network snapped to hex edges, as written to JSON.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hmz2riv
command
Command hmz2riv extracts rivers from a dem2hm heightmap (format 1.1) at full resolution and snaps them to the edges of a flat-top hex grid, writing the river edges as JSON, with optional full-resolution river lines and a PNG preview.
|
Command hmz2riv extracts rivers from a dem2hm heightmap (format 1.1) at full resolution and snaps them to the edges of a flat-top hex grid, writing the river edges as JSON, with optional full-resolution river lines and a PNG preview. |