Skip to content

asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

License

Notifications You must be signed in to change notification settings

artulab/asciigrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asciigrid

Version License: MIT

asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

Install

go get -v github.com/artulab/asciigrid

Usage

Import the package:

import "github.com/artulab/asciigrid"

Decoder

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()
}

Encoder

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.

Run tests

go test

Author

👤 Ahmet Artu Yildirim

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 Ahmet Artu Yildirim.

This project is MIT licensed.

About

asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages