aux platform
This commit is contained in:
69
extract/envi.go
Normal file
69
extract/envi.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package extract
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html"
|
||||
|
||||
"io"
|
||||
"os"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type BSQWriter struct {
|
||||
filepath string
|
||||
fio *os.File
|
||||
w io.Writer
|
||||
content *EnviHdr
|
||||
}
|
||||
|
||||
var HDRTemplate = `ENVI
|
||||
description = {
|
||||
File Imported into ENVI.}
|
||||
samples = {{.Samples}}
|
||||
lines = {{.Lines}}
|
||||
bands = {{.Bands}}
|
||||
header offset = 0
|
||||
file type = ENVI Standard
|
||||
data type = 12
|
||||
interleave = bsq
|
||||
sensor type = Unknown
|
||||
byte order = 0
|
||||
wavelength units = Unknown`
|
||||
|
||||
// https://www.nv5geospatialsoftware.com/docs/ENVIHeaderFiles.html
|
||||
type EnviHdr struct {
|
||||
Samples int // samples (pixels) each line
|
||||
Lines int
|
||||
Bands int
|
||||
}
|
||||
|
||||
func (h *EnviHdr) String() string {
|
||||
var t *template.Template
|
||||
t = template.New("template")
|
||||
t, err := t.Parse(HDRTemplate)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
t.Execute(buf, h)
|
||||
buf = bytes.NewBufferString(html.UnescapeString(buf.String()))
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func NewBSQWriter(filepath string, content *EnviHdr) (*BSQWriter, error) {
|
||||
fio, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w := fio
|
||||
return &BSQWriter{filepath, fio, w, content}, nil
|
||||
}
|
||||
|
||||
func (w *BSQWriter) Write(data []byte) (int, error) {
|
||||
return w.w.Write(data)
|
||||
}
|
||||
|
||||
func (w *BSQWriter) Close() error {
|
||||
return w.fio.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user