-
Notifications
You must be signed in to change notification settings - Fork 0
/
las2xyz.cpp
56 lines (45 loc) · 1.4 KB
/
las2xyz.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "las2xyz.hpp"
#include <iostream>
#include <ostream>
#include <pdal/PointView.hpp>
#include <pdal/Reader.hpp>
#include <pdal/StageFactory.hpp>
#include <fstream>
#include <string>
void las2xyz(const std::string &input_filename){
pdal::StageFactory factory;
//the reader stage
pdal::Stage* reader = factory.createStage("readers.las");
//pdal::Stage* reader = factory.createStage("readers.nitf");
if (!reader) {
std::cerr << "Failed to create LAS reader." << std::endl;
return;
}
//the inputfile
pdal::Options options;
options.add("filename", input_filename);
reader->setOptions(options);
//reading pipeline
pdal::PointTable table;
reader->prepare(table);
pdal::PointViewSet pointViewSet = reader->execute(table);
//open the output xyz file
std::string output_filename = "tmp.xyz";
std::ofstream outfile(output_filename);
if (!outfile.is_open()) {
std::cerr << "Failed to open output folder" << output_filename << std::endl;
return;
}
//loop over points & write
//
for (auto& pointView : pointViewSet) {
for (pdal::PointId i = 0; i < pointView->size(); ++i) {
double x = pointView->getFieldAs<double>(pdal::Dimension::Id::X, i);
double y = pointView->getFieldAs<double>(pdal::Dimension::Id::Y, i);
double z = pointView->getFieldAs<double>(pdal::Dimension::Id::Z, i);
outfile << x << " " << y << " " << z << std::endl;
}
}
//close the file
outfile.close();
}