grid

package
v0.0.0-...-79f6cc9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 23 Imported by: 9

README

goHydro.grid

Used for gridded data. Reads from and Writes to band interleaved by line (*.BIL) raster files.

Structures
  • definition basic grid metadata (origin, number of rows/columns, rotation, cell widths, etc.)
  • face is an alternate grid organization scheme based on the shared faces among grid cells.
  • indx for grids of integer data, generally assumed to have categorical implications.
  • intersect functions needed to rescale data from differing grid definitions.
  • real for grids of real (floating point) data.
  • sws specialized tools using the above functions to define set of topologically ordered sub-watersheds.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilterGaussianSmoothing = [][]float64{
	{0.00366, 0.01465, 0.02564, 0.01465, 0.00366},
	{0.01465, 0.05861, 0.09524, 0.05861, 0.01465},
	{0.02564, 0.09524, 0.15020, 0.09524, 0.02564},
	{0.01465, 0.05861, 0.09524, 0.05861, 0.01465},
	{0.00366, 0.01465, 0.02564, 0.01465, 0.00366},
}

https://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm center cell was modified from .15018 to .15020 such that the filter summed to 1.

Functions

func BufferRings

func BufferRings(nrings int) map[int][][]int

func BufferRingsSquare

func BufferRingsSquare(nrings int) map[int][][]int

func SurroundingCells

func SurroundingCells(unitRadius int) [][]int

SurroundingCells returns the relative row,col given in units of cell width

func SurroundingRing

func SurroundingRing(unitRadius int) [][]int

Types

type Cell

type Cell struct {
	Top, Bottom, N, Ss, Sy, H0 float32
	K                          []float32
}

type Crawler

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

func (*Crawler) CrawlByFloat

func (crwl *Crawler) CrawlByFloat(m map[int]float64, byKey bool) (groupId map[int]int, borderId map[int][]int, ng int)

func (*Crawler) CrawlByInt

func (crwl *Crawler) CrawlByInt(m map[int]int, byKey bool) (groupId map[int]int, borderId map[int][]int, ng int)

type Definition

type Definition struct {
	Coord map[int]mmaths.Point
	Act   map[int]int // [cellID]activeID

	Sactives                       []int   // an ordered slice of active cell IDs
	Eorig, Norig, Rotation, Cwidth float64 // Xul; Yul; grid rotation about ULorigin; cell width
	Nrow, Ncol, Nact               int
	Name                           string
	// contains filtered or unexported fields
}

Definition struct of a uniform grid

func BuildDefinitionFromPoints

func BuildDefinitionFromPoints(nam string, cxy map[int][]float64) *Definition

func NewDefinition

func NewDefinition(nam string, nr, nc int, UniformCellSize float64) *Definition

NewDefinition constructs a basic grid definition

func ReadGDEF

func ReadGDEF(fp string, print bool) (*Definition, error)

ReadGDEF imports a grid definition file

func ReadHdr

func ReadHdr(fp string) (*Definition, float64, error)

func (*Definition) Buffer

func (gd *Definition) Buffer(cid0 int, cardinal, isActive bool) []int

func (*Definition) Buffers

func (gd *Definition) Buffers(cardinal, isActive bool) map[int][]int

func (*Definition) BuildTileSet

func (gd *Definition) BuildTileSet(zoomMin, zoomMax, epsg int, outDir string) (tset TileSet)

func (*Definition) CellArea

func (gd *Definition) CellArea() float64

CellArea returns the (uniform) area of the grid cells

func (*Definition) CellCentroid

func (gd *Definition) CellCentroid(cid int) []float64

func (*Definition) CellCentroids

func (gd *Definition) CellCentroids() map[int][]float64

func (*Definition) CellID

func (gd *Definition) CellID(row, col int) int

CellID returns cell ID for a given row and column index

func (*Definition) CellIndexXR

func (gd *Definition) CellIndexXR() map[int]int

CellIndexXR returns a mapping of cell id to an array index

func (*Definition) CellOriginUL

func (gd *Definition) CellOriginUL(cid int) (r, c int, x0, y0 float64)

func (*Definition) CellPerimeter

func (gd *Definition) CellPerimeter(cid int) [][]float64

func (*Definition) ConatainsPoint

func (gd *Definition) ConatainsPoint(x, y, buf float64) bool

ConatainsPoint returns whether a point exists within a grid definition, with a specified buffer

func (*Definition) Crop

func (gd *Definition) Crop(xn, xx, yn, yx float64, buffer int) (*Definition, int, int)

func (*Definition) CropToActives

func (gd *Definition) CropToActives() *Definition

func (*Definition) ExtentToCellIDs

func (gd *Definition) ExtentToCellIDs(ext mmaths.Extent) []int

func (*Definition) Extents

func (gd *Definition) Extents() []float64

Extents Left Up Right Down

