Esempio n. 1
0
def pipes_to_raster_00(in_pipe_path, in_dem_path):
    """Converts the pipes feature to a raster.

    Rasterized culvert lines will be 1 cell wide, with the same cell size as the raster.

    Parameters
    ----------
    in_pipe_path: str
        Path to the pipe file to buffer
    in_dem_path: str
        Path to the base DEM

    Returns
    --------
    output_path: str
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    # Create pipe raster file
    output_path = new_file_00(in_pipe_path, "PIPR", "tif")
    wbt.vector_lines_to_raster(in_pipe_path,
                               output_path,
                               field="FID",
                               nodata=True,
                               base=in_dem_path)

    return output_path
Esempio n. 2
0
def breach_depressions_00(in_dem_path, breach_dist='20'):
    """Runs whitebox breach_depressions_least_cost tool

    Parameters
    ----------
    in_dem_path: str
        Path to the DEM
    breach_dist: str, optional
        Search radius

    Returns
    --------
    output_path: str
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    out_group = new_group_00(in_dem_path)
    output_path = new_file_00(in_dem_path, "DEM", "tif", out_group)

    wbt.breach_depressions_least_cost(in_dem_path,
                                      output_path,
                                      breach_dist,
                                      fill=True)
    # TODO: Add max_cost parameter for DEMs with quarries?

    return output_path
Esempio n. 3
0
def zone_min_00(in_dem_path, in_zones_path):
    """Set cells in culvert zones to the min elevation for the zone.

    Parameters
    -----------
    in_dem_path: str
        Path to input DEM file
    in_zones_path: str
        Path to culvert raster file

    Returns
    -------
    output_path: str
    """
    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    output_path = new_file_00(in_zones_path, "MIN", "tif")
    wbt.zonal_statistics(in_dem_path,
                         in_zones_path,
                         output_path,
                         stat="minimum",
                         out_table=None)

    return output_path
Esempio n. 4
0
def extend_pipes_00(in_pipe_path, dist='20.0'):
    """Extends individual culvert lines at each end.

    The culvert lines in the original files don't always extend across the
    road fill area on the DEM.

    Parameters
    -----------
    in_pipe_path: str
        Path to pipe file.
    dist: str, optional
        Distance to extend each line in both directions.

    Returns
    -------
    output_path: str

    """
    from WBT.whitebox_tools import WhiteboxTools

    wbt = WhiteboxTools()

    output_path = new_file_00(in_pipe_path, "XTPIPE", "shp")
    wbt.extend_vector_lines(in_pipe_path, output_path, dist)

    return output_path
Esempio n. 5
0
def merge_pipes_00(in_pipe_paths):
    """Merges culvert features from multiple files.

    The merged culvert file will be saved in a new Hydro_Route group.

    Parameters
    ----------
    in_pipe_paths: list of str
        List of pipe files to merge. Pipe files should already be clipped to basin extent. (If not, run extract_pipes_00 first.)

    Returns
    --------
    output_path: str
    """
    from pathlib import Path

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    last_pipe = Path(in_pipe_paths[-1])

    out_group = new_group_01(str(last_pipe.parent.parent),
                             last_pipe.stem.split('_')[1], "PIPES")
    output_path = new_file_00(str(last_pipe), "PIPES", "shp", str(out_group))

    wbt.merge_vectors(';'.join(in_pipe_paths), output_path)

    return output_path
Esempio n. 6
0
def extend_pipes_00(in_pipe_path, dist='10.0'):
    """ Extend individual culvert lines at each end, by the specified distance.
    Parameters
    ----------
    in_pipe_path : str
        Path to pipe file
    dist : str
        Distance to extend each line in both directions
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    output_path = out_file_00(in_pipe_path, "XTPIPE", "shp")
    wbt.extend_vector_lines(in_pipe_path, output_path, dist)

    return output_path
Esempio n. 7
0
def breach_depressions_00(in_dem_path, breach_dist):
    """
    Parameters
    ----------
    in_dem_path : str
        Path to the DEM
    breach_dist : str
        Max distance to breach
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    out_group = new_group_00(in_dem_path)
    out_path = out_file_00(in_dem_path, "DEM", "tif", out_group)

    wbt.breach_depressions_least_cost(in_dem_path, out_path, breach_dist)
Esempio n. 8
0
def merge_pipes_00(in_pipe_paths):
    """ Merge culvert features from multiple files
    Parameters
    ----------
    in_pipe_paths : list
        List of pipe files to merge
    """

    from WBT.whitebox_tools import WhiteboxTools

    wbt = WhiteboxTools()

    out_group = new_group_00(in_pipe_paths[-1])
    output_path = out_file_00(in_pipe_paths[-1], "PIPES", "shp", out_group)

    wbt.merge_vectors(';'.join(in_pipe_paths), output_path)

    return output_path
