liblas是一個通用的las庫,用來對las文件進行讀寫操做。今天使用時,明明數據寫入的很正確很成功,可是使用多個點雲瀏覽軟件測試,都打開,最後發現了問題所在,再次Mark一下,以供參考。ios
主要代碼以下:測試
// 設置文件頭,點數、格式、縮放因子、偏移量 liblas::Header header; header.SetVersionMajor(1); header.SetVersionMinor(2); header.SetDataFormatId(liblas::PointFormatName::ePointFormat3); header.SetScale(0.001, 0.001, 0.001); header.SetOffset(int(tempPt.GetX()), int(tempPt.GetY()), 0); // 創建存儲文件 ofstream outPt(newOutPath.c_str(), ios::out | ios::binary); if (!outPt.is_open()) { return 1; } liblas::Writer writer(outPt, header); liblas::Point point(&header); double minPt[3] = {9999999, 9999999, 9999999}; double maxPt[3] = {0, 0, 0}; double pt[3] = {0};
// 中間是寫入點雲及記錄點的個數 header.SetPointRecordsCount(point_count); header.SetPointRecordsByReturnCount(0, point_count); header.SetMax(maxPt[0], maxPt[1], maxPt[2]); header.SetMin(minPt[0], minPt[1], minPt[2]); writer.SetHeader(header);
// 注意此處有問題
outPt.close();
這是很通常的寫法,應該是沒有問題的,實際上保存的las文件打不開。緣由居然是「outPt.close()」,在這裏,將這句註釋掉就對了,我暫時也不清楚爲何。spa