add export to CSV files

This commit is contained in:
uclaros 2022-09-05 13:51:57 +03:00 committed by Nyall Dawson
parent ed9dfa9f5a
commit 1a7d160a50
6 changed files with 28 additions and 6 deletions

View File

@ -5,5 +5,6 @@ QgsPointCloudLayerExporter.ExportFormat.Las.__doc__ = "LAS/LAZ point cloud"
QgsPointCloudLayerExporter.ExportFormat.Gpkg.__doc__ = "Geopackage" QgsPointCloudLayerExporter.ExportFormat.Gpkg.__doc__ = "Geopackage"
QgsPointCloudLayerExporter.ExportFormat.Shp.__doc__ = "ESRI ShapeFile" QgsPointCloudLayerExporter.ExportFormat.Shp.__doc__ = "ESRI ShapeFile"
QgsPointCloudLayerExporter.ExportFormat.Dxf.__doc__ = "AutoCAD dxf" 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__ QgsPointCloudLayerExporter.ExportFormat.Csv.__doc__ = "Comma separated values"
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__ + '\n' + '* ``Csv``: ' + QgsPointCloudLayerExporter.ExportFormat.Csv.__doc__
# -- # --

View File

@ -32,6 +32,7 @@ Handles exporting point cloud layers to memory layers, OGR supported files and P
Gpkg, Gpkg,
Shp, Shp,
Dxf, Dxf,
Csv,
}; };

View File

@ -8387,6 +8387,7 @@ QString QgisApp::saveAsPointCloudLayer( QgsPointCloudLayer *pclayer )
case QgsPointCloudLayerExporter::ExportFormat::Gpkg: case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
case QgsPointCloudLayerExporter::ExportFormat::Shp: case QgsPointCloudLayerExporter::ExportFormat::Shp:
case QgsPointCloudLayerExporter::ExportFormat::Dxf: case QgsPointCloudLayerExporter::ExportFormat::Dxf:
case QgsPointCloudLayerExporter::ExportFormat::Csv:
if ( dialog.hasAttributes() ) if ( dialog.hasAttributes() )
exp->setAttributes( dialog.attributes() ); exp->setAttributes( dialog.attributes() );
else else

View File

