18#include "moc_qgsprofileexporter.cpp" 
   38      if ( std::unique_ptr< QgsAbstractProfileGenerator > generator{ source->createProfileGenerator( mRequest ) } )
 
   39        mGenerators.emplace_back( std::move( generator ) );
 
 
   48  if ( mGenerators.empty() )
 
   55  mFeatures = renderer.
asFeatures( mType, feedback );
 
 
   60  if ( mFeatures.empty() )
 
   64  QHash< quint32, QVector< QgsAbstractProfileResults::Feature > > featuresByGeometryType;
 
   67    featuresByGeometryType[
static_cast< quint32 
>( feature.geometry.wkbType() )].append( feature );
 
   71  QList< QgsVectorLayer * > res;
 
   72  for ( 
auto wkbTypeIt = featuresByGeometryType.constBegin(); wkbTypeIt != featuresByGeometryType.constEnd(); ++wkbTypeIt )
 
   76    outputFields.
append( 
QgsField( QStringLiteral( 
"layer" ), QMetaType::Type::QString ) );
 
   80      for ( 
auto attributeIt = feature.attributes.constBegin(); attributeIt != feature.attributes.constEnd(); ++attributeIt )
 
   82        const int existingFieldIndex = outputFields.
lookupField( attributeIt.key() );
 
   83        if ( existingFieldIndex < 0 )
 
   85          outputFields.
append( 
QgsField( attributeIt.key(), 
static_cast<QMetaType::Type
>( attributeIt.value().userType() ) ) );
 
   89          if ( outputFields.
at( existingFieldIndex ).
type() != QMetaType::Type::QString && outputFields.
at( existingFieldIndex ).
type() != attributeIt.value().userType() )
 
   92            outputFields[ existingFieldIndex ].setType( QMetaType::Type::QString );
 
  100          QStringLiteral( 
"profile" ),
 
  106    QList< QgsFeature > featuresToAdd;
 
  107    featuresToAdd.reserve( wkbTypeIt.value().size() );
 
  113      for ( 
auto attributeIt = feature.attributes.constBegin(); attributeIt != feature.attributes.constEnd(); ++attributeIt )
 
  115        const int outputFieldIndex = outputFields.
lookupField( attributeIt.key() );
 
  116        const QgsField &targetField = outputFields.
at( outputFieldIndex );
 
  117        QVariant value = attributeIt.value();
 
  121      featuresToAdd << out;
 
  125    res << outputLayer.release();
 
 
  137    const QString &destination,
 
  140  : 
QgsTask( tr( 
"Exporting elevation profile" ), 
QgsTask::CanCancel )
 
  141  , mDestination( destination )
 
  142  , mTransformContext( transformContext )
 
  144  mExporter = std::make_unique< QgsProfileExporter >( sources, request, type );
 
 
  149  mFeedback = std::make_unique< QgsFeedback >();
 
  151  mExporter->run( mFeedback.get() );
 
  153  mLayers = mExporter->toLayers();
 
  155  if ( mFeedback->isCanceled() )
 
  161  if ( !mDestination.isEmpty() && !mLayers.empty() )
 
  163    const QFileInfo destinationFileInfo( mDestination );
 
  164    const QString fileExtension = destinationFileInfo.completeSuffix();
 
  167    if ( driverName == QLatin1String( 
"DXF" ) )
 
  171      QList< QgsDxfExport::DxfLayer > dxfLayers;
 
  175        dxfLayers.append( dxfLayer );
 
  176        if ( layer->crs().isValid() )
 
  180      QFile dxfFile( mDestination );
 
  181      switch ( dxf.
writeToFile( &dxfFile, QStringLiteral( 
"UTF-8" ) ) )
 
  185          mCreatedFiles.append( mDestination );
 
  206        QString thisLayerFilename;
 
  208        if ( outputFormatIsMultiLayer )
 
  210          thisLayerFilename = mDestination;
 
  213          if ( mLayers.size() > 1 )
 
  214            options.
layerName = QStringLiteral( 
"profile_%1" ).arg( layerCount );
 
  219          if ( mLayers.size() > 1 )
 
  221            thisLayerFilename = QStringLiteral( 
"%1/%2_%3.%4" ).arg( destinationFileInfo.path(), destinationFileInfo.baseName() ).arg( layerCount ).arg( fileExtension );
 
  225            thisLayerFilename = mDestination;
 
  244            if ( !mCreatedFiles.contains( newFileName ) )
 
  245              mCreatedFiles.append( newFileName );
 
  275  else if ( mLayers.empty() )
 
  282    layer->moveToThread( 
nullptr );
 
 
  299  QList<QgsVectorLayer *> res;
 
  300  res.reserve( mLayers.size() );
 
  303    layer->moveToThread( QThread::currentThread() );
 
 
ProfileExportType
Types of export for elevation profiles.
 
