def run(self):
        global activeThreads
        activeThreads += 1

        #################################
        ##### Start here #####
        #################################

        global DEM
        global RASTERSTREAMS_4ha
        global DTW4ha
        global SLOPE
        global SLOPERADIAN
        global SLOPETAN
        global BACKLINK4

        wbt = WhiteboxTools()
        wbt.set_whitebox_dir(wb_dir)

        #Slope Degree
        inputdem = DEM + self.file
        slopedegrees = SLOPE + self.file
        args1 = ['--dem=' + inputdem, '--output=' + slopedegrees]

        #DTW uses a cost distance function with the stream as a source and slope as cost. the slope needs to be the mathematical slope and not slope in degrees.
        radians = SLOPERADIAN + self.file
        args2 = ['--input=' + slopedegrees, '--output=' + radians]
        slopetangens = SLOPETAN + self.file
        args3 = ['--input=' + radians, '--output=' + slopetangens]

        #DTW4ha
        streams = RASTERSTREAMS_4ha + self.file
        dtw4ha = DTW4ha + self.file.replace(
            '.dep', '.tif'
        )  #if you have .dep as input and want .tif as output you can use self.file.replace('.dep', '.tif')
        backlink4ha = BACKLINK4 + self.file
        args4 = [
            '--source=' + streams, '--cost=' + slopetangens,
            '--out_accum=' + dtw4ha, '--out_backlink=' + backlink4ha
        ]

        try:

            wbt.run_tool('Slope', args1, callback)
            wbt.run_tool('ToRadians', args2, callback)
            wbt.run_tool('tan', args3, callback)

            #Cost distance is the final step of DTW
            wbt.run_tool('CostDistance', args4, callback)  #DTW 4ha

        except:
            print('Unexpected error:', sys.exc_info()[0])
            raise
        #################################
        ##### end here #####
        #################################

        activeThreads -= 1
Beispiel #2
0
def main():
    ''' main function
    '''
    try:
        # Set the whitebox-tools executable directory
        # (change this to point to where you have the whitebox-tools.exe file)
        wb_dir = os.path.dirname(
            os.path.abspath(__file__)) + "/target/release/"
        wbt = WhiteboxTools()
        wbt.set_whitebox_dir(wb_dir)

        # Prints the whitebox-tools help...a listing of available commands
        print(wbt.help())

        # Prints the whitebox-tools license
        print(wbt.license())

        # Prints the whitebox-tools version
        print("Version information: {}".format(wbt.version()))

        # List all available tools in whitebox-tools
        print(wbt.list_tools())
        # Lists tools with 'lidar' or 'LAS' in tool name or description.
        print(wbt.list_tools(['lidar', 'LAS']))

        # print(wbt.tool_help("dev_from_mean_elev"))
        print(wbt.tool_help("elev_percentile"))

        # Sets verbose mode (True or False). Most tools will suppress output (e.g. updating
        # progress) when verbose mode is False. The default is True
        # wbt.set_verbose_mode(False)

        # needed to specify complete file names (with paths) to tools that you run.
        wbt.set_working_dir(
            os.path.dirname(os.path.abspath(__file__)) + "/testdata/")

        name = "elev_percentile"
        args = [
            "--input=\"DEM.dep\"", "--output=\"DEV_101.dep\"", "--filter=101"
        ]

        # Run the tool and check the return value
        if wbt.run_tool(name, args, callback) != 0:
            print("ERROR running {}".format(name))

    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
Beispiel #3
0
    def run(self):
        global activeThreads
        activeThreads += 1

        #################################
        ##### Begin here #####
        #################################
        #Set Global variables
        global wb_dir
        global DEMS
        global FilledDEMs


        wbt = WhiteboxTools()
        wbt.set_whitebox_dir(wb_dir)

        #orginal self.files
        originaldems = DEMS + self.file

        #Missing data filled
        filled = FilledDEMs + self.file

        args1 = ['--input="' + originaldems + '"', '--output="' + filled + '"', '--filter="' + '100' + '"', '--weight="' + '2' + '"']


        try:
            wbt.run_tool('FillMissingData', args1, callback)

        except:
            print('Unexpected error:', sys.exc_info()[0])
            raise
        #################################
        ##### End here #####
        #################################

        activeThreads -= 1
