3888
ENVI Lidar program to generate and classify surfaces by return
The ENVI Lidar API allows a user to perform many custom analyses that are not generally available in the interface. In this code example, different lidar returns are extracted and classified for comparison.
---------------------------------------------------------------------------------------------------------------------------
PRO generateSurfacesByReturn_extensions_init
COMPILE_OPT idl2
; Get E3DE session
e = E3DE(/CURRENT)
; Add the extension to the Samples folder
e.AddExtension, 'Generate Surfaces By Return', 'generateSurfacesByReturn', $
PATH='/Samples/', ERROR=error
IF error THEN BEGIN
print, 'Error adding extension: ' + error
ENDIF
END
PRO generateSurfacesByReturn
COMPILE_OPT idl2
e = e3de(/headless)
;Specify the classified input LAS file name
lasFileName = '44123A1305_ALL.las'
lasPROJECTname = '44123A1305_SUBRECT_API.ini'
;Directly read (don’t create a project) the input LAS file containing classification values
e.CreateLidarFromSubrect, oLidar, lasPROJECTname, sub_rect=[636844,851175,638912,852726]
startIndex = 0
blockSize = 500000
allReturnNumber = MAKE_ARRAY(blockSize, /BYTE)
; create the output files
outFileName1 = FILE_DIRNAME(lasFileName) + '\FirstAndOnlySUBSET.las'
writer1 = E3DLidar(outFileName1, /OVERWRITE)
outFileName2 = FILE_DIRNAME(lasFileName) + '\FirstOfManySUBSET.las'
writer2 = E3DLidar(outFileName2, /OVERWRITE)
outFileName3 = FILE_DIRNAME(lasFileName) + '\IntermediateOfManySUBSET.las'
writer3 = E3DLidar(outFileName3, /OVERWRITE)
outFileName4 = FILE_DIRNAME(lasFileName) + '\LastOfManySUBSET.las'
writer4 = E3DLidar(outFileName4, /OVERWRITE)
allread = 0
;Cycle through the points, separating by return class (defined below)
WHILE (allread eq 0) DO BEGIN
pointsInRange = oLidar.GetPointsInRange(startIndex, blockSize, $
ALL_ATTRIBS=ALL_ATTRIBS, COUNT=nPointsRead)
; *ALL_ATTRIBS.CLASSIFICATIONS returns the classification codes stored in
; the las file
ReturnNumber = *ALL_ATTRIBS.RETURN_NUMBER
NumberOfReturns = *ALL_ATTRIBS.NUMBER_OF_RETURNS
IF (nPointsRead LT blocksize) THEN allread = 1
;four classes:
; FO: NR = RN = 1 (First and Only)
; FM: NR > RN = 1 (First of Many - not bare earth)
; IM: NR > RN > 1 (Intermediate of Many - not bare earth)
; LM NR = RN > 1 (Last of Many)
FO = where(NumberOfReturns EQ ReturnNumber AND NumberOfReturns EQ 1)
FM = where(NumberOfReturns GT ReturnNumber AND ReturnNumber EQ 1)
IM = where(NumberOfReturns GT ReturnNumber AND ReturnNumber GT 1)
LM = where(NumberOfReturns EQ ReturnNumber AND ReturnNumber GT 1)
writer1.WritePoints, pointsInRange[*,FO];, ALL_ATTRIBS=all_attribs
writer2.WritePoints, pointsInRange[*,FM];, ALL_ATTRIBS=all_attribs
writer3.WritePoints, pointsInRange[*,IM];, ALL_ATTRIBS=all_attribs
writer4.WritePoints, pointsInRange[*,LM];, ALL_ATTRIBS=all_attribs
startIndex += nPointsRead
ENDWHILE
;Save and close output LAS files
writer1.SAVE
writer2.SAVE
writer3.SAVE
writer4.SAVE
writer1.CLOSE
writer2.CLOSE
writer3.CLOSE
writer4.CLOSE
e.CLOSE
END
----------------------------------------------------------------------------------------------------------
Review MM: 2/25/2015