LiDAR 点群データの読み取り、処理、書き込み
この例では、点群をワークスペースに読み取り、目的の点集合を選択して、選択された点を点群ファイルの形式に書き込む方法を示します。
手順 1: 点群の読み取りと表示
関数 lasFileReader を使用して、.las ファイルからワークスペースにデータを読み取ります。出力 lasFileReader オブジェクトに格納されたプロパティを表示します。
fileName = fullfile(toolboxdir("lidar"),"lidardata","las","aerialLidarData.laz"); lasReader = lasFileReader(fileName)
lasReader =
lasFileReader with properties:
Count: 1018047
XLimits: [4.2975e+05 4.3015e+05]
YLimits: [3.6798e+06 3.6801e+06]
ZLimits: [72.7900 125.8200]
Attributes: ["Classification" "LaserReturn" "NumReturns" "ScanDirectionFlag" "EdgeOfFlightLineFlag" "ScanAngle" "UserData" "PointSourceID" "GPSTimeStamp"]
ClassificationInfo: "To get the value, enter lasReader.ClassificationInfo at the Command Window. Learn more"
LaserReturnInfo: [4×2 table]
VariableLengthRecords: [3×3 table]
Show all properties
.las ファイルから点群を読み取ります。
ptCloud = readPointCloud(lasReader);
点群を表示します。
fig = figure(Position=[0 0 800 400]); hPanel = uipanel(fig); hPlot = axes(hPanel); pcshow(ptCloud.Location,Parent=hPlot)

手順 2: 目的の点集合の選択
オブジェクト クラスの分類値および関心領域 (ROI) 内の点のインデックスを指定して、入力点群から目的の点集合を選択できます。
分類値の指定による点の選択
分類値を指定して点を選択するには、
lasFileReaderオブジェクトのClassificationInfoプロパティを使用して入力点群のオブジェクト クラスに関する情報を読み取ります。
disp(lasReader.ClassificationInfo)
Classification Value Class Name Number of Points by Class
____________________ ___________________ _________________________
1 "Unclassified" 114842
2 "Ground" 646632
4 "Medium Vegetation" 210101
6 "Building" 45699
8 "Reserved(8)" 751
9 "Water" 22
関数
readpointCloudを使用して、入力点群から読み取るオブジェクト クラスの分類値を指定します。中植生領域に対応する点を読み取るには、名前と値の引数Classificationの値を 4 に設定します。
ptCloudB = readPointCloud(lasReader,Classification=4);
点群を表示します。
fig1 = figure(Position=[0 0 800 400]); hPanel1 = uipanel(fig1); hPlot1 = axes(hPanel1); pcshow(ptCloudB.Location,Parent=hPlot1)

インデックスの指定による点の選択
入力点群の "x" 座標、"y" 座標、"z" 座標の範囲内で直方体 ROI を定義します。
roi = [lasReader.XLimits(1)+200, lasReader.XLimits(2), ...
lasReader.YLimits(1), lasReader.YLimits(2), lasReader.ZLimits(1), lasReader.ZLimits(2)];直方体 ROI の中にある点のインデックスを調べます。
indices = findPointsInROI(ptCloudB,roi);
直方体 ROI の中にある点を選択し、点群オブジェクトとして格納します。
ptCloudC = select(ptCloudB,indices);
点群を表示します。
fig2 = figure(Position=[0 0 800 400]); hPanel2 = uipanel(fig2); hPlot2 = axes(hPanel2); pcshow(ptCloudC.Location,Parent=hPlot2)

手順 3: 選択された点の .las ファイル形式への書き込み
.las ファイルの名前を指定し、lasFileWriter オブジェクトを作成します。
newfileName = "aerialvegetation.las";
lasWriter = lasFileWriter(newfileName);関数 writePointCloud を使用して、選択された点を .las ファイルに書き込みます。この関数は、現在の作業ディレクトリに新しいファイルを作成します。
writePointCloud(lasWriter,ptCloudC);
手順 4: 新規に書き込んだファイルのプロパティの確認
newlasReader = lasFileReader(newfileName)
newlasReader =
lasFileReader with properties:
Count: 116598
XLimits: [4.2995e+05 4.3015e+05]
YLimits: [3.6798e+06 3.6801e+06]
ZLimits: [84.9500 123.1100]
Attributes: ["Classification" "LaserReturn" "NumReturns" "ScanDirectionFlag" "EdgeOfFlightLineFlag" "ScanAngle" "UserData" "PointSourceID" "GPSTimeStamp" "ScannerChannel"]
ClassificationInfo: "To get the value, enter newlasReader.ClassificationInfo at the Command Window. Learn more"
LaserReturnInfo: [1×2 table]
VariableLengthRecords: [1×3 table]
Show all properties
参考
lasFileReader | pcshow | readPointCloud | findPointsInROI | pointCloud | select