Esempio n. 9
0
def zone_min_00(in_dem_path, in_zones_path):
    """
    Parameters
    ----------
    in_dem_path : str
        Path to input DEM file
    in_zones_path : str
        Path to culvert raster file
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    output_path = out_file_00(in_zones_path, "MIN", "tif")
    wbt.zonal_statistics(in_dem_path,
                         in_zones_path,
                         output_path,
                         stat="minimum",
                         out_table=None)

    return output_path
Esempio n. 10
0
def burn_min_00(in_dem_path, in_zones_path):
    """
    Parameters
    ----------
    in_dem_path : str
        Path to the DEM input file
    in_zones_path : str
        Path to raster file resulting from zonal statistics minimum tool
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    out_group = new_group_00(in_dem_path)

    # Create position raster
    pos_path = out_file_00(in_dem_path, "POS", "tif", out_group)
    wbt.is_no_data(in_zones_path, pos_path)

    new_dem_path = out_file_00(in_dem_path, "DEM", "tif", out_group)

    inputs = "{};{}".format(in_zones_path, in_dem_path)

    # If position (isnodata) file = 0, use value from zones. If = 1, use value from dem.
    wbt.pick_from_list(inputs, pos_path, new_dem_path)

    return new_dem_path
Esempio n. 11
0
def clip_pipes_00(in_pipe_path, dem_path):
    """Clips a statewide culvert shapefile to the extent of a raster file.

    Parameters
    -----------
    in_pipe_path: str
        Path to full culvert file
    dem_path: str
        Path to DEM .tif file

    Returns
    -------
    out_file: str
    """

    from pathlib import Path

    from WBT.whitebox_tools import WhiteboxTools

    wbt = WhiteboxTools()

    dem = Path(dem_path)
    source_string = dem.stem.split("_")[0]
    huc_dir = dem.parent.parent.parent
    box = new_file_00(dem_path, "BOX", ".shp")

    # Create vector bounding box
    wbt.layer_footprint(dem_path, str(box))

    # Create new pipe group
    pipe_group = new_group_01(str(huc_dir / "Hydro_Route"), source_string,
                              "PIPES")
    out_file = new_file_00(dem_path, "PIPES", "shp", pipe_group)

    # Clip pipe file to bounding box
    wbt.clip(in_pipe_path, str(box), str(out_file))

    return out_file
Esempio n. 12
0
def burn_min_00(in_dem_path, in_zones_path):
    """Creates a new DEM with culvert zones burned in.

    Uses culvert zone minimum values where they exist and values from the
    original DEM file everywhere else.

    Parameters
    -----------
    in_dem_path: str
        Path to the DEM input file
    in_zones_path: str
        Path to raster file resulting from zonal statistics minimum tool

    Returns
    -------
    output_path: str
    """

    from WBT.whitebox_tools import WhiteboxTools
    wbt = WhiteboxTools()

    out_group = new_group_00(in_dem_path)

    # Create position raster
    pos_path = new_file_00(in_dem_path, "POS", "tif", out_group)
    wbt.is_no_data(in_zones_path, pos_path)

    output_path = new_file_00(in_dem_path, "DEM", "tif", out_group)

    inputs = "{};{}".format(in_zones_path, in_dem_path)

    # If position (isnodata) file = 0, use value from zones. If = 1,
    # use value from dem.
    wbt.pick_from_list(inputs, pos_path, output_path)

    return output_path
Esempio n. 13
0
import os
import sys
import time
from WBT.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()

work_dir = os.path.dirname(os.path.abspath(__file__))
wb_dir = work_dir + "/WBT"
data_dir = work_dir + "/data"
out_dir = work_dir + "/out"

wbt.set_whitebox_dir(wb_dir)

omr = '925'


def run():
    outfile = f'{out_dir}/basins/{omr}.tif'
    wbt.basins(f'{data_dir}/D8_Pointer/{omr}.dep', outfile)
    add_srs = f'gdal_edit.py -a_srs EPSG:3006 {outfile}'
    print(add_srs)
    os.system(add_srs)


start = time.time()
run()
end = time.time()
print(end - start)
Esempio n. 14
0
import os
import sys
from WBT.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()

work_dir = os.path.dirname(os.path.abspath(__file__))

wbt.set_whitebox_dir(os.path.dirname(os.path.abspath(__file__)) + "/WBT/")


def convert(wbt_work_dir):
    wbt.work_dir = wbt_work_dir

    wbt.convert_raster_format('824.dep', '824.tif')


convert(os.path.join(work_dir, 'data', 'Breached_DEMs'))
convert(os.path.join(work_dir, 'data', 'D8_Flowacc'))
convert(os.path.join(work_dir, 'data', 'D8_Pointer'))
Esempio n. 15
0
    # image3.plot()
    # plt.show()
    image3 = image2.rio.reproject_match(image3)
    print('image2.shape:  ', image2.shape)
    print('image3.shape:  ', image3.shape)
    # plt.figure()
    # destination.plot(robust=True)
    #  plt.show()

    image2 = False
    #image3=False
    return image3


