More scripts: Lidar
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# LAS_GROUND.sml
# sample script demonstrating creating an LAS Lidar file and writing to it.
# LAS files are linked as Shape objects (class RVC_SHAPE).
# copies Lidar points classified as "Ground" (classification = 2) in an existing LAS file to a new LAS file.
# requires TNTmips version 2010 or higher.
# version 16 December 2009
clear();
# get input LAS shape object
class RVC_SHAPE lasIn;
class RVC_OBJITEM objItemIn;
DlgGetObject("Select input LAS shape object:", "Shape", objItemIn, "ExistingOnly");
lasIn.Open(objItemIn, "Read");
class RVC_GEOREFERENCE georef; # get default georeference from input LAS file
lasIn.GetDefaultGeoref(georef);
# open input shape database and main table (table number = 0) for read
class RVC_DBASE_SHAPE dbIn;
dbIn.OpenAsSubobject(lasIn, "Read");
class RVC_DBTABLE tableIn;
tableIn.Open(dbIn, 0, "Read");
printf("Number of Fields in input LAS file = %d\n", tableIn.GetNumFields() );
# get filepath for output LAS file
class FILEPATH path = GetOutputFileName("output.las", "Select LAS file to make:", "las");
# make output LAS file for ground points; use method that takes the RVC_DBTABLE class
# instance for the existing LAS file to set the same point data record type for the new LAS file
class RVC_SHAPE lasOut;
lasOut.MakeLAS(path, georef.GetCoordRefSys(), tableIn);
# open shape database and main table for write
class RVC_DBASE_SHAPE dbOut;
dbOut.OpenAsSubobject(lasOut, "Write");
class RVC_DBTABLE tableOut;
tableOut.Open(dbOut, 0, "Write");
printf("Number of Fields in output LAS file = %d\n", tableOut.GetNumFields() );
# record class instances for reading, copying, and writing records
class RVC_DBTABLE_RECORD recordIn(tableIn);
class RVC_DBTABLE_RECORD recordOut(tableOut);
class RVC_RECORDNUM recordNum; # container for record number
class STATUSCONTEXT status;
class STATUSDIALOG statusDLG;
statusDLG.Create();
status = statusDLG.CreateContext();
status.BarInit(tableIn.GetNumRecords(), 0);
status.Message = "Processing LIDAR points...";
numeric i; # loop counter
# loop through LIDAR point records to find points classified as ground
for i = 1 to tableIn.GetNumRecords()
{
if (i % 100000 == 0) printf("Processing record %d of %d\n", i, tableIn.GetNumRecords() );
status.BarIncrement(1,0);
recordNum.Number = i;
tableIn.Read(recordNum, recordIn); # read record from input LAS
if (recordIn.GetValue( "Classification") == 2) # check value in Classification field, copy only ground points
{
recordIn.CopyTo(recordOut); # copy field values from record in input to a new record for the output
tableOut.AddRecord(recordOut); # write the new record to output LAS file
}
}
statusDLG.Destroy();
printf("Number of ground points transferred to output = %d\n", tableOut.GetNumRecords() );
print("Done.");