1

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?

11
  • Your for loop on the workspace string is completely wrong. It's going to iterate the characters of the string ['C',':','\\',...].
    – Vince
    Commented Sep 19, 2022 at 11:29
  • Thanks for your answer! I adapted the code with the ListFIles() command (see above), but it still doesn't work unfortunately.
    – Radde1683
    Commented Sep 19, 2022 at 11:42
  • arcpy..laszip is invalid syntax, it would typically be arcpy.toolboxalias.toolname()
    – Hornbydd
    Commented Sep 19, 2022 at 11:49
  • Hey I tried arcpy.LAStools.laszip but it also doesn't work. I also got the code examples by executing the function manually and by copying the python code (send to python), so this was proposed by ArcGIS itself.
    – Radde1683
    Commented Sep 19, 2022 at 12:05
  • Don't put your comment (# Define Output directory and and 'outfile' for file name) within the function?
    – Hornbydd
    Commented Sep 19, 2022 at 12:15

1 Answer 1

0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.