X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



3905 Rate this article:
No rating

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

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »