I'm currently trying to develop a LAStools specific routine, setting all the parameters for lasheight
then using the output of that to run lasclassify
. The closest thing I've found to being able to write this in Python is in Sending arguments to LAStools function from Python script not working
In the above post I'm a bit curious where the input and output .las files are. Also, not exactly sure how that Bat functionality is working. Does anyone have an example of a complete script they would be willing to post?
Here's what I have so far, I can't seem to get it to work though. I think it has something to do with the environments setting. I'm running the exact text from the bat file in the command line and it's working now that I updated the default PATH to where my LAStools bin folder is.
import os, random, sys, subprocess
input_path = "D:\Working_D\LAStools_scratch\input\\*.laz"
height_path = "D:\Working_D\LAStools_scratch\height"
arg_cores = "-cores 16"
directory = r'D:\Working_D\scripts\BatchFiles'
with open(os.path.join(directory, 'BatchTemp.bat'), 'w') as OPATH:
OPATH.writelines(["lasheight ",
"-i {0} ".format('"' + input_path + '"'),
"{0} ".format(arg_cores),
"{0} ".format("-odir"),
"{0} ".format('"' + height_path + '"'),
"{0} ".format("-olaz"),
"\n "])
BatFile = 'D:\Working_D\scripts\BatchFiles\BatchTemp.bat'
proc=subprocess.Popen(BatFile,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
output,error=proc.communicate()
os.remove(BatFile)
print 'process complete.'
SOLVED: I was running this in IDLE and it would not work but running the Python script through the cmd window (e.g. D:\Working_D\scripts\lasheight_v2.py) and it worked!