asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.
go get -v github.com/artulab/asciigrid
Import the package:
import "github.com/artulab/asciigrid"
Construct a decoder object out of any I/O stream implementing Go's Reader interface:
file, err := os.Open("grid.asc")
if err != nil {
log.Fatal(err)
}
enc := asciigrid.NewDecoder(file)
Read geographic header data and grid values into memory:
grid, err := enc.Decode()
fmt.Printf("ncols: %v\n", grid.Ncols)
fmt.Printf("nrows: %v\n", grid.Nrows)
fmt.Printf("nodata: %v\n", grid.Nodata)
for j := 0; j < grid.Nrows; j++ {
for i := 0; i < grid.Ncols; i++ {
fmt.Printf("%d ", grid.Buffer[j][i])
}
fmt.Println()
}
Construct an encoder object out of an I/O stream object representing files, memory buffers etc.:
file, err := os.Create("grid.asc")
if err != nil {
log.Fatal(err)
}
enc := asciigrid.NewEncoder(file)
Write the grid data in memory into an I/O stream implementing Go's Writer interface:
buf := [][]int{
{0, 1, 2},
{3, 4, 5},
}
grid := asciigrid.Grid{Ncols: 3, Nrows: 2, Xllcorner: 0.1, Yllcorner: 0.2, Cellsize: 1, Nodata: -9999, Buffer: buf}
enc.Encode(&grid)
See examples for more information.
go test
👤 Ahmet Artu Yildirim
- Website: https://www.artulab.com
- E-Mail: [email protected]
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2021 Ahmet Artu Yildirim.
This project is MIT licensed.