Using ArcPy to iterate through multiple LAZ files and convert them to LAS files with lastools

arcpyconvertfor looplassyntaxerror

I'm using Jupyter Notebooks in ArcGIS Pro and I would like to convert multiple .laz files into .las files by using the opensource toolbox 'lastools' and its function 'laszip'. For this I would like to iterate through all files within my working directory by using a for-loop.

This is my code so far:

arcpy.env.workspace = r"C:\user\lidar\laz" # Set the workspace
arcpy.ImportToolbox(r"C:\Users\user1\Desktop\LAStools\LAStools\ArcGIS_toolbox\LAStools.tbx.tbx") # Import lastools

for file in arcpy.ListFiles("*.laz"):
    outfile = arcpy.Describe(file).baseName + '_las' # Take original file name and add '_las'
    arcpy..laszip(input_file=file, 
                  only_report_size=False, also_compress_decompress_waveforms=False, 
                  output_format= "las",
                  output_file= r"C:\user\lidar\las\{}".format(outfile), # Define Output directory and and 'outfile' for file name
                  output_directory= r"C:\user\lidar\las", 
                  output_appendix="", additional_command-line_parameters="", verbose=True)

Unfortunately I'm getting this error message:

---------------------------------------------------------------------------
SyntaxError                               Traceback (most recent call last)
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\ast.py, in parse:
Line 35:    return compile(source, filename, mode, PyCF_ONLY_AST)

SyntaxError: invalid syntax (<string>, line 7)
---------------------------------------------------------------------------

How do I use the lastools toolbox in ArcPy?

Best Answer

If anybody is still wondering how to make it work, this is one solotion I found here. The problem was that the 'LAStools' toolbox can't be imported that easy into Arcpy. First a geoprocessing script has to be created. With this code I can run the 'laszip' function within a for-loop:

# set wd 
arcpy.env.workspace = r"C:\Users\laz" 

# create geoprocessing script
import arcgisscripting
gp = arcgisscripting.create()

# import lastools by using the geoprocessing script
gp.AddToolbox(r"C:\Users\LAStools\ArcGIS_toolbox\LAStools.tbx")


for file in arcpy.ListFiles("*.laz"):
    outfile = arcpy.Describe(file).baseName + '_las'
    print(outfile)
    arcpy.gp.laszip(file, 
                    False, 
                    False, 
                    "las", 
                    r"C:\Users\laz\las\{}".format(outfile),
                    r"C:\Users\laz\las", 
                    "", 
                    "", 
                    True)
Related Question