1

I am using ArcPy to convert large batches of LAS files to GeoTIFF format. It seems like a lot of the data I have acquired from a particular source is giving me the same error: I am able to convert the LAS file to a LAS Dataset in Arc, but the conversion to TIFF usually writes out to an empty TIFF (i.e. I pull the resulting TIFF into a viewer software and there is no terrain data stored in it, just a blank screen.)

What's really weird is that all of these erroneous files have the same size, ~1300kb, so there's SOMETHING there, just not the data that should be written out into it.

If I process them manually - without automating the process with ArcPy - they come out fine, but I am processing thousands and thousands of these tiles so this is just not sustainable for the project I am working on.

This problem is only with data that I have downloaded for Virginia, I have been able to process other states' data with the same code without any problems.

import os
import arcpy
import glob
import shutil
from arcpy import env

arcpy.CheckOutExtension("3D")


#ws (workspace) is the location of the LAS files that I would like to 
#process.  I am running the script from a location other than this folder 
#containing the LAS files, however the LAS files and resulting LASD and TIFs 
#will remain in the same location, unless an exception is thrown and the 
#files are moved by my script.

ws = "list of LAS files"
os.chdir("working directory")

#inLas uses glob to specify all files in the ws folder with the .las 
#extension will be processed.

inLas = glob.glob(os.path.join(ws, '*.las'))

#This first loop goes through the entire list of las files and creates a LASD 
#file for them using the ArcPy CreateLasDataset tool.  Since I was having 
#trouble with some of the LAS files during this step I added an 'except' 
#block that moves any files that this step fails on to another folder.

for las in inLas:
    try:
        arcpy.CreateLasDataset_management(las)
    except:
        print "Error with " + las 
        shutil.move(las,"Folder for segregating erroneous files")

#This next loop is just a repeat of the first loop, but this time I am 
#taking all of the resulting files with the .lasd extension and using the 
#ArcPy 'LASD to Raster'tool.  

inLasDataset = glob.glob(os.path.join(ws, '*.lasd'))

for lasd in inLasDataset:
     try:
        lasdLayer = arcpy.MakeLasDatasetLayer_management(lasd, class_code=[1,2,9])
        arcpy.LasDatasetToRaster_conversion(lasdLayer, sampling_value=1)

     except arcpy.ExecuteError:
        print "Error with " + lasd
        shutil.move(lasd,"Folder for segregating erroneous files") 

print "Done"

Any ideas?

2
  • 2
    Welcome to GIS SE! As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
    – Andy
    Dec 31, 2018 at 15:10
  • Moreover, based on this check the following: i) class codes 1, 2 and 9 exist in the raw data; ii) if the out_raster parameter needs to be specified in the code with its respective extension (.tif); iii) you used the sampling_value parameter, but did not use sampling_type; shouldn't they come together in the code? Not sure, but maybe it is worth to check. Jan 2, 2019 at 17:32

1 Answer 1

2

Please add comments to your code to help understand your directory structure, it seems to be unnecessarily deep. My first issue was that your first try and except are not correctly paired. Correcting this error, I have the script located in a directory with a folder named 'working directory' inside that base folder and a 'list of LAS files' folder inside the 'working directory' folder. This seems deeper than it needs to be. I don't experience any issues with the code as written when testing on 10 LAS files of Iowa LAS data. The tif files appear as designed within the 'list of LAS files' folder using default names. If the ArcGIS tools work correctly on the data outside of Python the error is not with the LAS data, but if they don't the LAS data might have errors.

3
  • Thanks, I am beginning to think that the problem is with the dataset, as this exact same set of code has worked many times in the past with no problems on other datasets. I am storing the script in a separate folder than the LAS files, but the results of my script are staying in the same place as the input LAS files (i.e. the TIFs and LASD files).
    – Scott4993
    Jan 2, 2019 at 16:51
  • Clarification: when I say the problem is with the dataset, I mean the raw LAS files that I have acquired from this particular source (raw Virginia LIDAR data)
    – Scott4993
    Jan 2, 2019 at 17:32
  • So the data comes out fine when I do the processing manually outside of Python, so I think the problem lies with the script itself/the network I am trying to do the work over.
    – Scott4993
    Jan 3, 2019 at 19:45

Your Answer

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

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