Ejemplo 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
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