支持xml入参
This commit is contained in:
17
cmd/fus.go
17
cmd/fus.go
@@ -19,6 +19,8 @@ var fusCmd = &cobra.Command{
|
|||||||
Use: "fus",
|
Use: "fus",
|
||||||
Short: "use GDAL_Pansharpen to merge PAN and MSS images",
|
Short: "use GDAL_Pansharpen to merge PAN and MSS images",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
initFUSParams()
|
||||||
|
|
||||||
fusedTiff := filepath.Base(mssImage)
|
fusedTiff := filepath.Base(mssImage)
|
||||||
fusedTiff = strings.Replace(fusedTiff, "MSS", "FUS", -1)
|
fusedTiff = strings.Replace(fusedTiff, "MSS", "FUS", -1)
|
||||||
err := producer.GDALPansharpen(panImage, mssImage, filepath.Join(outputDir, fusedTiff))
|
err := producer.GDALPansharpen(panImage, mssImage, filepath.Join(outputDir, fusedTiff))
|
||||||
@@ -36,3 +38,18 @@ func init() {
|
|||||||
fusCmd.Flags().StringVarP(&outputDir, "output", "o", "", "path to the output directory")
|
fusCmd.Flags().StringVarP(&outputDir, "output", "o", "", "path to the output directory")
|
||||||
fusCmd.Flags().StringVarP(¶msXML, "params", "x", "", "path to the XML file containing parameters for GDAL_Pansharpen")
|
fusCmd.Flags().StringVarP(¶msXML, "params", "x", "", "path to the XML file containing parameters for GDAL_Pansharpen")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initFUSParams() {
|
||||||
|
if paramsXML == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
task, err := producer.ParseXMLFUSTask(paramsXML)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
panImage = task.InputFileList.PanTiff
|
||||||
|
mssImage = task.InputFileList.MssTiff
|
||||||
|
outputDir = task.Params.OutputPath
|
||||||
|
}
|
||||||
|
|||||||
28
cmd/proc.go
28
cmd/proc.go
@@ -25,6 +25,8 @@ var procCmd = &cobra.Command{
|
|||||||
config.GViper = config.InitViper(configFile)
|
config.GViper = config.InitViper(configFile)
|
||||||
logrus.SetLevel(config.GCONFIG.LogLevel)
|
logrus.SetLevel(config.GCONFIG.LogLevel)
|
||||||
|
|
||||||
|
initParams()
|
||||||
|
|
||||||
reg := producer.NewRegistrator(producer.DownSampled)
|
reg := producer.NewRegistrator(producer.DownSampled)
|
||||||
reg.Params = params
|
reg.Params = params
|
||||||
reg.Params.MssTiffFile = filepath.Join(params.OutputDir, strings.TrimSuffix(filepath.Base(params.MssRawFile), filepath.Ext(params.MssRawFile))+".tiff")
|
reg.Params.MssTiffFile = filepath.Join(params.OutputDir, strings.TrimSuffix(filepath.Base(params.MssRawFile), filepath.Ext(params.MssRawFile))+".tiff")
|
||||||
@@ -92,3 +94,29 @@ func init() {
|
|||||||
procCmd.Flags().BoolVarP(&saveStrip, "save-strip", "", false, "save original and registered images as GDAL GTiff")
|
procCmd.Flags().BoolVarP(&saveStrip, "save-strip", "", false, "save original and registered images as GDAL GTiff")
|
||||||
procCmd.Flags().StringVarP(¶msXML, "params", "x", "", "params xml file path")
|
procCmd.Flags().StringVarP(¶msXML, "params", "x", "", "params xml file path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initParams() producer.Params {
|
||||||
|
taskParams := params
|
||||||
|
taskParams.MssTiffFile = filepath.Join(params.OutputDir, strings.TrimSuffix(filepath.Base(params.MssRawFile),
|
||||||
|
filepath.Ext(params.MssRawFile))+".tiff")
|
||||||
|
taskParams.PanTiffFile = filepath.Join(params.OutputDir,
|
||||||
|
strings.TrimSuffix(filepath.Base(params.PanRawFile),
|
||||||
|
filepath.Ext(params.PanRawFile))+".tiff")
|
||||||
|
taskParams.FusTIffFile = strings.Replace(taskParams.MssTiffFile, ".tiff", "_FUS.tiff", 1)
|
||||||
|
|
||||||
|
if paramsXML == "" {
|
||||||
|
return taskParams
|
||||||
|
}
|
||||||
|
|
||||||
|
task, err := producer.ParseXMLImageTask(paramsXML)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskParams.PanRawFile = task.InputFileList.PanData
|
||||||
|
taskParams.MssRawFile = task.InputFileList.MssData
|
||||||
|
taskParams.AuxRawFile = task.InputFileList.AuxData
|
||||||
|
taskParams.DoPansharpen = task.Params.DoPansharpen
|
||||||
|
taskParams.OutputDir = task.Params.OutputPath
|
||||||
|
return taskParams
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gonum.org/v1/gonum/mat"
|
"gonum.org/v1/gonum/mat"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type Params struct {
|
type Params struct {
|
||||||
PanRawFile string
|
PanRawFile string
|
||||||
@@ -12,3 +17,83 @@ type Params struct {
|
|||||||
FusTIffFile string
|
FusTIffFile string
|
||||||
SubScenes bool
|
SubScenes bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type XMLImageTask struct {
|
||||||
|
XMLName xml.Name `xml:"task"`
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
Script string `xml:"script"`
|
||||||
|
InputFileList XMLInputFileList `xml:"inputfilelist"`
|
||||||
|
Params XMLParams `xml:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMLInputFileList struct {
|
||||||
|
PanData string `xml:"panData"`
|
||||||
|
MssData string `xml:"mssData"`
|
||||||
|
AuxData string `xml:"auxData"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMLParams struct {
|
||||||
|
Satellite string `xml:"satellite"`
|
||||||
|
Sensor string `xml:"sensor"`
|
||||||
|
ProductLevel string `xml:"productLevel"`
|
||||||
|
ProductID string `xml:"productId"`
|
||||||
|
TempPath string `xml:"tempPath"`
|
||||||
|
OutputPath string `xml:"outputPath"`
|
||||||
|
DeleteTempFlag int `xml:"deleteTempFlag"`
|
||||||
|
ReportFile string `xml:"reportFile"`
|
||||||
|
DataID string `xml:"dataId"`
|
||||||
|
DoPansharpen bool `xml:"doPansharpen"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseXMLImageTask(xmlFile string) (*XMLImageTask, error) {
|
||||||
|
var task XMLImageTask
|
||||||
|
data, err := os.ReadFile(xmlFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = xml.Unmarshal(data, &task)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &task, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMLFUSTask struct {
|
||||||
|
XMLName xml.Name `xml:"task"`
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
Script string `xml:"script"`
|
||||||
|
InputFileList XMLFUSInputFileList `xml:"inputfilelist"`
|
||||||
|
Params XMLFUSParams `xml:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMLFUSInputFileList struct {
|
||||||
|
PanTiff string `xml:"panTiff"`
|
||||||
|
MssTiff string `xml:"mssTiff"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type XMLFUSParams struct {
|
||||||
|
Satellite string `xml:"satellite"`
|
||||||
|
Sensor string `xml:"sensor"`
|
||||||
|
ProductLevel string `xml:"productLevel"`
|
||||||
|
ProductID string `xml:"productId"`
|
||||||
|
TempPath string `xml:"tempPath"`
|
||||||
|
OutputPath string `xml:"outputPath"`
|
||||||
|
DeleteTempFlag int `xml:"deleteTempFlag"`
|
||||||
|
ReportFile string `xml:"reportFile"`
|
||||||
|
DataID string `xml:"dataId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseXMLFUSTask(xmlFile string) (*XMLFUSTask, error) {
|
||||||
|
var task XMLFUSTask
|
||||||
|
data, err := os.ReadFile(xmlFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = xml.Unmarshal(data, &task)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &task, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
@@ -11,7 +11,7 @@ type Report struct {
|
|||||||
Satellite string `xml:"satellite,attr"`
|
Satellite string `xml:"satellite,attr"`
|
||||||
Sensor string `xml:"sensor,attr"`
|
Sensor string `xml:"sensor,attr"`
|
||||||
ProductLevel string `xml:"productLevel,attr"`
|
ProductLevel string `xml:"productLevel,attr"`
|
||||||
Scenes []ReportScene `xml:"scene"`
|
Scenes []ReportScene `xml:"scenes>scene"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scene represents each scene in the report
|
// Scene represents each scene in the report
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package imageproc
|
package producer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|||||||
Reference in New Issue
Block a user