@ Profile2D
Export profiles as 2D profile lines, with elevation stored in exported geometry Y dimension and dista...
 
WkbType
The WKB type describes the number of dimensions a geometry has.
 
Interface for classes which can generate elevation profiles.
 
Represents a coordinate reference system (CRS).
 
Contains information about the context in which a coordinate transform is executed.
 
Exports QGIS layers to the DXF format.
 
@ DeviceNotWritableError
Device not writable error.
 
@ Success
Successful export.
 
@ EmptyExtentError
Empty extent, no extent given and no extent could be derived from layers.
 
@ InvalidDeviceError
Invalid device error.
 
ExportResult writeToFile(QIODevice *d, const QString &codec)
Export to a dxf file in the given encoding.
 
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Set destination CRS.
 
void addLayers(const QList< QgsDxfExport::DxfLayer > &layers)
Add layers to export.
 
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
 
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
 
Base class for feedback objects to be used for cancellation of something running in a worker thread.
 
Encapsulate a field in an attribute table or data source.
 
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
 
Container of fields for a vector layer.
 
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
 
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
 
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
 
static QgsVectorLayer * createMemoryLayer(const QString &name, const QgsFields &fields, Qgis::WkbType geometryType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), bool loadDefaultStyle=true) SIP_FACTORY
Creates a new memory layer using the specified parameters.
 
ExportResult
Results of exporting the profile.
 
@ Canceled
Export was canceled.
 
@ Success
Successful export.
 
@ LayerExportFailed
Generic error when outputting to files.
 
@ DxfExportFailed
Generic error when outputting to DXF.
 
@ DeviceError
Could not open output file device.
 
@ Empty
Results were empty.
 
QgsProfileExporterTask(const QList< QgsAbstractProfileSource * > &sources, const QgsProfileRequest &request, Qgis::ProfileExportType type, const QString &destination, const QgsCoordinateTransformContext &transformContext)
Constructor for QgsProfileExporterTask, saving results to the specified destination file.
 
bool run() override
Performs the task's operation.
 
QgsProfileExporterTask::ExportResult result() const
Returns the result of the export operation.
 
void cancel() override
Notifies the task that it should terminate.
 
QList< QgsVectorLayer * > takeLayers()
Returns a list of vector layer containing the exported profile results.
 
void run(QgsFeedback *feedback=nullptr)
Runs the profile generation.
 
QgsProfileExporter(const QList< QgsAbstractProfileSource * > &sources, const QgsProfileRequest &request, Qgis::ProfileExportType type)
Constructor for QgsProfileExporter, using the provided list of profile sources to generate the result...
 
QList< QgsVectorLayer * > toLayers()
Returns a list of vector layer containing the exported profile results.
 
Generates and renders elevation profile plots.
 
QVector< QgsAbstractProfileResults::Feature > asFeatures(Qgis::ProfileExportType type, QgsFeedback *feedback=nullptr)
Exports the profile results as a set of features.
 
void startGeneration()
Start the generation job and immediately return.
 
void waitForFinished()
Block until the current job has finished.
 
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
 
QgsCoordinateReferenceSystem crs() const
Returns the desired Coordinate Reference System for the profile.
 
Abstract base class for long running background tasks.
 
virtual void cancel()
Notifies the task that it should terminate.
 
Options to pass to QgsVectorFileWriter::writeAsVectorFormat().
 
QString fileEncoding
Encoding to use.
 
QString driverName
OGR driver to use.
 
QString layerName
Layer name. If let empty, it will be derived from the filename.
 
QgsVectorFileWriter::ActionOnExistingFile actionOnExistingFile
Action on existing file.
 
QgsFeedback * feedback
Optional feedback object allowing cancellation of layer save.
 
static QgsVectorFileWriter::WriterError writeAsVectorFormatV3(QgsVectorLayer *layer, const QString &fileName, const QgsCoordinateTransformContext &transformContext, const QgsVectorFileWriter::SaveVectorOptions &options, QString *errorMessage=nullptr, QString *newFilename=nullptr, QString *newLayer=nullptr)
Writes a layer out to a vector file.
 
@ ErrAttributeTypeUnsupported
 
@ Canceled
Writing was interrupted by manual cancellation.
 
@ ErrAttributeCreationFailed
 
@ ErrSavingMetadata
Metadata saving failed.
 
static QString driverForExtension(const QString &extension)
Returns the OGR driver name for a specified file extension.
 
@ SupportsMultipleLayers
Filter to only formats which support multiple layers.
 
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
 
@ CreateOrOverwriteLayer
Create or overwrite layer.
 
@ CreateOrOverwriteFile
Create or overwrite file.
 
Represents a vector layer which manages a vector based dataset.
 
Encapsulates information about a feature exported from the profile results.
 
Layers and optional attribute index to split into multiple layers using attribute value as layer name...