Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
        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"))
        # Notice that tool names within WhiteboxTools.exe are CamelCase but
        # you can also use snake_case here, e.g. print(wbt.tool_help("breach_depressions"))

        # Call some tools, do some work
        wbt.feature_preserving_smoothing("DEM.tif", "smoothed.tif", filter=9)
        wbt.breach_depressions("smoothed.tif", "breached.tif")
        wbt.d_inf_flow_accumulation("breached.tif", "flow_accum.tif")

    except: