Skip to content

lazer.lastools

LAStools is a set of point cloud processing tools for analyzing LiDAR data. We use LAStools to convert point clouds to metrics of vegetation structure, like canopy height, canopy cover, and canopy base height.

This module contains wrappers for calling LAStools command line executables from python. These wrappers include a series of default parameter settings and a list of explanations guiding the use of each executable.

LAStools is provided as windows exe files, which we run using wine, a tool for running windows applications on unix systems.

Environment variables

You have to download the LAStools executables to call these functions, then tell lazer where they're located on your system. You do the latter by setting the LTBASE environment variable.

LTBASE=/home/$USR/src/LAStoools/bin

You can set the path to the directory with the lastools executables in ~/.bashrc or anywhere else you set environment variables.


Routines for calling lastools executables.

blast2dem(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension='_dem', otif=True, step=2.0, nodata=-9999, ground=False, use_tile_bb=True, drop_above=None, cores=4, misc=None)

Interpolates, grids and rasterizes las files out of core.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output dem raster file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

'_dem'
step float

raster grid size in geographic units.

2.0
nodata float

raster value where no points are found.

-9999
ground bool

create dem using only ground points.

False
otif bool

set output to tif format.

True
use_tile_bb bool

output a grid only to the extent of the tile.

True
drop_above float

exclude points above this height.

