Select to view content in your preferred language

Creating LAS Datasets from .LAS files then convert each individual .las file to a tin

6758
3
06-17-2014 01:40 PM
by Anonymous User
Not applicable
Original User: MF79386

Folks,

I am a SUPER new python user and I am attempting to do the following:

1. Navigate to a folder full of .las files
2. Use the data management tool "create las dataset" to create an las dataset for each individual .las file
3. Convert said .lasd file into a tin using 3d Analyst's "LAS Dataset to TIN" tool
4. Repeat this process for ~100 or so .las files, ultimately ending up w/ 100 individual .adf files

I can perform this fairly easily using modelbuilder and batch mode, but it's somewhat time consuming.
My question: How in the world do I go about automating this process? I am attempting to write a script (command line using the powershell) to run everything outside of the GUI, but would be happy to even figure out how to do it w/in ArcPy if necessary. My initial attempts used some code from the ESRI help menu. What follows was my attempt to take 1 .las file, and convert it to a .lasd file (steps 1-2 above):

import os
import arcpy
import exceptions, sys, traceback

print "Set the input workspace for my .las files"
arcpy.env.workspace = raw_input()

print "This is my output workspace"
arcpy.env.workspace = raw_input()

try:

print "Set local variables: inLas"
inLas = raw_input()

print "set local variables:outlas"
lasD = raw_input()

print "..and finally we will create the new LAS Dataset"
arcpy.management.CreateLasDataset (inLas,lasD)

except:
print "Well you tried your best, better luck next time."



Obviously I am lost in the sauce, and would love some guidance. I'm sure I'm forgetting to import something, or who knows what. TThanks!

Cheers,

Mike
0 Kudos
3 Replies
by Anonymous User
Not applicable
Is there a reason you want to use a command prompt style rather than a stand alone script?  Using a stand alone script will still be running completely outside of the GUI.

Here is an example on how you can do a command prompt style:

import os
import arcpy
import glob

ws = raw_input("Set the input workspace for my .las files\n")
las_files = glob.glob(os.path.join(ws, '*.las'))

# create dictionary
las_dict = dict(enumerate(las_files))
las_dict[len(las_files)] = 'Include all .las files in this list'

# print menu
for num,las in sorted(las_dict.iteritems()):
    print '{0}: {1}'.format(num, las)

inLas = raw_input("\n\ncreate a comma separated list for all .las data sets " +
                  "you want to include\nor choose {0} to select all .las files (ex  1,2,3,7)\n".format(max(las_dict.keys())))

# choose full path for output .lasd file
lasD = raw_input('\nEnter full path to output .lasd file (ex. C:\Full_path\To_output\las_data.lasd)\n')

print "..and finally we will create the new LAS Dataset"
if ',' in inLas:
    inLas = map(lambda x: las_dict[int(x)], inLas.split(','))
else:
    if int(inLas) == len(las_files):
        inLas = las_files
    else:
        inLas = las_dict[int(inLas)]

arcpy.management.CreateLasDataset(inLas,lasD)
raw_input('Process complete...hit enter to close')


Or how I would do it as a stand alone script:

import os
import arcpy
import glob

# this is a folder containing .las files
ws = r'C:\some_path\to_your\las_files'  

# get list of .las files
inLas = glob.glob(os.path.join(ws, '*.las'))
print 'found {0} .las files'.format(len(inLas))
print inLas

# name of output LAS data set
lasD = r'C:\full_path\to_output\las_data.lasd'

print "..and finally we will create the new LAS Dataset"
arcpy.management.CreateLasDataset(inLas,lasD) 
print 'Process complete.'
0 Kudos
by Anonymous User
Not applicable
Original User: MF79386

Caleb,

Thanks a lot for the feedback. I wrote that poorly, and was in fact trying to run it in a script, not necessarily from the command line.

I'm going to play w/ your code and try to find a way to parse out individual .las files as each needs to be in their own .lasd (and eventually their own TIN as well). So ultimately I will combine the lasd creation w/ the 3d analyst tool in an attempt to essentially batch all 150 or so .las files in a two-tool, two-step process. Appreciate the response!

Cheers,

Mike
0 Kudos
by Anonymous User
Not applicable
You can iterate through the las files and convert to tin:

import os
import arcpy
import glob

# this is a folder containing .las files
ws = r'C:\some_path\to_your\las_files'  

# get list of .las files
inLas = glob.glob(os.path.join(ws, '*.las'))
print 'found {0} .las files'.format(len(inLas))
print inLas

# directories
lasd_dir = r'C:\some_path\for_lasd_files'
tin_dir = os.path.join(lasd_dir, 'tins')
if not os.path.exists(tin_dir):
    os.makedirs(tin_dir)

# iterate through .las files
for las in inLas:
    lasD = os.path.join(lasd_dir, os.path.basename(las) + 'd')
    arcpy.management.CreateLasDataset(inLas,lasD)
    print 'Created Las dataset: {0}'.format(lasD)
    out_tin = os.path.join(tin_dir, os.path.basename(las).split('.')[0][:9] + '_tin')
    arcpy.LasDatasetToTin_3d(lasD, out_tin)
    print 'Created tin: {0}'.format(out_tin)

print 'Process complete.'
0 Kudos