LAS格式点云读写

las格式点云作为一种激光点云数据格式,读写可以采用laslib库中提供的方法,参考网站:
https://www.liblas.org/tutorial/cpp.html

Reading LAS data using liblas::Reader

1.Include required header files from libLAS and C++ Standard Library
包含头文件

#include <liblas/liblas.hpp>
#include <fstream>  // std::ifstream
#include <iostream> // std::cout

2.Create input stream and associate it with .las file opened to read in binary mode
创建输入流用于打开二进制模式的las文件

std::ifstream ifs;
ifs.open("file.las", std::ios::in | std::ios::binary);

3.Create a ReaderFactory and instantiate a new liblas::Reader using the stream.
实例化一个liblas::Reader

liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);

4.After the reader has been created, you can access members of the Public Header Block
在创建阅读器之后,您可以访问公共标题块的成员

liblas::Header const& header = reader.GetHeader();

std::cout << "Compressed: " << (header.Compressed() == true) ? "true":"false";
std::cout << "Signature: " << header.GetFileSignature() << '\n';
std::cout << "Points count: " << header.GetPointRecordsCount() << '\n';

5.Iterate through point records
遍历点记录

while (reader.ReadNextPoint())
{
    liblas::Point const& p = reader.GetPoint();

    std::cout << p.GetX() << ", " << p.GetY() << ", " << p.GetZ() << "\n";
}

6.Randomly read point 2
随机读点2

reader.ReadPointAt(2);
liblas::Point const& p = reader.GetPoint();

Note: A ReadPointAt method call implies an individual seek in the file per point read. Use liblas::Reader::Seek if you wish to read a run of points starting at a specified location in the file.

7.Seek to the 10th point to start reading. A liblas::Reader provides a Seek method to allow you to start reading from a specified location for however many points you wish. This functionality is useful for reading strips out of files.
寻找第10点开始阅读

reader.Seek(10);
while (reader.ReadNextPoint())
...

8 关闭流

ifs.close();

Writing using liblas::Writer

1.Include required header files from libLAS and C++ Standard Library

#include <liblas/liblas.hpp>

#include <fstream>  // std::ofstream
#include <iostream> // std::cout

2.Create output stream and associate it with .las file opened to write data in binary mode

std::ofstream ofs;
ofs.open("file.las", ios::out | ios::binary);

Note:It is also possible to open the stream in append mode to add data to an existing file. You should first instantiate a liblas::Reader and fetch the liblas::Header from the file, and then create the liblas::Writer with that header and the ofstream opened in append mode.
添加数据到一个已存在的文件

liblas::Header header = reader.GetHeader();

std::ios::openmode m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
ofs.open("file.las", m);
liblas::Writer writer(ofs, header);

3.Create instance of liblas::Header class to define Public Header Block and set some values
创建 liblas::Header 类来定义公共头块并设置一些值

liblas::Header header;
header.SetDataFormatId(liblas::ePointFormat1); // Time only

// Set coordinate system using GDAL support
liblas::SpatialReference srs;
srs.SetFromUserInput("EPSG:4326");

header.SetSRS(srs);

// fill other header members

Note:Simply setting header.SetCompressed(true) on the header will be sufficient to output a compressed file when the liblas::Writer is created if LASzip support is enabled in libLAS, but it is up to the user to specify the proper file name extension, .laz, when writing the file.

4.Create LAS file writer object attached to the output stream and the based on the header object.

liblas::Writer writer(ofs, header);
// here the header has been serialized to disk into the *file.las*

5.Write some point records

liblas::Point point(&header);
point.SetCoordinates(10, 20, 30);
// fill other properties of point record

writer.WritePoint(point);

6 关闭流

ofs.close();

提供一个编译过的laslib1.8.0文件,用于vs2013开发,http://download.csdn.net/download/joker_mw/10128945
https://www.liblas.org/ 网站提供的下载:https://www.liblas.org/download.html

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值