None
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def blast2dem(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = "_dem",
    otif: bool = True,
    step: float = 2.0,
    nodata: float = defaults.nodata,
    ground: bool = False,
    use_tile_bb: bool = True,
    drop_above: float = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Interpolates, grids and rasterizes las files out of core.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output dem raster file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        step: raster grid size in geographic units.
        nodata: raster value where no points are found.
        ground: create dem using only ground points.
        otif: set output to tif format.
        use_tile_bb: output a grid only to the extent of the tile.
        drop_above: exclude points above this height.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-step {step}")
    param_list.append(f"-nodata {nodata}")
    param_list.append(f"-cores {cores}")
    if ground:
        param_list.append("-keep_class 2")
    if otif:
        param_list.append("-otif")
    if use_tile_bb:
        param_list.append("-use_tile_bb")
    if drop_above:
        param_list.append(f"-drop_above {drop_above:0.3f}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.blast2dem} {parameters}"

    _logger.debug("Running blast2dem")
    message = run_command_line(command)

    return message

las2dem(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension='_dem', otif=True, step=2.0, nodata=-9999, ground=False, use_tile_bb=False, drop_above=None, cores=4, misc=None)

Interpolates, grids and rasterizes las files.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output dem raster file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

'_dem'
step float

raster grid size in geographic units.

2.0
nodata float

raster value where no points are found.

-9999
ground bool

create dem using only ground points.

False
otif bool

set output to tif format.

True
use_tile_bb bool

output a grid only to the extent of the tile.

False
drop_above float

exclude points above this height.

None
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def las2dem(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = "_dem",
    otif: bool = True,
    step: float = 2.0,
    nodata: float = -9999,
    ground: bool = False,
    use_tile_bb: bool = False,
    drop_above: float = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Interpolates, grids and rasterizes las files.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output dem raster file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        step: raster grid size in geographic units.
        nodata: raster value where no points are found.
        ground: create dem using only ground points.
        otif: set output to tif format.
        use_tile_bb: output a grid only to the extent of the tile.
        drop_above: exclude points above this height.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-step {step}")
    param_list.append(f"-cores {cores}")
    if nodata is not None:
        param_list.append(f"-nodata {nodata}")
    if ground:
        param_list.append("-keep_class 2")
    if otif:
        param_list.append("-otif")
    if use_tile_bb:
        param_list.append("-use_tile_bb")
    if drop_above:
        param_list.append(f"-drop_above {drop_above:0.3f}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.las2dem} {parameters}"

    _logger.debug("Running las2dem")
    message = run_command_line(command)

    return message

las2las(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, olaz=True, epsg=None, target_utm=None, target_epsg=None, target_latlong=False, target_meter=False, target_feet=False, target_survey_feet=False, target_elevation_meter=False, target_elevation_feet=False, target_elevation_survey_feet=False, elevation_meter=False, elevation_feet=False, elevation_survey_feet=False, meter=False, feet=False, survey_feet=False, target_precision=None, target_elevation_precision=None, wgs84=False, keep_class=None, drop_above=None, cores=4, misc=None)

Reprojects, compresses, rescales, and otherwise converts las files.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output las file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
olaz bool

set output to laz format.

True
epsg int

input EPSG code.

None
target_utm str

output UTM zone, in {zone}{letter} format (e.g. '12T').

None
target_epsg int

output EPSG code (e.g. 32610 for UTM 10 north).

None
target_latlong bool

convert to latitude/longitude.

False
target_meter bool

convert horizontal datum to meters.

False
target_feet bool

convert horizontal datum to feet.

False
target_survey_feet bool

convert horizontal datum to survey feet.

False
target_elevation_meter bool

convert vertical datum to meters.

False
target_elevation_feet bool

convert vertical datum to feet.

False
target_elevation_survey_feet bool

convert vertical datum to survey feet.

False
meter bool

posit that input data are measured in meters.

False
feet bool

posit that input data are measured in feet.

False
survey_feet bool

posit that input data are measured in survey feet.

False
target_precision float

horizontal resolution precision (x/y) when reprojecting. Use 0.1 to set to 10cm precision.

None
target_elevation_precision float

vertical resolution precision (z) when reprojecting.

None
wgs84 bool

use the wgs84 ellipsoid.

False
keep_class list

a list of classes to keep when converting data.

None
drop_above float

exclude points above this height.

None
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def las2las(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    olaz: bool = True,
    epsg: int = None,
    target_utm: str = None,
    target_epsg: int = None,
    target_latlong: bool = False,
    target_meter: bool = False,
    target_feet: bool = False,
    target_survey_feet: bool = False,
    target_elevation_meter: bool = False,
    target_elevation_feet: bool = False,
    target_elevation_survey_feet: bool = False,
    elevation_meter: bool = False,
    elevation_feet: bool = False,
    elevation_survey_feet: bool = False,
    meter: bool = False,
    feet: bool = False,
    survey_feet: bool = False,
    target_precision: float = None,
    target_elevation_precision: float = None,
    wgs84: bool = False,
    keep_class: list = None,
    drop_above: float = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Reprojects, compresses, rescales, and otherwise converts las files.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output las file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        olaz: set output to laz format.
        epsg: input EPSG code.
        target_utm: output UTM zone, in {zone}{letter} format (e.g. '12T').
        target_epsg: output EPSG code (e.g. 32610 for UTM 10 north).
        target_latlong: convert to latitude/longitude.
        target_meter: convert horizontal datum to meters.
        target_feet: convert horizontal datum to feet.
        target_survey_feet: convert horizontal datum to survey feet.
        target_elevation_meter: convert vertical datum to meters.
        target_elevation_feet: convert vertical datum to feet.
        target_elevation_survey_feet: convert vertical datum to survey feet.
        meter: posit that input data are measured in meters.
        feet: posit that input data are measured in feet.
        survey_feet: posit that input data are measured in survey feet.
        target_precision: horizontal resolution precision (x/y) when reprojecting. Use 0.1 to set to 10cm precision.
        target_elevation_precision: vertical resolution precision (z) when reprojecting.
        wgs84: use the wgs84 ellipsoid.
        keep_class: a list of classes to keep when converting data.
        drop_above: exclude points above this height.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if olaz:
        param_list.append("-olaz")
    if epsg:
        param_list.append(f"-epsg {epsg}")
    if target_utm:
        param_list.append(f"-target_utm {target_utm}")
    if target_epsg:
        param_list.append(f"-target_epsg {target_epsg}")
    if target_latlong:
        param_list.append("-target_latlong")
    if wgs84:
        param_list.append("-wgs84")

    if target_meter:
        param_list.append("-target_meter")
    elif target_feet:
        param_list.append("-target_feet")
    elif target_survey_feet:
        param_list.append("-target_survey_feet")

    if target_elevation_meter:
        param_list.append("-target_elevation_meter")
    elif target_elevation_feet:
        param_list.append("-target_elevation_feet")
    elif target_elevation_survey_feet:
        param_list.append("-target_elevation_survey_feet")

    if meter:
        param_list.append("-meter")
    elif feet:
        param_list.append("-feet")
    elif survey_feet:
        param_list.append("-survey_feet")

    if target_precision:
        param_list.append(f"-target_precision {target_precision}")
    if target_elevation_precision:
        param_list.append(f"-target_elevation_precision {target_elevation_precision}")
    if drop_above:
        param_list.append(f"-drop_above {drop_above:0.3f}")
    if keep_class:
        classes = " ".join(map(str, keep_class))
        param_list.append(f"-keep_class {classes}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.las2las} {parameters}"

    _logger.debug("Running las2las")
    message = run_command_line(command)

    return message

lascanopy(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, otif=True, step=10.0, nodata=-9999, veg=False, min=False, max=False, avg=False, std=False, ske=False, kur=False, cov=False, dns=False, gap=False, cover_cutoff=None, height_cutoff=None, count=None, density=None, fractions=False, use_tile_bb=False, merged=False, files_are_plots=False, loc=None, cores=4, misc=None)

Rasterizes forest canopy metrics from z-values. Must be run using height-normalized las data.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output vegetation raster file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
otif bool

set output to tif format.

True
step float

the grid size of the output raster in geographic units.

10.0
nodata float

assign this value where no points are found.

-9999
veg bool

computes metrics using only the vegetation las classes (2, 3, 4, 5).

False
min bool

calculate z value minimum per step

False
max bool

calculate z value maximum per step

False
avg bool

calculate z value average per step

False
std bool

calculate z value standard deviation per step

False
ske bool

calculate z value skewness per step

False
kur bool

calculate z value kurtosis per step

False
cov bool

calculate canopy cover as 100 * (n_first_returns > cov_cutoff) / n_first_returns.

False
dns bool

calculate canopy density as 100 * (n_returns > cov_cutoff) / n_returns.

False
gap bool

calculate canopy gaps as the inverse of canopy cover or density. set either cov=True or dns=True to define which gap calculation to use.

False
cover_cutoff float

height threshold for computing cover.

None
height_cutoff float

maximum height to include in calculations.

None
count list

counts number of points within the list of intervals provided. count = [2, 4, 6, 8] will produce three rasters in intervals [2,4), [4, 6), [6, 8)

None
density list

similar to count, but returns normalized point density instead of point counts.

None
use_tile_bb bool

do not write data from the tile buffer.

False
merged bool

merge multiple input files to a single laz file before calculations.

False
files_are_plots bool

compute metrics for the full las file instead of gridding the output with -step.

False
loc str

path to an ascii file with locations to compute metrics, where each line is [center_x, center_y, radius].

None
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lascanopy(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    otif: bool = True,
    step: float = defaults.slicer_resolution,
    nodata: float = defaults.nodata,
    veg: bool = False,
    min: bool = False,
    max: bool = False,
    avg: bool = False,
    std: bool = False,
    ske: bool = False,
    kur: bool = False,
    cov: bool = False,
    dns: bool = False,
    gap: bool = False,
    cover_cutoff: float = None,
    height_cutoff: float = None,
    count: list = None,
    density: list = None,
    fractions: bool = False,
    use_tile_bb: bool = False,
    merged: bool = False,
    files_are_plots: bool = False,
    loc: str = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Rasterizes forest canopy metrics from z-values. Must be run using height-normalized las data.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output vegetation raster file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        otif: set output to tif format.
        step: the grid size of the output raster in geographic units.
        nodata: assign this value where no points are found.
        veg: computes metrics using only the vegetation las classes (2, 3, 4, 5).
        min: calculate z value minimum per step
        max: calculate z value maximum per step
        avg: calculate z value average per step
        std: calculate z value standard deviation per step
        ske: calculate z value skewness per step
        kur: calculate z value kurtosis per step
        cov: calculate canopy cover as 100 * (n_first_returns > cov_cutoff) / n_first_returns.
        dns: calculate canopy density as 100 * (n_returns > cov_cutoff) / n_returns.
        gap: calculate canopy gaps as the inverse of canopy cover or density.
            set either `cov=True` or `dns=True` to define which gap calculation to use.
        cover_cutoff: height threshold for computing cover.
        height_cutoff: maximum height to include in calculations.
        count: counts number of points within the list of intervals provided.
            count = [2, 4, 6, 8] will produce three rasters in intervals [2,4), [4, 6), [6, 8)
        density: similar to count, but returns normalized point density instead of point counts.
        use_tile_bb: do not write data from the tile buffer.
        merged: merge multiple input files to a single laz file before calculations.
        files_are_plots: compute metrics for the full las file instead of gridding the output with -step.
        loc: path to an ascii file with locations to compute metrics, where each line is [center_x, center_y, radius].
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if nodata is not None:
        param_list.append(f"-nodata {nodata}")
    if otif:
        param_list.append("-otif")
    if step:
        param_list.append(f"-step {step}")
    if veg:
        param_list.append("-keep_class 1 2 3 4 5")
    if min:
        param_list.append("-min")
    if max:
        param_list.append("-max")
    if avg:
        param_list.append("-avg")
    if std:
        param_list.append("-std")
    if ske:
        param_list.append("-ske")
    if kur:
        param_list.append("-kur")
    if cov:
        param_list.append("-cov")
        param_list.append(f"-cover_cutoff {cover_cutoff}")
    elif dns:
        param_list.append("-dns")
        param_list.append(f"-cover_cutoff {cover_cutoff}")
    if gap:
        param_list.append("-gap")
    if height_cutoff:
        param_list.append(f"-height_cutoff {height_cutoff}")
    if count is not None:
        count_str = list(map(str, count))
        param_list.append(f"-c {' '.join(count_str)}")
    if density is not None:
        density_str = list(map(str, density))
        param_list.append(f"-d {' '.join(density_str)}")
    if fractions:
        param_list.append("-fractions")
    if use_tile_bb:
        param_list.append("-use_tile_bb")
    if merged:
        param_list.append("-merged")
    if files_are_plots:
        param_list.append("-files_are_plots")
    if loc is not None:
        param_list.append(f"-loc {loc}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lascanopy} {parameters}"

    _logger.debug("Running lascanopy")
    message = run_command_line(command)

    return message

lasclassify(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, olaz=True, step=5, planar=0.25, ground_offset=4, height_in_z=False, cores=4, misc=None)

Classifies building and vegetation points. Requires ground and heights calculated in input file.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output classified laz file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
olaz bool

set output to laz format.

True
step float

the search radius for finding adjacent planar surface points.

5
planar float

vertical noise threshold for identifying planar surfaces. increasing this value fits planes to noisier/more rugged surfaces.

0.25
ground_offset float

minimum height to identify as vegetation.

4
height_in_z bool

las input has height data stored in the Z attribute. the default assumption is that height is in the "user data" attribute, which is how height data is stored by default by lasheight.

False
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasclassify(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    olaz: bool = True,
    step: float = defaults.planar_search_radius,
    planar: float = defaults.planar_threshold,
    ground_offset: float = defaults.canopy_density_base,
    height_in_z: bool = False,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Classifies building and vegetation points. Requires ground and heights calculated in input file.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output classified laz file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        olaz: set output to laz format.
        step: the search radius for finding adjacent planar surface points.
        planar: vertical noise threshold for identifying planar surfaces.
            increasing this value fits planes to noisier/more rugged surfaces.
        ground_offset: minimum height to identify as vegetation.
        height_in_z: las input has height data stored in the Z attribute.
            the default assumption is that height is in the "user data" attribute,
            which is how height data is stored by default by `lasheight`.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if olaz:
        param_list.append("-olaz")
    if step is not None:
        param_list.append(f"-step {step:0.3f}")
    if planar is not None:
        param_list.append(f"-planar {planar:0.3f}")
    if ground_offset is not None:
        param_list.append(f"-ground_offset {ground_offset:0.3f}")
    if height_in_z:
        param_list.append("-height_in_z")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lasclassify} {parameters}"

    _logger.debug("Running lasclassify")
    message = run_command_line(command)

    return message

lasgrid(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, otif=True, step=1.0, use_tile_bb=False, fill=5, subcircle=0.4, nodata=-9999, veg=False, elevation=False, ground=False, lowest=False, highest=False, wgs84=False, cores=4, misc=None)

Grids and rasterizes las files.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output gridded raster file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
otif bool

set output to tif format.

True
step float

the grid size of the output raster in geographic units.

1.0
use_tile_bb bool

do not write data from the tile buffer.

False
fill float

fills voids in the grid within this search radius.

5
subcircle float

'splats' each point to a larger radius.

0.4
nodata float

assign this value where no points are found.

-9999
veg bool

export values only from vegetation classes.

False
elevation bool

use elevation values.

False
ground bool

create a ground model.

False
lowest bool

use only the lowest points.

False
highest bool

use only the highest points.

False
wgs84 bool

adjust elevation using the wgs84 ellipsoid.

False
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasgrid(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    otif: bool = True,
    step: float = defaults.resolution,
    use_tile_bb: bool = False,
    fill: float = defaults.fill,
    subcircle: float = defaults.subcircle,
    nodata: float = defaults.nodata,
    veg: bool = False,
    elevation: bool = False,
    ground: bool = False,
    lowest: bool = False,
    highest: bool = False,
    wgs84: bool = False,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Grids and rasterizes las files.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output gridded raster file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        otif: set output to tif format.
        step: the grid size of the output raster in geographic units.
        use_tile_bb: do not write data from the tile buffer.
        fill: fills voids in the grid within this search radius.
        subcircle: 'splats' each point to a larger radius.
        nodata: assign this value where no points are found.
        veg: export values only from vegetation classes.
        elevation: use elevation values.
        ground: create a ground model.
        lowest: use only the lowest points.
        highest: use only the highest points.
        wgs84: adjust elevation using the wgs84 ellipsoid.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    param_list.append(f"-step {step}")
    if nodata is not None:
        param_list.append(f"-nodata {nodata}")
    if otif:
        param_list.append("-otif")
    if fill:
        param_list.append(f"-fill {fill:0.3f}")
    if subcircle:
        param_list.append(f"-subcircle {subcircle:0.3f}")
    if veg:
        param_list.append("-keep_class 1 2 3 4 5")
    if use_tile_bb:
        param_list.append("-use_tile_bb")
    if elevation:
        param_list.append("-elevation")
    if ground:
        param_list.append("-keep_class 2")
        lowest = True
    if lowest:
        param_list.append("-lowest")
    else:
        if highest:
            param_list.append("-highest")
    if wgs84:
        param_list.append("-wgs84")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lasgrid} {parameters}"

    _logger.debug("Running las2grid")
    message = run_command_line(command)

    return message

lasground(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, olaz=True, compute_height=False, replace_z=False, non_ground_unchanged=False, not_airborne=False, town=False, city=False, metro=False, fine=False, extra_fine=False, coarse=False, extra_coarse=False, cores=4, misc=None)

Identifies and classifies ground points.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output laz file with classified ground points.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
olaz bool

set output to laz format.

True
compute_height bool

calculates height aboveground for each point so you dont need lasheight.

False
replace_z bool

replace z value with height above ground. use in conjunction with compute_height.

False
non_ground_unchanged bool

keep original classification in place and only re-classify ground.

False
not_airborne bool

not_airborne: set if using ground-based LiDAR data.

False
town bool

use wide radius to find ground.

False
city bool

use very wide radius to find ground.

False
metro bool

use widest radius to find ground.

False
fine bool

use in steep terrain.

False
extra_fine bool

use in extra steep terrain.

False
coarse bool

use in flat terrain.

False
extra_coarse bool

use in extra flat terrain.

False
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasground(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    olaz: bool = True,
    compute_height: bool = False,
    replace_z: bool = False,
    non_ground_unchanged: bool = False,
    not_airborne: bool = False,
    town: bool = False,
    city: bool = False,
    metro: bool = False,
    fine: bool = False,
    extra_fine: bool = False,
    coarse: bool = False,
    extra_coarse: bool = False,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Identifies and classifies ground points.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output laz file with classified ground points.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        olaz: set output to laz format.
        compute_height: calculates height aboveground for each point so you dont need lasheight.
        replace_z: replace z value with height above ground. use in conjunction with compute_height.
        non_ground_unchanged: keep original classification in place and only re-classify ground.
        not_airborne: not_airborne: set if using ground-based LiDAR data.
        town: use wide radius to find ground.
        city: use very wide radius to find ground.
        metro: use widest radius to find ground.
        fine: use in steep terrain.
        extra_fine: use in extra steep terrain.
        coarse: use in flat terrain.
        extra_coarse: use in extra flat terrain.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if olaz:
        param_list.append("-olaz")
    if compute_height:
        param_list.append("-compute_height")
    if replace_z:
        param_list.append("-replace_z")
    if non_ground_unchanged:
        param_list.append("-non_ground_unchanged")
    if not_airborne:
        param_list.append("-not_airborne")

    if town:
        param_list.append("-town")
    elif city:
        param_list.append("-city")
    elif metro:
        param_list.append("-metro")
    elif fine:
        param_list.append("-fine")
    elif extra_fine:
        param_list.append("-extra_fine")
    elif coarse:
        param_list.append("-coarse")
    elif extra_coarse:
        param_list.append("-extra_coarse")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lasground} {parameters}"

    _logger.debug("Running lasground")
    message = run_command_line(command)

    return message

lasheight(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, olaz=True, replace_z=False, drop_above=None, drop_below=None, cores=4, misc=None)

Calculates the height of each point by triangulating ground point locations.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output height normalized laz file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
olaz bool

set output to laz format.

True
replace_z bool

replace z value with height above ground. use in conjunction with compute_height.

False
drop_above float

throw away points above this threshold.

None
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasheight(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    olaz: bool = True,
    replace_z: bool = False,
    drop_above: float = None,
    drop_below: float = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Calculates the height of each point by triangulating ground point locations.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output height normalized laz file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        olaz: set output to laz format.
        replace_z: replace z value with height above ground. use in conjunction with compute_height.
        drop_above: throw away points above this threshold.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if olaz:
        param_list.append("-olaz")
    if replace_z:
        param_list.append("-replace_z")
    if drop_above is not None:
        param_list.append(f"-drop_above {drop_above:0.3f}")
    if drop_above is not None:
        param_list.append(f"-drop_below {drop_below:0.3f}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lasheight} {parameters}"

    _logger.debug("Running lasheight")
    message = run_command_line(command)

    return message

lasindex(input_files=None, list_of_files=None, cores=4, misc=None)

Creates a spatial index (*.lax) for each las file to reduce multi-file operation runtimes.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasindex(
    input_files: str = None,
    list_of_files: str = None,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Creates a spatial index (*.lax) for each las file to reduce multi-file operation runtimes.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    param_list.append(f"-cores {cores}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lasindex} {parameters}"

    _logger.debug("Running lasindex")
    message = run_command_line(command)

    return message

lasmerge(input_files=None, list_of_files=None, output_file=None, olaz=True, rescale=[0.01, 0.01, 0.01], cores=4, misc=None)

Merges and rescales multiple input files into a single output.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output merged las/laz file.

None
rescale list

point precision for output x/y/z records.

[0.01, 0.01, 0.01]
olaz bool

set output to laz format.

True
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lasmerge(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    olaz: bool = True,
    rescale: list = [
        defaults.target_precision,
        defaults.target_precision,
        defaults.target_elevation_precision,
    ],
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Merges and rescales multiple input files into a single output.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output merged las/laz file.
        rescale: point precision for output x/y/z records.
        olaz: set output to laz format.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, None, None)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-cores {cores}")
    if rescale is not None:
        rescale_str = list(map(str, rescale))
        param_list.append(f"-rescale {rescale_str}")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lastile} {parameters}"

    _logger.debug("Running lastile")
    message = run_command_line(command)

    return message

lastile(input_files=None, list_of_files=None, output_file=None, output_directory=None, output_subextension=None, olaz=True, tile_size=600, buffer_size=20, reversible=False, reverse_tiling=False, cores=4, misc=None)

Creates square tiles of any size with optional overlap buffers.

Parameters:

Name Type Description Default
input_files str

input las/laz file(s). accepts wild cards. enter multiple files as one string.

None
list_of_files str

path to a text file with one input file per line. use when you have too many files to fit in a string.

None
output_file str

output tiled las/laz file.

None
output_directory str

the output tile directory. superceded by output_file.

None
output_subextension str

append this string to each output. superceded by output_file.

None
olaz bool

set output to laz format.

True
tile_size float

the x/y size of each tile (in geographic units).

600
buffer_size float

spatial overlap between tiles (in geographic units).

20
reversible bool

make it easy to re-assemble tiles to original schema.

False
reverse_tiling bool

re-assemble to original tiling schema.

False
cores int

number of processors to use.

4
misc str

additional command line parameters not handled by this wrapper.

None

Returns:

Type Description
str

the sdout string of the executed subprocess.

Source code in lazer/lastools.py
def lastile(
    input_files: str = None,
    list_of_files: str = None,
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
    olaz: bool = True,
    tile_size: float = defaults.tile_size,
    buffer_size: float = defaults.buffer_size,
    reversible: bool = False,
    reverse_tiling: bool = False,
    cores: int = NCORES,
    misc: str = None,
) -> str:
    """Creates square tiles of any size with optional overlap buffers.

    Args:
        input_files: input las/laz file(s). accepts wild cards. enter multiple files as one string.
        list_of_files: path to a text file with one input file per line.
            use when you have too many files to fit in a string.
        output_file: output tiled las/laz file.
        output_directory: the output tile directory. superceded by `output_file`.
        output_subextension: append this string to each output. superceded by `output_file`.
        olaz: set output to laz format.
        tile_size: the x/y size of each tile (in geographic units).
        buffer_size: spatial overlap between tiles (in geographic units).
        reversible: make it easy to re-assemble tiles to original schema.
        reverse_tiling: re-assemble to original tiling schema.
        cores: number of processors to use.
        misc: additional command line parameters not handled by this wrapper.

    Returns:
        the sdout string of the executed subprocess.
    """
    param_list = []

    # i/o
    param_list.append(parse_input_files(input_files, list_of_files))
    output_path = parse_output_files(output_file, output_directory, output_subextension)
    if output_path:
        param_list.append(output_path)

    # processing parameters
    param_list.append(f"-tile_size {tile_size}")
    param_list.append(f"-buffer {buffer_size}")
    param_list.append(f"-cores {cores}")
    if olaz:
        param_list.append("-olaz")
    if reversible:
        param_list.append("-reversible")
    if reverse_tiling:
        param_list.append("-reverse_tiling")
    if misc:
        param_list.append(misc)

    # prepare the full command line call
    parameters = " ".join(param_list)
    command = f"{paths.lastile} {parameters}"

    _logger.debug("Running lastile")
    message = run_command_line(command)

    return message

parse_input_files(input_files=None, list_of_files=None)

Runs a logic check to handle multiple input file parameters and returns the preferred input.

Source code in lazer/lastools.py
def parse_input_files(input_files: str = None, list_of_files: str = None) -> str:
    """Runs a logic check to handle multiple input file parameters and returns the preferred input."""
    if input_files:
        return f"-i {input_files}"
    elif list_of_files:
        return f"-lof {list_of_files}"
    else:
        raise LAStoolsException("No input files specified")

parse_output_files(output_file=None, output_directory=None, output_subextension=None)

Runs a logic check to handle multiple output file parameters and returns the preferred output.

Source code in lazer/lastools.py
def parse_output_files(
    output_file: str = None,
    output_directory: str = None,
    output_subextension: str = None,
) -> str:
    """Runs a logic check to handle multiple output file parameters and returns the preferred output."""
    if output_file:
        return f"-o {output_file}"
    elif output_directory:
        output_string = f"-odir {output_directory}"
        if output_subextension:
            output_string += f" -odix {output_subextension}"
        return output_string
    else:
        pass  # lastools automatically determines output paths
Back to top