使用liblas文件将数据存储为las却打不开问题的原因

liblas是一个通用的las库,用来对las文件进行读写操作。今天使用时,明明数据写入的很正确很成功,但是使用多个点云浏览软件测试,都打开,最后发现了问题所在,再次Mark一下,以供参考。

主要代码如下:

     // 设置文件头,点数、格式、缩放因子、偏移量
        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()”,在这里,将这句注释掉就对了,我暂时也不清楚为什么。

原文地址:https://www.cnblogs.com/xingzhensun/p/6305802.html