func (*Definition) Intersect

func (gd *Definition) Intersect(toGD *Definition) map[int][]int

Intersect returns a mapping from current Definition to inputted Definition for now, only Definitions that share the same origin, and cell sizes are mulitples can be considered

func (*Definition) IsActive

func (gd *Definition) IsActive(cid int) bool

IsActive returns whether a cell ID is of an active cell

func (*Definition) IsSimilar

func (gd *Definition) IsSimilar(gd1 *Definition) bool

func (*Definition) LineToCellIDs

func (gd *Definition) LineToCellIDs(x0, y0, x1, y1 float64) []int

func (*Definition) Ncells

func (gd *Definition) Ncells() int

Ncells returns the count of grid cells

func (*Definition) NullArray

func (gd *Definition) NullArray(nodatavalue float64) []float64

func (*Definition) NullFloat32

func (gd *Definition) NullFloat32(nodatavalue float32) []float32

func (*Definition) NullInt32

func (gd *Definition) NullInt32(nodatavalue int32) []int32

func (*Definition) PointToActiveCellID

func (gd *Definition) PointToActiveCellID(x, y float64) int

func (*Definition) PointToCellID

func (gd *Definition) PointToCellID(x, y float64) int

PointToCellID returns the cell id that contains the xy coordinates

func (*Definition) PointToRowCol

func (gd *Definition) PointToRowCol(x, y float64) (row, col int)

PointToRowCol returns the row and column grid cell that contains the xy coordinates

func (*Definition) PolygonToCellIDs

func (gd *Definition) PolygonToCellIDs(vertices [][]float64) ([]int, int)

func (*Definition) ResetActives

func (gd *Definition) ResetActives(cids []int)

func (*Definition) RowCol

func (gd *Definition) RowCol(cid int) (row, col int)

RowCol returns row and column index for a given cell ID

func (*Definition) SaveAs

func (gd *Definition) SaveAs(fp string) error

SaveAs writes a grid definition file of format *.gdef

func (*Definition) ToASC

func (gd *Definition) ToASC(fp string) error

ToASC creates an ascii-grid based on grid definition. If the grid definition contains active cells, they will be given a value of 1 in the raster.

func (*Definition) ToASCheader

func (gd *Definition) ToASCheader(t *mmio.TXTwriter)

ToASCheader writes ASC grid header info to writer

func (*Definition) ToAscData

func (gd *Definition) ToAscData(fp string, d map[int]float64) error

ToAscData converts a map referenced to cell id to an ASCII grid

func (*Definition) ToBIL

func (gd *Definition) ToBIL(fp string, f32 []float32)

func (*Definition) ToCrawler

func (gd *Definition) ToCrawler(cardinalOnly bool) *Crawler

func (*Definition) ToHDR

func (gd *Definition) ToHDR(fp string, nbands, nbits int) error

ToHDR creates an ESRI-grid based on grid definition header

func (*Definition) ToHDRfloat

func (gd *Definition) ToHDRfloat(fp string, nbands, nbits int) error

ToHDRfloat creates an ESRI-grid based on grid definition header for float arrays

func (*Definition) ToIndx

func (gd *Definition) ToIndx(imap map[int]int) *Indx

ToIndx

func (*Definition) ToVertex

func (gd *Definition) ToVertex() *Vertex

type Face

type Face struct {
	GD *Definition

	CellFace, FaceCell map[int][]int

	Nfaces int
	// contains filtered or unexported fields
}

Face definition struct collection of cell IDs surrounding grid faces EXAMPLE: 4x5 cells = 2*(4x5)+4+5 = 49 faces gd1 := Definition("test", 4, 5)

o---o---o---o---o---o       o-0-o-1-o-2-o-3-o-4-o      o---o---o---o---o---o
| 0 | 1 | 2 | 3 | 4 |       |   |   |   |   |   |     25  26  27  28  29  30        North-east              |
o---o---o---o---o---o       o-5-o-6-o-7-o-8-o-9-o      o---o---o---o---o---o     ^   positive          from | to
| 5 | 6 | 7 | 8 | 9 |       |   |   |   |   |   |     31  32  33  34  35  36    /|\                         |
o---o---o---o---o---o  -->  o-10o-11o-12o-13o-14o  &   o---o---o---o---o---o     |
| 10| 11| 12| 13| 14|       |   |   |   |   |   |     37  38  39  40  41  42     |   +                     to
o---o---o---o---o---o       o-15o-16o-17o-18o-19o      o---o---o---o---o---o     |_________\             ------
| 15| 16| 17| 18| 19|       |   |   |   |   |   |     43  44  45  46  47  48               /              from
o---o---o---o---o---o       o-20o-21o-22o-23o-24o      o---o---o---o---o---o

func NewFace

func NewFace(gd *Definition) *Face

NewFace creates a new Face struct

