mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-12 00:06:54 -05:00
use enum for supported formats
This commit is contained in:
parent
3c426b274f
commit
cf7137d218
9
python/core/auto_additions/qgspointcloudlayerexporter.py
Normal file
9
python/core/auto_additions/qgspointcloudlayerexporter.py
Normal file
@ -0,0 +1,9 @@
|
||||
# The following has been generated automatically from src/core/pointcloud/qgspointcloudlayerexporter.h
|
||||
# monkey patching scoped based enum
|
||||
QgsPointCloudLayerExporter.ExportFormat.Memory.__doc__ = "Memory layer"
|
||||
QgsPointCloudLayerExporter.ExportFormat.Las.__doc__ = "LAS/LAZ point cloud"
|
||||
QgsPointCloudLayerExporter.ExportFormat.Gpkg.__doc__ = "Geopackage"
|
||||
QgsPointCloudLayerExporter.ExportFormat.Shp.__doc__ = "ESRI ShapeFile"
|
||||
QgsPointCloudLayerExporter.ExportFormat.Dxf.__doc__ = "AutoCAD dxf"
|
||||
QgsPointCloudLayerExporter.ExportFormat.__doc__ = 'Supported export formats for point clouds\n\n' + '* ``Memory``: ' + QgsPointCloudLayerExporter.ExportFormat.Memory.__doc__ + '\n' + '* ``Las``: ' + QgsPointCloudLayerExporter.ExportFormat.Las.__doc__ + '\n' + '* ``Gpkg``: ' + QgsPointCloudLayerExporter.ExportFormat.Gpkg.__doc__ + '\n' + '* ``Shp``: ' + QgsPointCloudLayerExporter.ExportFormat.Shp.__doc__ + '\n' + '* ``Dxf``: ' + QgsPointCloudLayerExporter.ExportFormat.Dxf.__doc__
|
||||
# --
|
||||
@ -25,6 +25,31 @@ Handles exporting point cloud layers to memory layers, OGR supported files and P
|
||||
%End
|
||||
public:
|
||||
|
||||
enum class ExportFormat
|
||||
{
|
||||
Memory,
|
||||
Las,
|
||||
Gpkg,
|
||||
Shp,
|
||||
Dxf,
|
||||
};
|
||||
|
||||
|
||||
static QString getTranslatedName( ExportFormat format );
|
||||
%Docstring
|
||||
Gets the translated name for the specified ``format``
|
||||
%End
|
||||
|
||||
static QString getFilter( ExportFormat format );
|
||||
%Docstring
|
||||
Gets the extensions filter for the specified ``format``
|
||||
%End
|
||||
|
||||
static QString getOgrDriverName( ExportFormat format );
|
||||
%Docstring
|
||||
Gets the OGR driver name for the specified ``format``
|
||||
%End
|
||||
|
||||
QgsPointCloudLayerExporter( QgsPointCloudLayer *layer );
|
||||
%Docstring
|
||||
Constructor for QgsPointCloudLayerExporter, associated with the specified ``layer``.
|
||||
@ -146,25 +171,18 @@ for reprojection if different from the point cloud layer's CRS.
|
||||
Gets the ``crs`` for the exported file.
|
||||
%End
|
||||
|
||||
bool setFormat( const QString &format );
|
||||
bool setFormat( const ExportFormat format );
|
||||
%Docstring
|
||||
Sets the ``format`` for the exported file.
|
||||
|
||||
:return: true if the ``format`` is supported, false otherwise.
|
||||
|
||||
.. seealso:: :py:func:`supportedFormats`
|
||||
.. seealso:: ExportFormat
|
||||
%End
|
||||
|
||||
QString format() const;
|
||||
ExportFormat format() const;
|
||||
%Docstring
|
||||
Returns the format for the exported file or layer.
|
||||
%End
|
||||
|
||||
QStringList supportedFormats() const;
|
||||
%Docstring
|
||||
Gets a list of the supported export formats.
|
||||
|
||||
.. seealso:: :py:func:`setFormat`
|
||||
%End
|
||||
|
||||
void setPointsLimit( qint64 limit );
|
||||
|
||||
@ -8376,16 +8376,25 @@ QString QgisApp::saveAsPointCloudLayer( QgsPointCloudLayer *pclayer )
|
||||
QgsDatumTransformDialog::run( pclayer->crs(), destCRS, this, mMapCanvas );
|
||||
}
|
||||
exp->setCrs( destCRS, pclayer->transformContext() );
|
||||
exp->setFormat( dialog.format() );
|
||||
|
||||
const QgsPointCloudLayerExporter::ExportFormat format = dialog.exportFormat();
|
||||
exp->setFormat( format );
|
||||
|
||||
// LAZ format exports all attributes
|
||||
if ( dialog.format() != QLatin1String( "LAZ" ) &&
|
||||
dialog.format() != QLatin1String( "LAS" ) )
|
||||
switch ( format )
|
||||
{
|
||||
if ( dialog.hasAttributes() )
|
||||
exp->setAttributes( dialog.attributes() );
|
||||
else
|
||||
exp->setNoAttributes();
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Memory:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Shp:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Dxf:
|
||||
if ( dialog.hasAttributes() )
|
||||
exp->setAttributes( dialog.attributes() );
|
||||
else
|
||||
exp->setNoAttributes();
|
||||
break;
|
||||
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Las:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( dialog.hasFilterExtent() )
|
||||
|
||||
@ -33,6 +33,59 @@
|
||||
#include <pdal/Dimension.hpp>
|
||||
#endif
|
||||
|
||||
QString QgsPointCloudLayerExporter::getFilter( ExportFormat format )
|
||||
{
|
||||
switch ( format )
|
||||
{
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Las:
|
||||
return QStringLiteral( "LAZ point cloud (*.laz *.LAZ);;LAS point cloud (*.las *.LAS)" );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
|
||||
return QStringLiteral( "GeoPackage (*.gpkg *.GPKG)" );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Dxf:
|
||||
return QStringLiteral( "AutoCAD DXF (*.dxf *.dxf)" );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Shp:
|
||||
return QStringLiteral( "ESRI Shapefile (*.shp *.SHP)" );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Memory:
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsPointCloudLayerExporter::getTranslatedName( ExportFormat format )
|
||||
{
|
||||
switch ( format )
|
||||
{
|
||||
case ExportFormat::Memory:
|
||||
return QObject::tr( "Temporary Scratch Layer" );
|
||||
case ExportFormat::Gpkg:
|
||||
return QObject::tr( "GeoPackage" );
|
||||
case ExportFormat::Dxf:
|
||||
return QObject::tr( "AutoCAD DXF" );
|
||||
case ExportFormat::Shp:
|
||||
return QObject::tr( "ESRI Shapefile" );
|
||||
case ExportFormat::Las:
|
||||
return QObject::tr( "LAS/LAZ point cloud" );
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QgsPointCloudLayerExporter::getOgrDriverName( ExportFormat format )
|
||||
{
|
||||
switch ( format )
|
||||
{
|
||||
case ExportFormat::Gpkg:
|
||||
return QStringLiteral( "GPKG" );
|
||||
case ExportFormat::Dxf:
|
||||
return QStringLiteral( "DXF" );
|
||||
case ExportFormat::Shp:
|
||||
return QStringLiteral( "ESRI Shapefile" );
|
||||
case ExportFormat::Memory:
|
||||
case ExportFormat::Las:
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QgsPointCloudLayerExporter::QgsPointCloudLayerExporter( QgsPointCloudLayer *layer )
|
||||
: mLayerAttributeCollection( layer->attributes() )
|
||||
, mIndex( layer->dataProvider()->index()->clone().release() )
|
||||
@ -44,15 +97,6 @@ QgsPointCloudLayerExporter::QgsPointCloudLayerExporter( QgsPointCloudLayer *laye
|
||||
if ( !ok )
|
||||
mPointRecordFormat = 3;
|
||||
|
||||
mSupportedFormats << QStringLiteral( "memory" )
|
||||
#ifdef HAVE_PDAL_QGIS
|
||||
<< QStringLiteral( "LAZ" )
|
||||
<< QStringLiteral( "LAS" )
|
||||
#endif
|
||||
<< QStringLiteral( "GPKG" )
|
||||
<< QStringLiteral( "ESRI Shapefile" )
|
||||
<< QStringLiteral( "DXF" );
|
||||
|
||||
setAllAttributes();
|
||||
}
|
||||
|
||||
@ -63,9 +107,9 @@ QgsPointCloudLayerExporter::~QgsPointCloudLayerExporter()
|
||||
delete mTransform;
|
||||
}
|
||||
|
||||
bool QgsPointCloudLayerExporter::setFormat( const QString &format )
|
||||
bool QgsPointCloudLayerExporter::setFormat( const ExportFormat format )
|
||||
{
|
||||
if ( mSupportedFormats.contains( format, Qt::CaseInsensitive ) )
|
||||
if ( supportedFormats().contains( format ) )
|
||||
{
|
||||
mFormat = format;
|
||||
return true;
|
||||
@ -183,7 +227,7 @@ void QgsPointCloudLayerExporter::prepareExport()
|
||||
delete mMemoryLayer;
|
||||
mMemoryLayer = nullptr;
|
||||
|
||||
if ( mFormat == QLatin1String( "memory" ) )
|
||||
if ( mFormat == ExportFormat::Memory )
|
||||
{
|
||||
if ( QApplication::instance()->thread() != QThread::currentThread() )
|
||||
QgsDebugMsgLevel( QStringLiteral( "prepareExport() should better be called from the main thread!" ), 2 );
|
||||
@ -207,73 +251,89 @@ void QgsPointCloudLayerExporter::doExport()
|
||||
}
|
||||
}
|
||||
|
||||
if ( mFormat == QLatin1String( "memory" ) )
|
||||
switch ( mFormat )
|
||||
{
|
||||
if ( !mMemoryLayer )
|
||||
prepareExport();
|
||||
case ExportFormat::Memory:
|
||||
{
|
||||
if ( !mMemoryLayer )
|
||||
prepareExport();
|
||||
|
||||
ExporterMemory exp( this );
|
||||
exp.run();
|
||||
}
|
||||
#ifdef HAVE_PDAL_QGIS
|
||||
else if ( mFormat == QLatin1String( "LAZ" ) ||
|
||||
mFormat == QLatin1String( "LAS" ) )
|
||||
{
|
||||
setAllAttributes();
|
||||
// PDAL may throw exceptions
|
||||
try
|
||||
{
|
||||
ExporterPdal exp( this );
|
||||
ExporterMemory exp( this );
|
||||
exp.run();
|
||||
break;
|
||||
}
|
||||
catch ( std::runtime_error &e )
|
||||
|
||||
case ExportFormat::Las:
|
||||
{
|
||||
setLastError( QString::fromLatin1( e.what() ) );
|
||||
QgsDebugMsg( QStringLiteral( "PDAL has thrown an exception: {}" ).arg( e.what() ) );
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_PDAL_QGIS
|
||||
setAllAttributes();
|
||||
// PDAL may throw exceptions
|
||||
try
|
||||
{
|
||||
ExporterPdal exp( this );
|
||||
exp.run();
|
||||
}
|
||||
catch ( std::runtime_error &e )
|
||||
{
|
||||
setLastError( QString::fromLatin1( e.what() ) );
|
||||
QgsDebugMsg( QStringLiteral( "PDAL has thrown an exception: {}" ).arg( e.what() ) );
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
QgsVectorFileWriter::SaveVectorOptions saveOptions;
|
||||
saveOptions.layerName = mName;
|
||||
saveOptions.driverName = mFormat;
|
||||
saveOptions.datasourceOptions = QgsVectorFileWriter::defaultDatasetOptions( mFormat );
|
||||
saveOptions.layerOptions = QgsVectorFileWriter::defaultLayerOptions( mFormat );
|
||||
saveOptions.symbologyExport = QgsVectorFileWriter::NoSymbology;
|
||||
saveOptions.actionOnExistingFile = mActionOnExistingFile;
|
||||
saveOptions.feedback = mFeedback;
|
||||
mVectorSink = QgsVectorFileWriter::create( mFilename, outputFields(), QgsWkbTypes::PointZ, mTargetCrs, QgsCoordinateTransformContext(), saveOptions );
|
||||
ExporterVector exp( this );
|
||||
exp.run();
|
||||
break;
|
||||
}
|
||||
|
||||
case ExportFormat::Gpkg:
|
||||
case ExportFormat::Dxf:
|
||||
case ExportFormat::Shp:
|
||||
{
|
||||
const QString ogrDriver = getOgrDriverName( mFormat );
|
||||
QgsVectorFileWriter::SaveVectorOptions saveOptions;
|
||||
saveOptions.layerName = mName;
|
||||
saveOptions.driverName = ogrDriver;
|
||||
saveOptions.datasourceOptions = QgsVectorFileWriter::defaultDatasetOptions( ogrDriver );
|
||||
saveOptions.layerOptions = QgsVectorFileWriter::defaultLayerOptions( ogrDriver );
|
||||
saveOptions.symbologyExport = QgsVectorFileWriter::NoSymbology;
|
||||
saveOptions.actionOnExistingFile = mActionOnExistingFile;
|
||||
saveOptions.feedback = mFeedback;
|
||||
mVectorSink = QgsVectorFileWriter::create( mFilename, outputFields(), QgsWkbTypes::PointZ, mTargetCrs, QgsCoordinateTransformContext(), saveOptions );
|
||||
ExporterVector exp( this );
|
||||
exp.run();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QgsMapLayer *QgsPointCloudLayerExporter::takeExportedLayer()
|
||||
{
|
||||
if ( mFormat == QLatin1String( "memory" ) && mMemoryLayer )
|
||||
switch ( mFormat )
|
||||
{
|
||||
QgsMapLayer *retVal = mMemoryLayer;
|
||||
mMemoryLayer = nullptr;
|
||||
return retVal;
|
||||
case ExportFormat::Memory:
|
||||
{
|
||||
QgsMapLayer *retVal = mMemoryLayer;
|
||||
mMemoryLayer = nullptr;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
case ExportFormat::Las:
|
||||
{
|
||||
const QFileInfo fileInfo( mFilename );
|
||||
return new QgsPointCloudLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "pdal" ) );
|
||||
}
|
||||
|
||||
case ExportFormat::Gpkg:
|
||||
{
|
||||
QString uri( mFilename );
|
||||
uri += "|layername=" + mName;
|
||||
return new QgsVectorLayer( uri, mName, QStringLiteral( "ogr" ) );
|
||||
}
|
||||
|
||||
case ExportFormat::Dxf:
|
||||
case ExportFormat::Shp:
|
||||
{
|
||||
const QFileInfo fileInfo( mFilename );
|
||||
return new QgsVectorLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
|
||||
}
|
||||
}
|
||||
|
||||
const QFileInfo fileInfo( mFilename );
|
||||
|
||||
if ( mFormat == QLatin1String( "LAZ" ) ||
|
||||
mFormat == QLatin1String( "LAS" ) )
|
||||
{
|
||||
return new QgsPointCloudLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "pdal" ) );
|
||||
}
|
||||
|
||||
if ( mFormat == QLatin1String( "GPKG" ) )
|
||||
{
|
||||
QString uri( mFilename );
|
||||
uri += "|layername=" + mName;
|
||||
return new QgsVectorLayer( uri, mName, QStringLiteral( "ogr" ) );
|
||||
}
|
||||
|
||||
return new QgsVectorLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -45,6 +45,51 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Supported export formats for point clouds
|
||||
*/
|
||||
enum class ExportFormat : int
|
||||
{
|
||||
Memory = 0, //!< Memory layer
|
||||
Las = 1, //!< LAS/LAZ point cloud
|
||||
Gpkg = 2, //!< Geopackage
|
||||
Shp = 3, //!< ESRI ShapeFile
|
||||
Dxf = 4, //!< AutoCAD dxf
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a list of the supported export formats.
|
||||
*
|
||||
* \see setFormat()
|
||||
*/
|
||||
static QList< ExportFormat > supportedFormats() SIP_SKIP
|
||||
{
|
||||
QList< ExportFormat > formats;
|
||||
formats << ExportFormat::Memory;
|
||||
#ifdef HAVE_PDAL_QGIS
|
||||
formats << ExportFormat::Las;
|
||||
#endif
|
||||
formats << ExportFormat::Gpkg;
|
||||
formats << ExportFormat::Shp;
|
||||
formats << ExportFormat::Dxf;
|
||||
return formats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translated name for the specified \a format
|
||||
*/
|
||||
static QString getTranslatedName( ExportFormat format );
|
||||
|
||||
/**
|
||||
* Gets the extensions filter for the specified \a format
|
||||
*/
|
||||
static QString getFilter( ExportFormat format );
|
||||
|
||||
/**
|
||||
* Gets the OGR driver name for the specified \a format
|
||||
*/
|
||||
static QString getOgrDriverName( ExportFormat format );
|
||||
|
||||
/**
|
||||
* Constructor for QgsPointCloudLayerExporter, associated with the specified \a layer.
|
||||
*
|
||||
@ -158,21 +203,14 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
|
||||
/**
|
||||
* Sets the \a format for the exported file.
|
||||
* \returns true if the \a format is supported, false otherwise.
|
||||
* \see supportedFormats()
|
||||
* \see ExportFormat
|
||||
*/
|
||||
bool setFormat( const QString &format );
|
||||
bool setFormat( const ExportFormat format );
|
||||
|
||||
/**
|
||||
* Returns the format for the exported file or layer.
|
||||
*/
|
||||
QString format() const { return mFormat; }
|
||||
|
||||
/**
|
||||
* Gets a list of the supported export formats.
|
||||
*
|
||||
* \see setFormat()
|
||||
*/
|
||||
QStringList supportedFormats() const { return mSupportedFormats; }
|
||||
ExportFormat format() const { return mFormat; }
|
||||
|
||||
/**
|
||||
* Sets the maximum number of points to be exported. Default value is 0.
|
||||
@ -227,7 +265,7 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
|
||||
|
||||
QgsPointCloudIndex *mIndex = nullptr;
|
||||
QString mName = QObject::tr( "Exported" );
|
||||
QString mFormat;
|
||||
ExportFormat mFormat;
|
||||
QString mFilename;
|
||||
QString mLastError;
|
||||
QgsRectangle mExtent = QgsRectangle( -std::numeric_limits<double>::infinity(),
|
||||
@ -240,7 +278,6 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
|
||||
QgsFeedback *mFeedback = nullptr;
|
||||
qint64 mPointsLimit = 0;
|
||||
QStringList mRequestedAttributes;
|
||||
QStringList mSupportedFormats;
|
||||
QgsCoordinateReferenceSystem mSourceCrs;
|
||||
QgsCoordinateReferenceSystem mTargetCrs;
|
||||
QgsCoordinateTransformContext mTransformContext;
|
||||
|
||||
@ -65,15 +65,12 @@ void QgsPointCloudLayerSaveAsDialog::setup()
|
||||
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsPointCloudLayerSaveAsDialog::reject );
|
||||
|
||||
mFormatComboBox->blockSignals( true );
|
||||
mFormatComboBox->addItem( tr( "Temporary Scratch Layer" ), QStringLiteral( "memory" ) );
|
||||
mFormatComboBox->addItem( tr( "LAZ point cloud" ), QStringLiteral( "LAZ" ) );
|
||||
mFormatComboBox->addItem( tr( "LAS point cloud" ), QStringLiteral( "LAS" ) );
|
||||
mFormatComboBox->addItem( tr( "GeoPackage" ), QStringLiteral( "GPKG" ) );
|
||||
mFormatComboBox->addItem( tr( "ESRI Shapefile" ), QStringLiteral( "ESRI Shapefile" ) );
|
||||
mFormatComboBox->addItem( tr( "AutoCAD DXF" ), QStringLiteral( "DXF" ) );
|
||||
const QList< QgsPointCloudLayerExporter::ExportFormat > supportedFormats = QgsPointCloudLayerExporter::supportedFormats();
|
||||
for ( const auto &format : supportedFormats )
|
||||
mFormatComboBox->addItem( QgsPointCloudLayerExporter::getTranslatedName( format ), static_cast< int >( format ) );
|
||||
|
||||
QgsSettings settings;
|
||||
const QString defaultFormat = settings.value( QStringLiteral( "UI/lastPointCloudFormat" ), "memory" ).toString();
|
||||
const int defaultFormat = settings.value( QStringLiteral( "UI/lastPointCloudFormat" ), 0 ).toInt();
|
||||
mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( defaultFormat ) );
|
||||
mFormatComboBox->blockSignals( false );
|
||||
mFormatComboBox_currentIndexChanged( 0 );
|
||||
@ -183,7 +180,7 @@ void QgsPointCloudLayerSaveAsDialog::setup()
|
||||
|
||||
mCrsSelector->setShowAccuracyWarnings( true );
|
||||
|
||||
mAddToCanvas->setEnabled( format() != QLatin1String( "memory" ) );
|
||||
mAddToCanvas->setEnabled( exportFormat() != QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
|
||||
if ( mLayer )
|
||||
{
|
||||
@ -194,7 +191,8 @@ void QgsPointCloudLayerSaveAsDialog::setup()
|
||||
leLayername->setText( mDefaultOutputLayerNameFromInputLayerName );
|
||||
}
|
||||
|
||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( format() == QLatin1String( "memory" ) || !mFilename->filePath().isEmpty() );
|
||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( exportFormat() == QgsPointCloudLayerExporter::ExportFormat::Memory ||
|
||||
!mFilename->filePath().isEmpty() );
|
||||
}
|
||||
|
||||
void QgsPointCloudLayerSaveAsDialog::accept()
|
||||
@ -300,56 +298,70 @@ void QgsPointCloudLayerSaveAsDialog::accept()
|
||||
|
||||
QgsSettings settings;
|
||||
settings.setValue( QStringLiteral( "UI/lastPointCloudFileFilterDir" ), QFileInfo( filename() ).absolutePath() );
|
||||
settings.setValue( QStringLiteral( "UI/lastPointCloudFormat" ), format() );
|
||||
settings.setValue( QStringLiteral( "UI/lastPointCloudFormat" ), static_cast< int >( exportFormat() ) );
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
QString QgsPointCloudLayerSaveAsDialog::filterForDriver( const QString &driverName ) const
|
||||
{
|
||||
if ( driverName == QLatin1String( "LAZ" ) )
|
||||
return QStringLiteral( "LAZ pointcloud (*.laz *.LAZ)" );
|
||||
if ( driverName == QLatin1String( "LAS" ) )
|
||||
return QStringLiteral( "LAS pointcloud (*.las *.LAS)" );
|
||||
if ( driverName == QLatin1String( "GPKG" ) )
|
||||
return QStringLiteral( "GeoPackage (*.gpkg *.GPKG)" );
|
||||
if ( driverName == QLatin1String( "ESRI Shapefile" ) )
|
||||
return QStringLiteral( "ESRI Shapefile (*.shp *.SHP)" );
|
||||
if ( driverName == QLatin1String( "DXF" ) )
|
||||
return QStringLiteral( "AutoCAD DXF (*.dxf *.dxf)" );
|
||||
return QString();
|
||||
}
|
||||
|
||||
void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
|
||||
{
|
||||
Q_UNUSED( idx )
|
||||
|
||||
const QString sFormat( format() );
|
||||
mAttributesSelection->setEnabled( sFormat != QLatin1String( "DXF" ) &&
|
||||
sFormat != QLatin1String( "LAZ" ) &&
|
||||
sFormat != QLatin1String( "LAS" ) );
|
||||
const QgsPointCloudLayerExporter::ExportFormat format = exportFormat();
|
||||
|
||||
|
||||
if ( sFormat == QLatin1String( "memory" ) )
|
||||
switch ( format )
|
||||
{
|
||||
mWasAddToCanvasForced = !mAddToCanvas->isChecked();
|
||||
mAddToCanvas->setEnabled( false );
|
||||
mAddToCanvas->setChecked( true );
|
||||
mFilename->setEnabled( false );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Memory:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Shp:
|
||||
mAttributesSelection->setEnabled( true );
|
||||
break;
|
||||
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Las:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Dxf:
|
||||
mAttributesSelection->setEnabled( false );
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
mAddToCanvas->setEnabled( true );
|
||||
if ( mWasAddToCanvasForced )
|
||||
{
|
||||
mAddToCanvas->setChecked( !mAddToCanvas->isChecked() );
|
||||
mWasAddToCanvasForced = false;
|
||||
}
|
||||
mFilename->setEnabled( true );
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Memory:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
|
||||
leLayername->setEnabled( true );
|
||||
break;
|
||||
\
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Shp:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Las:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Dxf:
|
||||
leLayername->setEnabled( false );
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Memory:
|
||||
mWasAddToCanvasForced = !mAddToCanvas->isChecked();
|
||||
mAddToCanvas->setEnabled( false );
|
||||
mAddToCanvas->setChecked( true );
|
||||
mFilename->setEnabled( false );
|
||||
break;
|
||||
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Shp:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Las:
|
||||
case QgsPointCloudLayerExporter::ExportFormat::Dxf:
|
||||
mAddToCanvas->setEnabled( true );
|
||||
if ( mWasAddToCanvasForced )
|
||||
{
|
||||
mAddToCanvas->setChecked( !mAddToCanvas->isChecked() );
|
||||
mWasAddToCanvasForced = false;
|
||||
}
|
||||
mFilename->setEnabled( true );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( mFilename->isEnabled() )
|
||||
{
|
||||
mFilename->setFilter( filterForDriver( format() ) );
|
||||
mFilename->setFilter( QgsPointCloudLayerExporter::getFilter( format ) );
|
||||
|
||||
// if output filename already defined we need to replace old suffix
|
||||
// to avoid double extensions like .gpkg.shp
|
||||
@ -357,7 +369,7 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
|
||||
{
|
||||
QRegularExpression rx( "\\.(.*?)[\\s]" );
|
||||
QString ext;
|
||||
ext = rx.match( filterForDriver( format() ) ).captured( 1 );
|
||||
ext = rx.match( QgsPointCloudLayerExporter::getFilter( format ) ).captured( 1 );
|
||||
if ( !ext.isEmpty() )
|
||||
{
|
||||
QFileInfo fi( mLastUsedFilename );
|
||||
@ -366,9 +378,6 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
|
||||
}
|
||||
}
|
||||
|
||||
leLayername->setEnabled( sFormat == QLatin1String( "memory" ) ||
|
||||
sFormat == QLatin1String( "GPKG" ) );
|
||||
|
||||
if ( !mFilename->isEnabled() )
|
||||
mFilename->setFilePath( QString() );
|
||||
|
||||
@ -391,7 +400,8 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
|
||||
leLayername->setText( layerName );
|
||||
}
|
||||
|
||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( sFormat == QLatin1String( "memory" ) || !mFilename->filePath().isEmpty() );
|
||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( format == QgsPointCloudLayerExporter::ExportFormat::Memory ||
|
||||
!mFilename->filePath().isEmpty() );
|
||||
}
|
||||
|
||||
void QgsPointCloudLayerSaveAsDialog::mFilterGeometryGroupBoxCheckToggled( bool checked )
|
||||
@ -423,9 +433,9 @@ QString QgsPointCloudLayerSaveAsDialog::layername() const
|
||||
return leLayername->text();
|
||||
}
|
||||
|
||||
QString QgsPointCloudLayerSaveAsDialog::format() const
|
||||
QgsPointCloudLayerExporter::ExportFormat QgsPointCloudLayerSaveAsDialog::exportFormat() const
|
||||
{
|
||||
return mFormatComboBox->currentData().toString();
|
||||
return static_cast< QgsPointCloudLayerExporter::ExportFormat >( mFormatComboBox->currentData().toInt() );
|
||||
}
|
||||
|
||||
QgsCoordinateReferenceSystem QgsPointCloudLayerSaveAsDialog::crsObject() const
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "qgsfields.h"
|
||||
#include "qgsvectorfilewriter.h"
|
||||
#include "qgis_gui.h"
|
||||
#include "qgspointcloudlayerexporter.h"
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
@ -50,7 +51,7 @@ class GUI_EXPORT QgsPointCloudLayerSaveAsDialog : public QDialog, private Ui::Qg
|
||||
* The format in which the export should be written.
|
||||
* \see QgsVectorFileWriter::filterForDriver()
|
||||
*/
|
||||
QString format() const;
|
||||
QgsPointCloudLayerExporter::ExportFormat exportFormat() const;
|
||||
|
||||
/**
|
||||
* Returns the target filename.
|
||||
@ -165,7 +166,6 @@ class GUI_EXPORT QgsPointCloudLayerSaveAsDialog : public QDialog, private Ui::Qg
|
||||
private:
|
||||
|
||||
void setup();
|
||||
QString filterForDriver( const QString &driverName ) const;
|
||||
|
||||
QgsCoordinateReferenceSystem mSelectedCrs;
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ void TestQgsPointCloudLayerExporter::cleanup()
|
||||
void TestQgsPointCloudLayerExporter::testScratchLayer()
|
||||
{
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -121,7 +121,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerFiltered()
|
||||
{
|
||||
mLayer->setSubsetString( QStringLiteral( "red > 150" ) );
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -136,7 +136,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerExtent()
|
||||
{
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFilterExtent( QgsRectangle( 497754, 7050888, 497755, 7050889 ) );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -150,7 +150,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerZRange()
|
||||
{
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setZRange( QgsDoubleRange( 1, 1.1 ) );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -166,7 +166,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerFilteredByGeometry()
|
||||
QgsMultiPolygon *geom = new QgsMultiPolygon();
|
||||
geom->fromWkt( QStringLiteral( "MultiPolygon (((497753.68054185633081943 7050888.42151333577930927, 497753.68262159946607426 7050888.20937953889369965, 497753.93531038763467222 7050888.2218579975888133, 497753.93219077296089381 7050888.28736990503966808, 497753.86355925025418401 7050888.28840977698564529, 497753.85835989244515076 7050888.41215449199080467, 497753.68054185633081943 7050888.42151333577930927)),((497753.63665927684633061 7050887.68445237725973129, 497753.66327998862834647 7050887.93235775642096996, 497753.85794394387630746 7050887.95232329051941633, 497753.86293532734271139 7050887.84084905963391066, 497753.89621121709933504 7050887.66781443264335394, 497753.63665927684633061 7050887.68445237725973129)),((497753.69655587844317779 7050888.15697001200169325, 497753.82134046510327607 7050888.16528898477554321, 497753.87624568323371932 7050888.10871997196227312, 497753.98439232504460961 7050888.13534068409353495, 497754.18072007474256679 7050888.12702171131968498, 497754.25226323772221804 7050888.07544408272951841, 497754.23229770385660231 7050888.00889230240136385, 497754.17739248572615907 7050887.9822715912014246, 497753.99437509197741747 7050887.95731467381119728, 497753.9211681344313547 7050887.94899570103734732, 497753.834650820994284 7050887.98393538594245911, 497753.70154726190958172 7050887.96064226236194372, 497753.69655587844317779 7050888.15697001200169325)))" ) );
|
||||
exp.setFilterGeometry( geom );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -193,7 +193,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerFilteredByLayer()
|
||||
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFilterGeometry( polygonLayer );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -223,7 +223,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerFilteredByLayerSelected()
|
||||
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFilterGeometry( polygonLayer, true );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -250,7 +250,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerFilteredByLayerDifferentCrs
|
||||
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFilterGeometry( polygonLayer );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -269,7 +269,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerAttributes()
|
||||
QStringLiteral( "Blue" )
|
||||
};
|
||||
exp.setAttributes( attrs );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -294,7 +294,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerBadAttributes()
|
||||
QStringLiteral( "MissingAttribute" )
|
||||
};
|
||||
exp.setAttributes( attrs );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -313,7 +313,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerSkipAttributes()
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
QStringList attrs;
|
||||
exp.setAttributes( attrs );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -332,7 +332,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerCrs()
|
||||
|
||||
QgsCoordinateReferenceSystem differentCrs = QgsCoordinateReferenceSystem::fromEpsgId( 2100 );
|
||||
exp.setCrs( differentCrs );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -357,7 +357,7 @@ void TestQgsPointCloudLayerExporter::testScratchLayerSynthetic()
|
||||
exp.setAttributes( attrs );
|
||||
exp.setFilterExtent( QgsRectangle( 497754, 7050888, 497755, 7050889 ) );
|
||||
exp.setZRange( QgsDoubleRange( 1, 1.1 ) );
|
||||
exp.setFormat( QStringLiteral( "memory" ) );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Memory );
|
||||
exp.doExport();
|
||||
QgsVectorLayer *result = qgis::down_cast<QgsVectorLayer *>( exp.takeExportedLayer() );
|
||||
|
||||
@ -374,9 +374,8 @@ void TestQgsPointCloudLayerExporter::testScratchLayerSynthetic()
|
||||
void TestQgsPointCloudLayerExporter::testOgrFile()
|
||||
{
|
||||
const QString file = QDir::tempPath() + "/filename.gpkg";
|
||||
const QString driver = QStringLiteral( "GPKG" );
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFormat( driver );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Gpkg );
|
||||
exp.setFileName( file );
|
||||
exp.doExport();
|
||||
|
||||
@ -391,9 +390,8 @@ void TestQgsPointCloudLayerExporter::testOgrFile()
|
||||
void TestQgsPointCloudLayerExporter::testPdalFile()
|
||||
{
|
||||
const QString file = QDir::tempPath() + "/filename.laz";
|
||||
const QString driver = QStringLiteral( "LAZ" );
|
||||
QgsPointCloudLayerExporter exp( mLayer );
|
||||
exp.setFormat( driver );
|
||||
exp.setFormat( QgsPointCloudLayerExporter::ExportFormat::Las );
|
||||
exp.setFileName( file );
|
||||
exp.doExport();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user