28 QString QgsTinMeshCreationAlgorithm::group()
 const 
   30   return QObject::tr( 
"Mesh" );
 
   33 QString QgsTinMeshCreationAlgorithm::groupId()
 const 
   35   return QStringLiteral( 
"mesh" );
 
   38 QString QgsTinMeshCreationAlgorithm::shortHelpString()
 const 
   40   return QObject::tr( 
"TIN mesh creation from vector layers" );
 
   43 QString QgsTinMeshCreationAlgorithm::name()
 const 
   45   return QStringLiteral( 
"tinmeshcreation" );
 
   48 QString QgsTinMeshCreationAlgorithm::displayName()
 const 
   50   return QObject::tr( 
"TIN Mesh Creation" );
 
   55   return new QgsTinMeshCreationAlgorithm();
 
   58 void QgsTinMeshCreationAlgorithm::initAlgorithm( 
const QVariantMap &configuration )
 
   60   Q_UNUSED( configuration );
 
   65   QList<QgsMeshDriverMetadata> driverList;
 
   71       mAvailableFormat.append( driverMeta.name() );
 
   73   addParameter( 
new QgsProcessingParameterEnum( QStringLiteral( 
"MESH_FORMAT" ), QObject::tr( 
"Output format" ), mAvailableFormat, 
false, 0 ) );
 
   74   addParameter( 
new QgsProcessingParameterCrs( QStringLiteral( 
"CRS_OUTPUT" ), QObject::tr( 
"Output Coordinate System" ), QVariant(), 
true ) );
 
   80   const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral( 
"SOURCE_DATA" ) )->name() );
 
   81   if ( layersVariant.type() != QVariant::List )
 
   84   const QVariantList layersList = layersVariant.toList();
 
   90   for ( 
const QVariant &layer : layersList )
 
   95     if ( layer.type() != QVariant::Map )
 
   97     const QVariantMap layerMap = layer.toMap();
 
   98     const QString layerSource = layerMap.value( QStringLiteral( 
"source" ) ).toString();
 
  101     int attributeIndex = layerMap.value( QStringLiteral( 
"attributeIndex" ) ).toInt();
 
  105     if ( !featureSource )
 
  109     long long featureCount = featureSource->featureCount();
 
  113         mVerticesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
 
  116         mBreakLinesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
 
  123   if ( mVerticesLayer.isEmpty() && mBreakLinesLayer.isEmpty() )
 
  135   triangulation.
setCrs( destinationCrs );
 
  137   if ( !mVerticesLayer.isEmpty() && feedback )
 
  138     feedback->
setProgressText( QObject::tr( 
"Adding vertices layer(s) to the triangulation" ) );
 
  139   for ( Layer &l : mVerticesLayer )
 
  143     triangulation.
addVertices( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
 
  146   if ( !mBreakLinesLayer.isEmpty() && feedback )
 
  147     feedback->
setProgressText( QObject::tr( 
"Adding break lines layer(s) to the triangulation" ) );
 
  148   for ( Layer &l : mBreakLinesLayer )
 
  152     triangulation.
addBreakLines( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
 
  156     return QVariantMap();
 
  158   const QString fileName = parameterAsFile( parameters, QStringLiteral( 
"OUTPUT_MESH" ), context );
 
  159   int driverIndex = parameterAsEnum( parameters, QStringLiteral( 
"MESH_FORMAT" ), context );
 
  160   const QString driver = mAvailableFormat.at( driverIndex );
 
  162     feedback->
setProgressText( QObject::tr( 
"Creating mesh from triangulation" ) );
 
  166     return QVariantMap();
 
  172   if ( providerMetadata )
 
  173     providerMetadata->
createMeshData( mesh, fileName, driver, destinationCrs );
 
  181   if ( driver == 
"SELAFIN" )
 
  183     addZValueDataset( fileName, mesh, driver );
 
  187   ret[QStringLiteral( 
"OUTPUT_MESH" )] = fileName;
 
  192 void QgsTinMeshCreationAlgorithm::addZValueDataset( 
const QString &fileName, 
const QgsMesh &mesh, 
const QString &driver )
 
  194   std::unique_ptr<QgsMeshLayer> tempLayer = std::make_unique<QgsMeshLayer>( fileName, 
"temp", 
"mdal" );
 
  196   tempLayer->addDatasets( zValueDatasetGroup );
 
  197   int datasetGroupIndex = tempLayer->datasetGroupCount() - 1;
 
  198   tempLayer->saveDataset( fileName, datasetGroupIndex, driver );
 
  201 bool QgsTinMeshCreationAlgorithm::canExecute( QString *errorMessage )
 const 
  203   if ( mAvailableFormat.count() == 0 )
 
  205     *errorMessage = QObject::tr( 
"MDAL not available" );
 
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Class that handles mesh creation with Delaunay constrained triangulation.
bool addBreakLines(QgsFeatureIterator &lineFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transformContext, QgsFeedback *feedback=nullptr, long featureCount=1)
Adds break lines from a vector layer, return true if successful.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the coordinate reference system used for the triangulation.
bool addVertices(QgsFeatureIterator &vertexFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback=nullptr, long featureCount=1)
Adds vertices to the triangulation from a feature iterator, return true if successful.
QgsMesh triangulatedMesh(QgsFeedback *feedback=nullptr) const
Returns the triangulated mesh.
Convenient class that can be used to obtain a datasetgroup on vertices that represents the Z value of...
Abstract base class for processing algorithms.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
Base class for providing feedback from a processing algorithm.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
A coordinate reference system parameter for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
@ Mesh
Mesh layer type, since QGIS 3.6.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
QgsCoordinateReferenceSystem crs
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
Mesh - vertices, edges and faces.