@ -42,6 +42,8 @@ QString QgsPointCloudLayerExporter::getOgrDriverName( ExportFormat format )
return QStringLiteral( "DXF" ); return QStringLiteral( "DXF" );
case ExportFormat::Shp: case ExportFormat::Shp:
return QStringLiteral( "ESRI Shapefile" ); return QStringLiteral( "ESRI Shapefile" );
case ExportFormat::Csv:
return QStringLiteral( "CSV" );
case ExportFormat::Memory: case ExportFormat::Memory:
case ExportFormat::Las: case ExportFormat::Las:
break; break;
@ -214,6 +216,8 @@ void QgsPointCloudLayerExporter::doExport()
} }
} }
QStringList layerCreationOptions;
switch ( mFormat ) switch ( mFormat )
{ {
case ExportFormat::Memory: case ExportFormat::Memory:
@ -245,6 +249,10 @@ void QgsPointCloudLayerExporter::doExport()
break; break;
} }
case ExportFormat::Csv:
layerCreationOptions << QStringLiteral( "GEOMETRY=AS_XYZ" )
<< QStringLiteral( "SEPARATOR=COMMA" ); // just in case ogr changes the default lco
// Intentional Fallthrough
case ExportFormat::Gpkg: case ExportFormat::Gpkg:
case ExportFormat::Dxf: case ExportFormat::Dxf:
case ExportFormat::Shp: case ExportFormat::Shp:
@ -255,6 +263,7 @@ void QgsPointCloudLayerExporter::doExport()
saveOptions.driverName = ogrDriver; saveOptions.driverName = ogrDriver;
saveOptions.datasourceOptions = QgsVectorFileWriter::defaultDatasetOptions( ogrDriver ); saveOptions.datasourceOptions = QgsVectorFileWriter::defaultDatasetOptions( ogrDriver );
saveOptions.layerOptions = QgsVectorFileWriter::defaultLayerOptions( ogrDriver ); saveOptions.layerOptions = QgsVectorFileWriter::defaultLayerOptions( ogrDriver );
saveOptions.layerOptions << layerCreationOptions;
saveOptions.symbologyExport = QgsVectorFileWriter::NoSymbology; saveOptions.symbologyExport = QgsVectorFileWriter::NoSymbology;
saveOptions.actionOnExistingFile = mActionOnExistingFile; saveOptions.actionOnExistingFile = mActionOnExistingFile;
saveOptions.feedback = mFeedback; saveOptions.feedback = mFeedback;
@ -292,6 +301,7 @@ QgsMapLayer *QgsPointCloudLayerExporter::takeExportedLayer()
case ExportFormat::Dxf: case ExportFormat::Dxf:
case ExportFormat::Shp: case ExportFormat::Shp:
case ExportFormat::Csv:
{ {
const QFileInfo fileInfo( mFilename ); const QFileInfo fileInfo( mFilename );
return new QgsVectorLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); return new QgsVectorLayer( mFilename, fileInfo.completeBaseName(), QStringLiteral( "ogr" ) );

View File

@ -55,6 +55,7 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
Gpkg = 2, //!< Geopackage Gpkg = 2, //!< Geopackage
Shp = 3, //!< ESRI ShapeFile Shp = 3, //!< ESRI ShapeFile
Dxf = 4, //!< AutoCAD dxf Dxf = 4, //!< AutoCAD dxf
Csv = 5, //!< Comma separated values
}; };
/** /**
@ -65,13 +66,14 @@ class CORE_EXPORT QgsPointCloudLayerExporter SIP_NODEFAULTCTORS
static QList< ExportFormat > supportedFormats() SIP_SKIP static QList< ExportFormat > supportedFormats() SIP_SKIP
{ {
QList< ExportFormat > formats; QList< ExportFormat > formats;
formats << ExportFormat::Memory; formats << ExportFormat::Memory
#ifdef HAVE_PDAL_QGIS #ifdef HAVE_PDAL_QGIS
formats << ExportFormat::Las; << ExportFormat::Las
#endif #endif
formats << ExportFormat::Gpkg; << ExportFormat::Gpkg
formats << ExportFormat::Shp; << ExportFormat::Shp
formats << ExportFormat::Dxf; << ExportFormat::Dxf
<< ExportFormat::Csv;
return formats; return formats;
} }

View File

@ -315,6 +315,7 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
case QgsPointCloudLayerExporter::ExportFormat::Memory: case QgsPointCloudLayerExporter::ExportFormat::Memory:
case QgsPointCloudLayerExporter::ExportFormat::Gpkg: case QgsPointCloudLayerExporter::ExportFormat::Gpkg:
case QgsPointCloudLayerExporter::ExportFormat::Shp: case QgsPointCloudLayerExporter::ExportFormat::Shp:
case QgsPointCloudLayerExporter::ExportFormat::Csv:
mAttributesSelection->setEnabled( true ); mAttributesSelection->setEnabled( true );
break; break;
@ -334,6 +335,7 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
case QgsPointCloudLayerExporter::ExportFormat::Shp: case QgsPointCloudLayerExporter::ExportFormat::Shp:
case QgsPointCloudLayerExporter::ExportFormat::Las: case QgsPointCloudLayerExporter::ExportFormat::Las:
case QgsPointCloudLayerExporter::ExportFormat::Dxf: case QgsPointCloudLayerExporter::ExportFormat::Dxf:
case QgsPointCloudLayerExporter::ExportFormat::Csv:
leLayername->setEnabled( false ); leLayername->setEnabled( false );
break; break;
} }
@ -351,6 +353,7 @@ void QgsPointCloudLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int id
case QgsPointCloudLayerExporter::ExportFormat::Shp: case QgsPointCloudLayerExporter::ExportFormat::Shp:
case QgsPointCloudLayerExporter::ExportFormat::Las: case QgsPointCloudLayerExporter::ExportFormat::Las:
case QgsPointCloudLayerExporter::ExportFormat::Dxf: case QgsPointCloudLayerExporter::ExportFormat::Dxf:
case QgsPointCloudLayerExporter::ExportFormat::Csv:
mAddToCanvas->setEnabled( true ); mAddToCanvas->setEnabled( true );
if ( mWasAddToCanvasForced ) if ( mWasAddToCanvasForced )
{ {
@ -576,6 +579,8 @@ QString QgsPointCloudLayerSaveAsDialog::getFilterForFormat( QgsPointCloudLayerEx
return QStringLiteral( "AutoCAD DXF (*.dxf *.dxf)" ); return QStringLiteral( "AutoCAD DXF (*.dxf *.dxf)" );
case QgsPointCloudLayerExporter::ExportFormat::Shp: case QgsPointCloudLayerExporter::ExportFormat::Shp:
return QStringLiteral( "ESRI Shapefile (*.shp *.SHP)" ); return QStringLiteral( "ESRI Shapefile (*.shp *.SHP)" );
case QgsPointCloudLayerExporter::ExportFormat::Csv:
return QStringLiteral( "Comma separated values (*.csv *.CSV)" );
case QgsPointCloudLayerExporter::ExportFormat::Memory: case QgsPointCloudLayerExporter::ExportFormat::Memory:
break; break;
} }
@ -596,6 +601,8 @@ QString QgsPointCloudLayerSaveAsDialog::getTranslatedNameForFormat( QgsPointClou
return tr( "ESRI Shapefile" ); return tr( "ESRI Shapefile" );
case QgsPointCloudLayerExporter::ExportFormat::Las: case QgsPointCloudLayerExporter::ExportFormat::Las:
return tr( "LAS/LAZ point cloud" ); return tr( "LAS/LAZ point cloud" );
case QgsPointCloudLayerExporter::ExportFormat::Csv:
return tr( "Comma separated values" );
} }
return QString(); return QString();
} }