if __name__ == "__main__":
    wbt = WhiteboxTools()
    wbt.set_verbose_mode(True)
    name = 'Kalimantan'
    file1 = "KalimantanFINAL_classified_by_ensemble_rf.tif"
    year = 2017
    base_dir = dir.guess_data_dir()
    wbt.work_dir = os.path.join(base_dir, name, 'sklearn_test', str(year),
                                'test_temp', 'wkdir')
    # wbt.majority_filter(file, "Kalimantan2018_Final_smooth3x3.tif", filterx=3, filtery=3)
    #
    base = os.path.join(base_dir, name, 'sklearn_test', str(year), 'test_temp',
                        'Kalimantan2017_Final_100m.tif')
    out1 = "resample2017.tif"
    out2 = "round2017.tif"
    wbt.resample(file1, out1, "cc", base=base)
    wbt.round(out1, out2)
Esempio n. 16
0
import os
import sys
import time
from WBT.whitebox_tools import WhiteboxTools
import subprocess

def add_srs_raster(file, epsg=3006):
    subprocess.run(['gdal_edit.py', '-a_srs', f'EPSG:{epsg}', file])

def add_srs_vector(file, epsg=3006):
    split = file.split('.')
    split[0] += f'_{epsg}'
    newfile = '.'.join(split)
    subprocess.run(['ogr2ogr', '-a_srs', f'EPSG:{epsg}', newfile, file])

wbt = WhiteboxTools()

work_dir = os.path.dirname(os.path.abspath(__file__))
wb_dir = work_dir + "/WBT"
data_dir = "/home/johnnie/kod/flodesapp/localdata/geodata"
out_dir = data_dir + "/out/hierarki_riks_50m"

wbt.set_whitebox_dir(wb_dir)

d8_pntr = f'{data_dir}/out/flowacc_riks_50m/pntr.tif'
flowacc = f'{data_dir}/out/flowacc_riks_50m/accum.tif'

streams = f'{out_dir}/streams.tif'
wbt.greater_than(
    flowacc,
    10000,
# from __future__ import print_function
from WBT.whitebox_tools import WhiteboxTools, to_camelcase
wbt = WhiteboxTools()
"""
This script is just used to automatically generate the documentation for each
of the plugin tools in the WhiteboxTools User Manual. It should be run each time new
tools are added to WhiteboxTools.exe and before a public release.
"""
import os
from os import path
import re
import json
import sys
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

_underscorer1 = re.compile(r'(.)([A-Z][a-z]+)')
_underscorer2 = re.compile('([a-z0-9])([A-Z])')


def camel_to_snake(s):
    subbed = _underscorer1.sub(r'\1_\2', s)
    return _underscorer2.sub(r'\1_\2', subbed).lower()


def to_camelcase(name):
    '''
    Convert snake_case name to CamelCase name
    '''
    return ''.join(x.title() for x in name.split('_'))

Esempio n. 18
0
import os
from WBT.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()

# Set the working directory, i.e. the folder containing the data,
# to the 'data' sub-directory.
wbt.set_working_dir(os.path.dirname(os.path.abspath(__file__)) + "/data/")

# When you're running mulitple tools, the outputs can be a tad
# chatty. In this case, you may want to suppress the output by
# setting the verbose mode to False.
# wbt.set_verbose_mode(False)

# Interpolate the LiDAR data using an inverse-distance weighting
# (IDW) scheme.
print("Interpolating DEM...")
wbt.lidar_idw_interpolation(
i="wb_test1.las",
output="raw_dem.tif",
parameter="elevation",
returns="last",
resolution=1.0,
weight=1.0,
radius=2.5
)

# The resulting DEM will contain NoData gaps. We need to fill
# these in by interpolating across the gap.
print("Filling missing data...")
wbt.fill_missing_data(
import arcpy
import os
import webbrowser
from WBT.whitebox_tools import WhiteboxTools
if sys.version_info < (3, 0):
    from StringIO import StringIO
else:
    from io import StringIO

wbt = WhiteboxTools()
tool_labels = []

tool_labels.append("Absolute Value")
tool_labels.append("Adaptive Filter")
tool_labels.append("Add")
tool_labels.append("Add Point Coordinates To Table")
tool_labels.append("Aggregate Raster")
tool_labels.append("And")
tool_labels.append("Anova")
tool_labels.append("Arc Cos")
tool_labels.append("Arc Sin")
tool_labels.append("Arc Tan")
tool_labels.append("Arcosh")
tool_labels.append("Arsinh")
tool_labels.append("Artanh")
tool_labels.append("Ascii To Las")
tool_labels.append("Aspect")
tool_labels.append("Atan2")
tool_labels.append("Attribute Correlation")
tool_labels.append("Attribute Correlation Neighbourhood Analysis")
tool_labels.append("Attribute Histogram")
from WBT.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()

# since i=none, our input will be everything in the working directory
wbt.set_working_dir("E:\\guelphAreaProject\\lasDir\\"
                    )  #select directory containing LAS files of interest

wbt.lidar_tile_footprint(  #this will create a polygon of a grid of square km tiles
    output=
    "E:\\guelphAreaProject\\grid.shp",  #choose output directory and file name
)