Beispiel #4
0
def main():
    ''' main function
    '''
    try:
        wbt = WhiteboxTools()

        # Get the root directory of WhiteboxTools source code or executable file
        root_dir = os.path.dirname(os.path.abspath(__file__))
        # WhiteboxTools executable file name for MS Windows
        wbt_win_bin = os.path.join(root_dir, "whitebox_tools.exe")
        # WhiteboxTools executable file name for MacOS/Linux
        wbt_linux_bin = os.path.join(root_dir, "whitebox_tools")

        # If the WhiteboxTools executable file (whitbox_tools.exe) is in the same
        # directory as this script, set wbt path to the current directory
        # otherwise, set wbt path to (root_dir + "/target/release/")
        if os.path.isfile(wbt_win_bin) or os.path.isfile(wbt_linux_bin):
            wbt.set_whitebox_dir(root_dir)
        else:
            wbt.set_whitebox_dir(root_dir + "/target/release/")  # or simply wbt.exe_path = ...

        # Set the working directory. This is the path to the folder containing the data,
        # i.e. files sent to tools as input/output parameters. You don't need to set
        # the working directory if you specify full path names as tool parameters.
        wbt.work_dir = os.path.dirname(
            os.path.abspath(__file__)) + "/testdata/"

        # If test datasets do not exist, download them from the WhiteboxTools repo
        if not os.path.exists(wbt.work_dir):
            os.mkdir(wbt.work_dir)
            dem_url = "https://github.com/jblindsay/whitebox-tools/raw/master/testdata/DEM.tif"
            dep_url = "https://github.com/jblindsay/whitebox-tools/raw/master/testdata/DEM.dep"
            urllib.request.urlretrieve(dem_url, "testdata/DEM.tif")
            urllib.request.urlretrieve(dep_url, "testdata/DEM.dep")

        # Sets verbose mode (True or False). Most tools will suppress output (e.g. updating
        # progress) when verbose mode is False. The default is True
        # wbt.set_verbose_mode(False) # or simply, wbt.verbose = False

        # The most convenient way to run a tool is to use its associated method, e.g.:
        if wbt.elev_percentile("DEM.tif", "output.tif", 15, 15) != 0:
            print("ERROR running tool")

        # You may also provide an optional custom callback for processing output from the
        # tool. If you don't provide a callback, and verbose is set to True, tool output
        # will simply be printed to the standard output. Also, notice that each tool has a
        # convenience method. While internally, whitebox_tools.exe uses CamelCase (MeanFilter)
        # to denote tool names, but the Python interface of whitebox_tools.py uses
        # snake_case (mean_filter), according to Python style conventions.

        # All of the convenience methods just call the 'run_tool' method, feeding it an
        # args array. This is an alternative way of calling tools:
        tool_name = "elev_percentile"
        args = ["--dem=\"DEM.dep\"",
                "--output=\"DEV_101.dep\"",
                "--filterx=101"]

        if wbt.run_tool(tool_name, args, my_callback) != 0:
            print("ERROR running {}".format(tool_name))

        # Prints the whitebox-tools help...a listing of available commands
        print(wbt.help())

        # Prints the whitebox-tools license
        print(wbt.license())

        # Prints the whitebox-tools version
        print("Version information: {}".format(wbt.version()))

        # List all available tools in whitebox-tools
        print(wbt.list_tools())

        # Lists tools with 'lidar' or 'LAS' in tool name or description.
        print(wbt.list_tools(['lidar', 'LAS']))

        # Print the help for a specific tool.
        print(wbt.tool_help("ElevPercentile"))
        # Notice that tool names within WhiteboxTools.exe are CamelCase but
        # you can also use snake_case here, e.g. print(wbt.tool_help("elev_percentile"))

    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
