This commit is contained in:
nuknal
2024-08-19 18:05:55 +08:00
parent 85f9f44653
commit ea23839bf2
6 changed files with 116 additions and 1 deletions

View File

@@ -150,3 +150,27 @@ func setGeoTransform(ds *godal.Dataset, topLeftLng, topLeftLat, resolution float
ds.SetMetadata("TIFFTAG_DATETIME", time.Now().String())
ds.SetMetadata("TIFFTAG_SOFTWARE", "StarWiz-SJY01-IMAGE-PROC")
}
func ReadTiff(tifFile string) ([][][]float32, error) {
hDataset, err := godal.Open(tifFile)
if err != nil {
return nil, err
}
var data [][][]float32
for _, band := range hDataset.Bands() {
structure := band.Structure()
var dataBand [][]float32
for y := 1; y <= structure.SizeY; y++ {
scanline := make([]float32, structure.SizeX)
err = band.Read(0, y, scanline, structure.SizeX, 1)
if err != nil {
return nil, err
}
dataBand = append(dataBand, scanline)
}
data = append(data, dataBand)
}
return data, nil
}