Skip to content

Commit

Permalink
Catch pdal exceptions when creating data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 5, 2020
1 parent c9bee4a commit 4c9338b
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions src/providers/pdal/qgspdalprovider.cpp
Expand Up @@ -20,6 +20,8 @@
#include "qgspdaldataitems.h" #include "qgspdaldataitems.h"
#include "qgsruntimeprofiler.h" #include "qgsruntimeprofiler.h"
#include "qgsapplication.h" #include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"


#include <pdal/io/LasReader.hpp> #include <pdal/io/LasReader.hpp>
#include <pdal/io/LasHeader.hpp> #include <pdal/io/LasHeader.hpp>
Expand Down Expand Up @@ -76,39 +78,47 @@ QgsPointCloudIndex *QgsPdalProvider::index() const


bool QgsPdalProvider::load( const QString &uri ) bool QgsPdalProvider::load( const QString &uri )
{ {
pdal::Option las_opt( "filename", uri.toStdString() ); try
pdal::Options las_opts; {
las_opts.add( las_opt ); pdal::Option las_opt( "filename", uri.toStdString() );
pdal::LasReader las_reader; pdal::Options las_opts;
las_reader.setOptions( las_opts ); las_opts.add( las_opt );
pdal::PointTable table; pdal::LasReader las_reader;
las_reader.prepare( table ); las_reader.setOptions( las_opts );
pdal::LasHeader las_header = las_reader.header(); pdal::PointTable table;

las_reader.prepare( table );
// extent pdal::LasHeader las_header = las_reader.header();
/*
double scale_x = las_header.scaleX(); // extent
double scale_y = las_header.scaleY(); /*
double scale_z = las_header.scaleZ(); double scale_x = las_header.scaleX();
double scale_y = las_header.scaleY();
double offset_x = las_header.offsetX(); double scale_z = las_header.scaleZ();
double offset_y = las_header.offsetY();
double offset_z = las_header.offsetZ(); double offset_x = las_header.offsetX();
*/ double offset_y = las_header.offsetY();

double offset_z = las_header.offsetZ();
double xmin = las_header.minX(); */
double xmax = las_header.maxX();
double ymin = las_header.minY(); double xmin = las_header.minX();
double ymax = las_header.maxY(); double xmax = las_header.maxX();
mExtent = QgsRectangle( xmin, ymin, xmax, ymax ); double ymin = las_header.minY();

double ymax = las_header.maxY();
// unsigned int nFeatures = las_header.pointCount(); mExtent = QgsRectangle( xmin, ymin, xmax, ymax );


// projection // unsigned int nFeatures = las_header.pointCount();
QString wkt = QString::fromStdString( las_reader.getSpatialReference().getWKT() );
mCrs = QgsCoordinateReferenceSystem::fromWkt( wkt ); // projection

QString wkt = QString::fromStdString( las_reader.getSpatialReference().getWKT() );
return true; mCrs = QgsCoordinateReferenceSystem::fromWkt( wkt );
return true;
}
catch ( pdal::pdal_error &error )
{
QgsDebugMsg( QStringLiteral( "Error loading PDAL data source %1" ).arg( error.what() ) );
QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( error.what() ), QStringLiteral( "PDAL" ) );
return false;
}
} }


QgsPdalProviderMetadata::QgsPdalProviderMetadata(): QgsPdalProviderMetadata::QgsPdalProviderMetadata():
Expand Down

0 comments on commit 4c9338b

Please sign in to comment.