@@ -314,6 +314,40 @@ PointSet *fastPlyReadPointSet(const std::string &filename) {
314314 return r;
315315}
316316
317+ #ifdef WITH_PDAL
318+ template <typename T>
319+ bool pdalReadLasMeta (pdal::MetadataNode &lasforward, std::string name, T &val) {
320+ pdal::MetadataNode m = lasforward.findChild (name);
321+ if (m.valid ()) {
322+ val = m.value <T>();
323+ return true ;
324+ } else {
325+ return false ;
326+ }
327+ }
328+
329+ void pdalReadLasScaleOffset (pdal::PointTable *table, PointSet *pSet) {
330+ pdal::MetadataNode lasforward;
331+ lasforward = table->privateMetadata (" lasforward" );
332+ if (!lasforward.valid ())
333+ return ;
334+ bool success = true ;
335+ pSet->scales = std::make_unique<std::array<double , 3 >>();
336+ success &= pdalReadLasMeta (lasforward, " scale_x" , pSet->scales ->at (0 ));
337+ success &= pdalReadLasMeta (lasforward, " scale_y" , pSet->scales ->at (1 ));
338+ success &= pdalReadLasMeta (lasforward, " scale_z" , pSet->scales ->at (2 ));
339+ if (!success)
340+ pSet->scales = nullptr ;
341+ success = true ;
342+ pSet->offsets = std::make_unique<std::array<double , 3 >>();
343+ success &= pdalReadLasMeta (lasforward, " offset_x" , pSet->offsets ->at (0 ));
344+ success &= pdalReadLasMeta (lasforward, " offset_y" , pSet->offsets ->at (1 ));
345+ success &= pdalReadLasMeta (lasforward, " offset_z" , pSet->offsets ->at (2 ));
346+ if (!success)
347+ pSet->offsets = nullptr ;
348+ }
349+ #endif
350+
317351PointSet *pdalReadPointSet (const std::string &filename) {
318352 #ifdef WITH_PDAL
319353 std::string labelDimension;
@@ -336,6 +370,10 @@ PointSet *pdalReadPointSet(const std::string &filename) {
336370 s->prepare (*table);
337371 const pdal::PointViewSet pvSet = s->execute (*table);
338372
373+ if (driver == " readers.las" ) {
374+ pdalReadLasScaleOffset (table, r);
375+ }
376+
339377 r->pointView = *pvSet.begin ();
340378 const pdal::PointViewPtr pView = r->pointView ;
341379
@@ -492,6 +530,18 @@ void pdalSavePointSet(PointSet &pSet, const std::string &filename) {
492530 pdal::Stage *s = factory.createStage (driver);
493531 pdal::Options opts;
494532 opts.add (" filename" , filename);
533+ if (driver == " writers.las" ) {
534+ if (pSet.scales != nullptr ) {
535+ opts.add (" scale_x" , pSet.scales ->at (0 ));
536+ opts.add (" scale_y" , pSet.scales ->at (1 ));
537+ opts.add (" scale_z" , pSet.scales ->at (2 ));
538+ }
539+ if (pSet.offsets != nullptr ) {
540+ opts.add (" offset_x" , pSet.offsets ->at (0 ));
541+ opts.add (" offset_y" , pSet.offsets ->at (1 ));
542+ opts.add (" offset_z" , pSet.offsets ->at (2 ));
543+ }
544+ }
495545 s->setOptions (opts);
496546 s->setInput (reader);
497547
0 commit comments