Example #1
0
func (this *FillDepressions) ParseArguments(args []string) {
	inputFile := args[0]
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}
	outputFile := args[1]
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	this.fixFlats = false
	if len(strings.TrimSpace(args[2])) > 0 && args[2] != "not specified" {
		var err error
		if this.fixFlats, err = strconv.ParseBool(strings.TrimSpace(args[2])); err != nil {
			this.fixFlats = false
			println(err)
		}
	} else {
		this.fixFlats = false
	}
	this.Run()
}
Example #2
0
func (this *Aspect) ParseArguments(args []string) {
	inputFile := args[0]
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}
	outputFile := args[1]
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	this.Run()
}
Example #3
0
func (this *DeviationFromMean) CollectArguments() {
	consolereader := bufio.NewReader(os.Stdin)

	// get the input file name
	print("Enter the raster file name (incl. file extension): ")
	inputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}

	// get the output file name
	print("Enter the output file name (incl. file extension): ")
	outputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	// get the neighbourhood radius argument
	print("Neighbourhood radius (grid cells): ")
	radiusStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.neighbourhoodSize = 1
		println(err)
	}

	if len(strings.TrimSpace(radiusStr)) > 0 {
		var val int64
		if val, err = strconv.ParseInt(strings.TrimSpace(radiusStr), 0, 0); err != nil {
			this.neighbourhoodSize = 1
			println(err)
		} else {
			this.neighbourhoodSize = int(val)
		}
	} else {
		this.neighbourhoodSize = 1
	}

	this.Run()
}
Example #4
0
func (this *BreachStreams) CollectArguments() {
	consolereader := bufio.NewReader(os.Stdin)

	// get the input streams file name
	print("Enter the streams raster file name (incl. file extension): ")
	streamFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	streamFile = strings.TrimSpace(streamFile)
	if !strings.Contains(streamFile, pathSep) {
		streamFile = this.toolManager.workingDirectory + streamFile
	}
	this.streamFile = streamFile
	// see if the file exists
	if _, err := os.Stat(this.streamFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.streamFile)
		return
	}

	// get the input DEM file name
	print("Enter the DEM file name (incl. file extension): ")
	demFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	demFile = strings.TrimSpace(demFile)
	if !strings.Contains(demFile, pathSep) {
		demFile = this.toolManager.workingDirectory + demFile
	}
	this.demFile = demFile
	// see if the file exists
	if _, err := os.Stat(this.demFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.demFile)
		return
	}

	// get the output file name
	print("Enter the output file name (incl. file extension): ")
	outputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	this.Run()
}
Example #5
0
func (this *FillDepressions) CollectArguments() {
	consolereader := bufio.NewReader(os.Stdin)

	// get the input file name
	print("Enter the DEM file name (incl. file extension): ")
	inputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}

	// get the output file name
	print("Enter the output file name (incl. file extension): ")
	outputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	// get the fixflats argument
	print("Fix the resulting flat areas (T or F)? ")
	fixFlatsStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.fixFlats = false
		println(err)
	}

	if len(strings.TrimSpace(fixFlatsStr)) > 0 {
		if this.fixFlats, err = strconv.ParseBool(strings.TrimSpace(fixFlatsStr)); err != nil {
			this.fixFlats = false
			println(err)
		}
	} else {
		this.fixFlats = false
	}

	this.Run()
}
func (this *ElevationPercentile) ParseArguments(args []string) {
	inputFile := args[0]
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}
	outputFile := args[1]
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	this.neighbourhoodSize = 1
	if len(strings.TrimSpace(args[2])) > 0 && args[2] != "not specified" {
		var err error
		var val int64
		if val, err = strconv.ParseInt(strings.TrimSpace(args[2]), 0, 0); err != nil {
			println(err)
		} else {
			this.neighbourhoodSize = int(val)
		}
	}

	this.numBins = 1
	if len(strings.TrimSpace(args[3])) > 0 && args[3] != "not specified" {
		var err error
		var val int64
		if val, err = strconv.ParseInt(strings.TrimSpace(args[3]), 0, 0); err != nil {
			println(err)
		} else {
			this.numBins = uint32(val)
		}
	}

	this.Run()
}
Example #7
0
func (this *PrintGeoTiffTags) Run() {

	rasterType, err := raster.DetermineRasterFormat(this.inputFile)
	if rasterType != raster.RT_GeoTiff || err != nil {
		println("The input file is not of a GeoTIFF format.")
		return
	}

	input, err := raster.CreateRasterFromFile(this.inputFile)
	if err != nil {
		println(err.Error())
	}

	tagInfo := input.GetMetadataEntries()
	if len(tagInfo) > 0 {
		println(tagInfo[0])
	} else {
		println("Error reading metadata entries.")
	}
}
Example #8
0
// ParseArguments is used when the tool is run using command-line args
// rather than in interactive input/output mode.
func (this *BreachDepressions) ParseArguments(args []string) {
	inputFile := args[0]
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}
	outputFile := args[1]
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	if len(strings.TrimSpace(args[2])) > 0 && args[2] != "not specified" {
		if maxDepth, err := strconv.ParseFloat(strings.TrimSpace(args[2]), 64); err == nil {
			this.maxDepth = maxDepth
			if this.maxDepth < 0 {
				this.maxDepth = math.MaxFloat32
			}
		} else {
			this.maxDepth = math.MaxFloat32
			println(err)
		}
	} else {
		this.maxDepth = math.MaxFloat32
	}
	if len(strings.TrimSpace(args[3])) > 0 && args[3] != "not specified" {
		if maxLength, err := strconv.ParseFloat(strings.TrimSpace(args[3]), 64); err == nil {
			this.maxLength = int32(maxLength)
			if this.maxLength < 0 {
				this.maxLength = math.MaxInt32
			}
		} else {
			this.maxLength = math.MaxInt32
			println(err)
		}
	} else {
		this.maxLength = math.MaxInt32
	}

	this.constrainedBreaching = false
	if len(strings.TrimSpace(args[4])) > 0 && args[4] != "not specified" {
		var err error
		if this.constrainedBreaching, err = strconv.ParseBool(strings.TrimSpace(args[4])); err != nil {
			this.constrainedBreaching = false
			println(err)
		}
	} else {
		this.constrainedBreaching = false
	}

	this.Run()
}
Example #9
0
func (this *BreachDepressions) CollectArguments() {
	consolereader := bufio.NewReader(os.Stdin)

	// get the input file name
	print("Enter the DEM file name (incl. file extension): ")
	inputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}

	// get the output file name
	print("Enter the output file name (incl. file extension): ")
	outputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	// get the maxDepth argument
	print("Enter the maximum breach depth (z units): ")
	maxDepthStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.maxDepth = math.MaxFloat64
		println(err)
	}

	if len(strings.TrimSpace(maxDepthStr)) > 0 {
		if this.maxDepth, err = strconv.ParseFloat(strings.TrimSpace(maxDepthStr), 64); err != nil {
			this.maxDepth = math.MaxFloat64
			println(err)
		}
	} else {
		this.maxDepth = -1
	}

	// get the maxDepth argument
	print("Enter the maximum breach channel length (grid cells): ")
	maxLengthStr, err := consolereader.ReadString('\n')
	if len(strings.TrimSpace(maxLengthStr)) > 0 {
		if err != nil {
			this.maxLength = math.MaxInt32
			println(err)
		}
		if maxLength, err := strconv.ParseFloat(strings.TrimSpace(maxLengthStr), 64); err == nil {
			this.maxLength = int32(maxLength)
		} else {
			this.maxLength = math.MaxInt32
			println(err)
		}
	} else {
		this.maxLength = -1
	}

	// get the constrained breaching argument
	print("Use constrained breaching (T or F)? ")
	constrainedStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.constrainedBreaching = false
		println(err)
	}

	if len(strings.TrimSpace(constrainedStr)) > 0 {
		if this.constrainedBreaching, err = strconv.ParseBool(strings.TrimSpace(constrainedStr)); err != nil {
			this.constrainedBreaching = false
			println(err)
		}
	} else {
		this.constrainedBreaching = false
	}

	if this.maxDepth < math.MaxFloat64 && this.maxLength < math.MaxInt32 {
		print("Perform post-breach filling (T or F)? ")
		postBreachFillStr, err := consolereader.ReadString('\n')
		if err != nil {
			this.postBreachFilling = false
			println(err)
		}

		if len(strings.TrimSpace(postBreachFillStr)) > 0 {
			if this.postBreachFilling, err = strconv.ParseBool(strings.TrimSpace(postBreachFillStr)); err != nil {
				this.postBreachFilling = false
				println(err)
			}
		} else {
			this.postBreachFilling = false
		}
	}

	this.Run()
}
func (this *Whitebox2GeoTiff) Run() {

	// check that the input raster is in Whitebox GAT format
	rasterType, err := raster.DetermineRasterFormat(this.inputFile)
	if rasterType != raster.RT_WhiteboxRaster || err != nil {
		println("The input file is not of a Whitebox GAT format.")
		return
	}

	input, err := raster.CreateRasterFromFile(this.inputFile)
	if err != nil {
		println(err.Error())
	}

	// get the input config
	inConfig := input.GetRasterConfig()

	// get the number of rows and columns
	rows := input.Rows
	columns := input.Columns
	rowsLessOne := rows - 1
	inNodata := input.NoDataValue

	// check that the specified output file is in GeoTiff format
	rasterType, err = raster.DetermineRasterFormat(this.outputFile)
	if rasterType != raster.RT_GeoTiff || err != nil {
		println("Warning: The specified output file name is not of a GeoTIFF format.\nThe file name has been modified")
		index := strings.LastIndex(this.outputFile, ".")
		extension := this.outputFile[index:len(this.outputFile)]
		newFileName := strings.Replace(this.outputFile, extension, ".tif", -1)
		this.outputFile = newFileName
	}

	// output the data
	outConfig := raster.NewDefaultRasterConfig()
	outConfig.DataType = inConfig.DataType
	outConfig.EPSGCode = inConfig.EPSGCode
	//outConfig.NoDataValue = inConfig.NoDataValue
	outConfig.CoordinateRefSystemWKT = inConfig.CoordinateRefSystemWKT
	output, err := raster.CreateNewRaster(this.outputFile, input.Rows, input.Columns,
		input.North, input.South, input.East, input.West, outConfig)
	outNodata := output.NoDataValue
	if err != nil {
		println(err.Error())
	}

	var progress, oldProgress int
	var z float64
	oldProgress = -1
	for row := 0; row < rows; row++ {
		for col := 0; col < columns; col++ {
			z = input.Value(row, col)
			if z != inNodata {
				output.SetValue(row, col, z)
			} else {
				output.SetValue(row, col, outNodata)
			}
		}
		progress = int(100.0 * row / rowsLessOne)
		if progress != oldProgress {
			printf("\rProgress: %v%%", progress)
			oldProgress = progress
		}
	}
	output.Save()
	println("\nOperation complete!")
}
Example #11
0
func (this *FD8FlowAccum) CollectArguments() {
	consolereader := bufio.NewReader(os.Stdin)

	// get the input file name
	print("Enter the DEM file name (incl. file extension): ")
	inputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	inputFile = strings.TrimSpace(inputFile)
	if !strings.Contains(inputFile, pathSep) {
		inputFile = this.toolManager.workingDirectory + inputFile
	}
	this.inputFile = inputFile
	// see if the file exists
	if _, err := os.Stat(this.inputFile); os.IsNotExist(err) {
		printf("no such file or directory: %s\n", this.inputFile)
		return
	}

	// get the output file name
	print("Enter the output file name (incl. file extension): ")
	outputFile, err := consolereader.ReadString('\n')
	if err != nil {
		println(err)
	}
	outputFile = strings.TrimSpace(outputFile)
	if !strings.Contains(outputFile, pathSep) {
		outputFile = this.toolManager.workingDirectory + outputFile
	}
	rasterType, err := raster.DetermineRasterFormat(outputFile)
	if rasterType == raster.RT_UnknownRaster || err == raster.UnsupportedRasterFormatError {
		outputFile = outputFile + ".tif" // default to a geotiff
	}
	this.outputFile = outputFile

	// get the ln-transform argument
	print("Log-transform the output (T or F)? ")
	lnTransformStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.lnTransform = false
		println(err)
	}

	if len(strings.TrimSpace(lnTransformStr)) > 0 {
		if this.lnTransform, err = strconv.ParseBool(strings.TrimSpace(lnTransformStr)); err != nil {
			this.lnTransform = false
			println(err)
		}
	} else {
		this.lnTransform = false
	}

	// get the perform parallel argument
	print("Perform in parallel (T or F)? ")
	parallelStr, err := consolereader.ReadString('\n')
	if err != nil {
		this.parallel = false
		println(err)
	}

	if len(strings.TrimSpace(parallelStr)) > 0 {
		if this.parallel, err = strconv.ParseBool(strings.TrimSpace(parallelStr)); err != nil {
			this.parallel = false
			println(err)
		}
	} else {
		this.parallel = false
	}

	this.Run()
}