func (*Face) IsUpwardFace

func (f *Face) IsUpwardFace(fid int) bool

IsUpwardFace returns whether the orientation of the face is normal to the vertical

func (*Face) LeftFaces

func (f *Face) LeftFaces() []int

LeftFaces returns the face indices of all 'left' faces

func (*Face) RightFaces

func (f *Face) RightFaces() []int

RightFaces returns the face indices of all 'right' faces

type HSTRAT

type HSTRAT struct {
	Nam      string
	MinThick float64
	Nlay     int
	Cells    map[int]Cell
}

func ReadHSTRAT

func ReadHSTRAT(fp string, print bool) (*HSTRAT, error)

type Indx

type Indx struct {
	GD *Definition
	A  map[int]int
}

Indx data type array of integers

func (*Indx) ImportBil

func (x *Indx) ImportBil(fp string) error

func (*Indx) New

func (x *Indx) New(fp string)

New constructor

func (*Indx) Nvalues

func (x *Indx) Nvalues() int

Nvalues returns the size of the Indx

func (*Indx) ToASC

func (x *Indx) ToASC(fp string, ignoreActives bool) error

ToASC creates an ascii-grid of Indx.

func (*Indx) ToBil

func (x *Indx) ToBil(fp string) error

func (*Indx) ToBinary

func (x *Indx) ToBinary(fp string) error

ToBinary writes to binary array

func (*Indx) ToTiles

func (g *Indx) ToTiles(cmap map[int]color.RGBA, zoomMin, zoomMax, epsg int, tileDir string)

ToTiles take a categorical grid and builds a set of raster/image tiles for webmapping

func (*Indx) UniqueValues

func (x *Indx) UniqueValues() []int

UniqueValues returns the value of a given cell ID

func (*Indx) Value

func (x *Indx) Value(cid int) int

Value returns the value of a given cell ID

type PolygonRasterizer

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

func (*PolygonRasterizer) InteriorCellIDs

func (pr *PolygonRasterizer) InteriorCellIDs(GD *Definition, Polygon [][]float64) ([]int, int)

type Real

type Real struct {
	GD *Definition
	A  map[int]float64
}

Real data type array

func (*Real) Crop

func (r *Real) Crop(xn, xx, yn, yx float64, buffer int)

func (*Real) ImportAsc

func (r *Real) ImportAsc(fp string) error

func (*Real) ImportBil

func (r *Real) ImportBil(fp string) error

func (*Real) ImportRaster

func (r *Real) ImportRaster(fp string) error

func (Real) Min

func (g Real) Min(buffer int) map[int]float64

func (*Real) New

func (r *Real) New(fp string)

New constructor

func (*Real) NewGD32

func (r *Real) NewGD32(fp string, gd *Definition)

NewGD32 constructor

func (*Real) ResetToGDEF

func (r *Real) ResetToGDEF(gdeffp string, crop bool)

func (*Real) ToAsc

func (r *Real) ToAsc(fp string) error

func (*Real) ToBil

func (x *Real) ToBil(fp string) error

func (*Real) ToPNG

func (r *Real) ToPNG(fp string) error

func (*Real) ToTiles

func (r *Real) ToTiles(minVal, maxVal float64, zoomMin, zoomMax, epsg int, tileDir string)

ToTiles take a Real grid and builds a set of raster/image tiles for webmapping

type SWS

type SWS struct {
	GD         *Definition
	SwsC, Usws map[int][]int // SwsC: [swsID]cellID; Usws: [downstream_swsID]upstream_swsID
	CSws, Dsws map[int]int   // CSws: [cellID]swsID; Dsws: [upstream_swsID]downstream_swsID
}

func CollectSWS

func CollectSWS(swsFP string, gd *Definition) *SWS

func (*SWS) ClimbFrom

func (s *SWS) ClimbFrom(swsID int) []int

func (*SWS) Print

func (s *SWS) Print()

type Tile

type Tile struct{ Z, X, Y int }

func (*Tile) FromLatLong

func (t *Tile) FromLatLong(lat, long float64, z int)

func (*Tile) Scale

func (t *Tile) Scale(lat float64) float64

func (*Tile) ToExtent

func (t *Tile) ToExtent() (latUL, longUL, latLR, longLR float64)

func (*Tile) ToLatLong

func (t *Tile) ToLatLong() (lat, long float64)

type TileSet

type TileSet struct {
	Tiles   []Tile
	Cids    [][]int           // cell ids covering tiles
	Clnglat map[int][]float64 // lat-long projected cell centroid locations
}

type Vertex

type Vertex struct {
	Nodecoord            map[int][]float64
	Nodecells, Cellnodes map[int][]int
	// contains filtered or unexported fields
}

func (*Vertex) Nvert

func (v *Vertex) Nvert() int

Jump to

Keyboard shortcuts

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