Make input and output argument names more general

etta-drone
Dan Howe 6 years ago
parent cee13119c7
commit ae2fa58588

@ -2,30 +2,30 @@ import os
import subprocess import subprocess
def call_lastools(tool_name, las_in, las_out=None, args=None, verbose=True): def call_lastools(tool_name, input, output=None, args=None, verbose=True):
"""Send commands to the lastools library. """Send commands to the lastools library.
Requires lastools in system path. Requires lastools in system path.
Args: Args:
tool_name: name of lastools binary tool_name: name of lastools binary
las_in: bytes from stdout, or path to input point cloud input: bytes from stdout, or path to main input data
las_out: '-stdout' to pipe output, or path to output point cloud output: '-stdout' to pipe output, or path to main output data
args: list of additional arguments, formatted for lastools args: list of additional arguments, formatted for lastools
verbose: show all warnings and messages from lastools (boolean) verbose: show all warnings and messages from lastools (boolean)
Returns: Returns:
bytes of output las, if las_out='-stdout' bytes of output las, if output='-stdout'
None, if las_out='path/to/las/file' None, if output='path/to/las/file'
Examples: Examples:
# Convert xyz file to las and pipe stdout to a python bytes object # Convert xyz file to las and pipe stdout to a python bytes object
las_data = call_lastools('txt2las', las_in='points.xyz', las_out='-stdout', las_data = call_lastools('txt2las', input='points.xyz', output='-stdout',
args=['-parse', 'sxyz']) args=['-parse', 'sxyz'])
# Clip las_data with a shapefile, and save to a new las file # Clip las_data with a shapefile, and save to a new las file
call_lastools('lasclip', las_in=las_data, las_out='points.las', call_lastools('lasclip', input=las_data, output='points.las',
args=['-poly', 'boundary.shp']) args=['-poly', 'boundary.shp'])
""" """
@ -33,22 +33,22 @@ def call_lastools(tool_name, las_in, las_out=None, args=None, verbose=True):
cmd = [tool_name] cmd = [tool_name]
# Parse input # Parse input
if type(las_in) == bytes: if type(input) == bytes:
# Pipe input las bytes to stdin # Pipe input las bytes to stdin
cmd += ['-stdin'] cmd += ['-stdin']
stdin = las_in stdin = input
else: else:
# Load las from file path # Load las from file path
cmd += ['-i', las_in] cmd += ['-i', input]
stdin = None stdin = None
# Parse output # Parse output
if las_out == '-stdout': if output == '-stdout':
# Pipe output las to stdout # Pipe output las to stdout
cmd += ['-stdout'] cmd += ['-stdout']
elif las_out: elif output:
# Save output las to file # Save output las to file
cmd += ['-o', las_out] cmd += ['-o', output]
# Append additional lastools arguments, if provided # Append additional lastools arguments, if provided
if args: if args:
@ -64,7 +64,7 @@ def call_lastools(tool_name, las_in, las_out=None, args=None, verbose=True):
# Handle errors, if detected # Handle errors, if detected
if process.returncode != 0: if process.returncode != 0:
print("Error: {} failed on {}".format(tool_name, print("Error: {} failed on {}".format(tool_name,
os.path.basename(las_in))) os.path.basename(input)))
print(stderr.decode()) print(stderr.decode())
elif verbose: elif verbose:
@ -72,7 +72,7 @@ def call_lastools(tool_name, las_in, las_out=None, args=None, verbose=True):
print(stderr.decode()) print(stderr.decode())
# Output piped stdout if required # Output piped stdout if required
if las_out == '-stdout': if output == '-stdout':
return stdout return stdout
else: else:
return None return None

Loading…
Cancel
Save