Beispiel #5
0
'''

import os
import sys
from whitebox_tools import WhiteboxTools

if __name__ == '__main__':

    try:
        wbt = WhiteboxTools()

        root_dir = os.path.dirname(os.path.abspath(__file__))
        # exe_dir = os.path.join(root_dir, "WBT")
        exe_dir = os.path.dirname(os.path.abspath(__file__))

        wbt.set_whitebox_dir(exe_dir)
        wbt.work_dir = os.path.join(root_dir, "testdata")
        wbt.verbose = False

        # Prints the whitebox-tools help...a listing of available commands
        print(wbt.help())
        # Prints the whitebox-tools license
        print(wbt.license())
        # Prints the whitebox-tools version
        print("Version information: {}".format(wbt.version()))
        # List all available tools in whitebox-tools
        print("ALl available tools: {}\n".format(wbt.list_tools()))
        # Lists tools with 'lidar' or 'LAS' in tool name or description.
        print("lidar tools: {}\n".format(wbt.list_tools(['lidar', 'LAS'])))
        # Print the help for a specific tool.
        print(wbt.tool_help("breach_depressions"))
def main():
    """ main function
    """
    try:
        # name = input("Tool name: ") or 'DevFromMeanElev'
        # input_file = input("Input file: ") or 'DEM no OTOs.dep'
        # output_file = input("Output file: ") or 'tmp.dep'
        # filter_size = int(input("Filter size: ") or "101")

        # setup WhiteboxTools
        wbt = WhiteboxTools()

        wb_dir = os.path.dirname(
            os.path.abspath(__file__)) + "/target/release/"
        wbt.set_whitebox_dir(wb_dir)

        # wkdir = "/Users/johnlindsay/Documents/data/GarveyGlenWatershed/"
        # wkdir = "/Users/johnlindsay/Documents/data/DanData/"
        # wkdir = "/Users/johnlindsay/Desktop/WhiteboxGAT-mac/resources/samples/Vermont DEM/"
        wkdir = "Users/johnlindsay/Documents/Data/NewBrunswick/"
        wbt.set_working_dir(wkdir)

        # Tool name and arguments
        # name = "DevFromMeanElev"
        # name = "ElevsPercentile"
        # name = "RelativeTopographicPosition"

        # filter_size = 101
        # args = ["--input=\"DEM no OTOs.dep\"",
        #         "--output=\"tmp33.dep\"",
        #         "--filterx={0}".format(filter_size),
        #         "--filtery={0}".format(filter_size)]

        # args = ["--input=\"{0}\"".format(input_file),
        #         "--output=\"{0}\"".format(output_file),
        #         "--filterx={0}".format(filter_size),
        #         "--filtery={0}".format(filter_size)]

        # args = ["--input=\"DEM.dep\"",
        #         "--output=\"tmp33.dep\"",
        #         "--filterx=101",
        #         "--filtery=101"]

        # name = "RemoveOffTerrainObjects"
        # args = ["--input=\"DEM no OTOs.dep\"",
        #         "--output=\"tmp34.dep\"",
        #         "--filter=10",
        #         "--slope=10.0"]

        # name = "LidarInfo"
        # args = ["--input=\"points.las\"",
        #         "--vlr",
        #         "--geokeys"]

        # name = "LidarHillshade"
        # args = ["--input=\"RGB_5_529_150502_1754__0_270112_2848.las\"",
        #         "--output=\"hillshade2.las\"",
        #         "--azimuth=315.0",
        #         "--altitude=30.0",
        #         "--radius=2.5"]

        # name = "LidarTophatTransform"
        # args = ["--input=\"RGB_5_529_150502_1754__0_270112_2848.las\"",
        #         "--output=\"filtered12m_RGB_5_529_150502_1754__0_270112_2848.las\"",
        #         "--radius=12.0"]

        def custom_callback(value):
            ''' A custom callback for dealing with tool output.
            '''
            if not hasattr(custom_callback, 'prev_line_progress'):
                custom_callback.prev_line_progress = False
            if not hasattr(custom_callback, 'prev_line_len'):
                custom_callback.prev_line_len = -1
            if "%" in value:
                # wbt.cancel_op = True
                if custom_callback.prev_line_progress:
                    if len(value) < custom_callback.prev_line_len:
                        print('                                   ', end="\r")
                    print('{0}'.format(value), end="\r")
                else:
                    custom_callback.prev_line_progress = True
                    print(value)
            else:
                if custom_callback.prev_line_progress:
                    print('\n{0}'.format(value))
                    custom_callback.prev_line_progress = False
                else:
                    print(value)

            custom_callback.prev_line_len = len(value)

        # file_names = ["RGB_3_529_150514_1353__0_294688_2784.las",
        #               "RGB_3_529_150514_1353__0_276256_2784.las"]

        # filter_size = 18.0

        # for file_name in file_names:
        #     name = "LidarGroundPointFilter"
        #     args = ["--input=\"{0}\"".format(file_name),
        #             "--output=\"filtered{0}m_{1}\"".format(
        #                 str(filter_size).replace(".", "_"), file_name),
        #             "--radius={0}".format(filter_size),
        #             "--otoheight=0.75"]

        #     # Run the tool and check the return value
        #     ret = wbt.run_tool(name, args, custom_callback)
        #     if ret == 1:
        #         print("ERROR running {}".format(name))
        #     elif ret == 2:
        #         print("Operation cancelled while running {}".format(name))

        # name = "FillMissingData"
        # args = ["--input=\"mosaic_FR.dep\"",
        #         "--output=\"tmp1.dep\"",
        #         "--filter=41"]

        # name = "RemoveOffTerrainObjects"
        # args = ["--input=\"tmp1_clipped.dep\"",
        #         "--output=\"mosaic_FR no OTOs4.dep\"",
        #         "--filter=251",
        #         "--slope=10.0"]

        # name = "Hillshade"
        # args = ["--input=\"tmp10.dep\"",
        #         "--output=\"tmp11.dep\"",
        #         "--azimuth=315.0",
        #         "--altitude=20.0"]

        # name = "D8FlowAccumulation"
        # args = ["--input=\"DEM final.dep\"",
        #         "--output=\"tmp13.dep\"",
        #         "--out_type=\"cells\"",
        #         "--log"]

        # name = "BufferRaster"
        # args = ["--input=\"tmp11.dep\"",
        #         "--output=\"tmp12.dep\"",
        #         "--size=450",
        #         "--gridcells"]

        # name = "Quantiles"
        # args = ["--input=\"DEM final.dep\"",
        #         "--output=\"tmp10.dep\"",
        #         "--num_quantiles=15"]

        # name = "Clump"
        # args = ["--input=\"tmp10.dep\"",
        #         "--output=\"tmp15.dep\""]

        # name = "Clump"
        # args = ["--input=\"tmp12.dep\"",
        #         "--output=\"tmp16.dep\"",
        #         "--diag",
        #         "--zero_back"]

        # name = "DevFromMeanElev"
        # args = ["--input=\"Rel_Low_Denoised.dep\"",
        #         "--output=\"tmp6.dep\"",
        #         "--filter=411"]

        name = "MaxElevationDeviation"
        args = [
            "--dem='alosDEM1.dep'", "--out_mag='mag1.dep'",
            "--out_scale='scale1.dep'", "--min_scale=15", "--max_scale=60",
            "--step=5"
        ]

        # Run the tool and check the return value
        ret = wbt.run_tool(name, args, custom_callback)
        if ret == 1:
            print("ERROR running {}".format(name))
        elif ret == 2:
            print("Operation cancelled while running {}".format(name))

        # app = SampleApp()
        # app.mainloop()

    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
from __future__ import print_function
import threading
import time
import os
import sys

sys.path.insert(1, r'D:\\WAMBAF\\WhiteboxTools_win_amd64\WBT'
                )  #This is where whitebox tools is located on my computer

from whitebox_tools import WhiteboxTools

#wb_dir = os.path.dirname('V:/JohannesLarson/WhiteboxTools_win_amd64/WBT/') #This is where whitebox tools is located on my computer
wb_dir = os.path.dirname('D:\\WAMBAF\\WhiteboxTools_win_amd64\WBT\\')

wbt = WhiteboxTools()
wbt.set_whitebox_dir(wb_dir)

#input folders
#DEM = 'Z:/RIP_WAM/TLW/newProcessing/BreachedDEM/'

#data1
DEM = 'G:/wambaf_06_2020/FeatureExtraction/Breached/'

#RASTERSTREAMS_4ha = 'Z:/RIP_WAM/TLW/newProcessing/RasterStreams/4ha/'

RASTERSTREAMS_4ha = 'G:/wambaf_06_2020/FeatureExtraction/rasterstreams/5ha'

#Output folders

#SLOPE = 'Z:/RIP_WAM/TLW/newProcessing/DTW/SLOPE/' #Gallant, J. C., and J. P. Wilson, 2000, Primary topographic attributes, in Terrain Analysis: Principles and Applications, edited by J. P. Wilson and J. C. Gallant pp. 51-86, John Wiley, Hoboken, N.J.
#SLOPERADIAN = 'Z:/RIP_WAM/TLW/newProcessing/DTW/SLOPERADIAN/'
Beispiel #8
0
    def run(self):
        global activeThreads
        activeThreads += 1

        #################################
        ##### Begin here #####
        #################################
        #Set Global variables
        global wb_dir
        global DEMS
        global BREACHED
        global POINTER
        global FLOWACC
        global RASTERSTREAMS_1ha
        global RASTERSTREAMS_5ha
        global RASTERSTREAMS_10ha
        global RASTERSTREAMS_20ha

        wbt = WhiteboxTools()
        wbt.set_whitebox_dir(wb_dir)

        #orginal self.files
        originaldems = DEMS + self.file

        #Breach
        breachout = BREACHED + self.file
        args1 = ['--input="' + originaldems + '"', '--output="' + breachout + '"', '--max_depth="' + '5' + '"']

        #Flowpopinter
        pointerout = POINTER + self.file
        args2 = ['--dem="' + breachout + '"', '--output="' + pointerout + '"']

        #Flowaccumulation from DEM (not from pointer)
        Flowaccout = FLOWACC + self.file
        args3 = ['--dem="' + breachout + '"', '--output="' + Flowaccout + '"', '--out_type="' + 'Cells"' + '"']

        #Extract raster streams for four different stream initation thresholds
        #1ha Stream network
        Streamsout1ha = RASTERSTREAMS_1ha + self.file
        args4 = ['--flow_accum="' + Flowaccout + '"',  '--output="' + Streamsout1ha + '"', '--threshold="' + '2500.0"' + '"', '--zero_background"']
        #5ha Stream network
        Streamsout5ha = RASTERSTREAMS_5ha + self.file
        args5 = ['--flow_accum="' + Flowaccout + '"',  '--output="' + Streamsout5ha + '"', '--threshold="' + '12500.0"' + '"', '--zero_background"']
        #10ha Stream network
        Streamsout10ha = RASTERSTREAMS_10ha + self.file
        args6 = ['--flow_accum="' + Flowaccout + '"',  '--output="' + Streamsout10ha + '"', '--threshold="' + '25000.0"' + '"', '--zero_background"']
        #20ha Stream network
        Streamsout20ha = RASTERSTREAMS_20ha + self.file
        args7 = ['--flow_accum="' + Flowaccout + '"',  '--output="' + Streamsout20ha + '"', '--threshold="' + '50000.0"' + '"', '--zero_background"']
        
        try:
            wbt.run_tool('BreachDepressions', args1, callback)
            wbt.run_tool('D8Pointer', args2, callback)
            wbt.run_tool('D8FlowAccumulation', args3, callback)
            wbt.run_tool('ExtractStreams', args4, callback)
            wbt.run_tool('ExtractStreams', args5, callback)
            wbt.run_tool('ExtractStreams', args6, callback)
            wbt.run_tool('ExtractStreams', args7, callback)
            

        except:
            print('Unexpected error:', sys.exc_info()[0])
            raise
        #################################
        ##### End here #####
        #################################

        activeThreads -= 1