I wrote this function to read Las file and save a shapefile. The function creates a shapefile with 8 fields. What I wish insert a parse element in the function in order to select the fields I wish to save LAS2SHP(inFile, outFile=None, parse=None)
. If parse=None
all fields are saved. If parse="irn"
the fields intensity
, return_number
, and number_of_returns
are saved, following the legend:
"i": p.intensity,
"r": p.return_number,
"n": p.number_of_returns,
"s": p.scan_direction,
"e": p.flightline_edge,
"c": p.classification,
"a": p.scan_angle,
I wrote a solution if....ifelse....else
really code consuming (and not elegant). Thanks for all helps and suggestions for saving code.
Here is the original function in Python:
import shapefile
from liblas import file as lasfile
def LAS2SHP(inFile,outFile=None):
w = shapefile.Writer(shapefile.POINT)
w.field('Z','C','10')
w.field('Intensity','C','10')
w.field('Return','C','10')
w.field('NumberRet','C','10')
w.field('ScanDir','C','10')
w.field('FlightEdge','C','10')
w.field('Class','C','10')
w.field('ScanAngle','C','10')
for p in lasfile.File(inFile,None,'r'):
w.point(p.x,p.y)
w.record(float(p.z),float(p.intensity),float(p.return_number),float(p.number_of_returns),float(p.scan_direction),float(p.flightline_edge),float(p.classification),float(p.scan_angle))
if outFile == None:
inFile_path, inFile_name_ext = os.path.split(os.path.abspath(inFile))
inFile_name = os.path.splitext(inFile_name_ext)[0]
w.save("{0}\\{1}.shp".format(inFile_path,inFile_name))
else:
w.save(outFile)