29QString QgsTinMeshCreationAlgorithm::group()
const
31 return QObject::tr(
"Mesh" );
34QString QgsTinMeshCreationAlgorithm::groupId()
const
36 return QStringLiteral(
"mesh" );
39QString QgsTinMeshCreationAlgorithm::shortDescription()
const
41 return QObject::tr(
"Creates a TIN mesh layer from vector layers" );
44QString QgsTinMeshCreationAlgorithm::shortHelpString()
const
46 return QObject::tr(
"This algorithm creates a TIN mesh layer from vector layers." );
49QString QgsTinMeshCreationAlgorithm::name()
const
51 return QStringLiteral(
"tinmeshcreation" );
54QString QgsTinMeshCreationAlgorithm::displayName()
const
56 return QObject::tr(
"TIN Mesh Creation" );
61 return new QgsTinMeshCreationAlgorithm();
64void QgsTinMeshCreationAlgorithm::initAlgorithm(
const QVariantMap &configuration )
66 Q_UNUSED( configuration );
71 QList<QgsMeshDriverMetadata> driverList;
78 const QString name = driverMeta.name();
79 mDriverSuffix[name] = driverMeta.writeMeshFrameOnFileSuffix();
80 mAvailableFormat.append( name );
83 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"MESH_FORMAT" ), QObject::tr(
"Output format" ), mAvailableFormat,
false, 0 ) );
84 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
90 const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral(
"SOURCE_DATA" ) )->name() );
91 if ( layersVariant.userType() != QMetaType::Type::QVariantList )
94 const QVariantList layersList = layersVariant.toList();
100 for (
const QVariant &layer : layersList )
105 if ( layer.userType() != QMetaType::Type::QVariantMap )
107 const QVariantMap layerMap = layer.toMap();
108 const QString layerSource = layerMap.value( QStringLiteral(
"source" ) ).toString();
111 const int attributeIndex = layerMap.value( QStringLiteral(
"attributeIndex" ) ).toInt();
115 if ( !featureSource )
119 const long long featureCount = featureSource->featureCount();
123 mVerticesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
126 mBreakLinesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
133 if ( mVerticesLayer.isEmpty() && mBreakLinesLayer.isEmpty() )
145 triangulation.
setCrs( destinationCrs );
147 if ( !mVerticesLayer.isEmpty() && feedback )
148 feedback->
setProgressText( QObject::tr(
"Adding vertices layer(s) to the triangulation" ) );
149 for ( Layer &l : mVerticesLayer )
153 triangulation.
addVertices( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
156 if ( !mBreakLinesLayer.isEmpty() && feedback )
157 feedback->
setProgressText( QObject::tr(
"Adding break lines layer(s) to the triangulation" ) );
158 for ( Layer &l : mBreakLinesLayer )
162 triangulation.
addBreakLines( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
166 return QVariantMap();
168 QString fileName = parameterAsFile( parameters, QStringLiteral(
"OUTPUT_MESH" ), context );
169 const int driverIndex = parameterAsEnum( parameters, QStringLiteral(
"MESH_FORMAT" ), context );
170 const QString driver = mAvailableFormat.at( driverIndex );
172 feedback->
setProgressText( QObject::tr(
"Creating mesh from triangulation" ) );
176 return QVariantMap();
184 if ( providerMetadata )
185 providerMetadata->
createMeshData( mesh, fileName, driver, destinationCrs );
193 if ( driver ==
"SELAFIN" )
195 addZValueDataset( fileName, mesh, driver );
199 ret[QStringLiteral(
"OUTPUT_MESH" )] = fileName;
204void QgsTinMeshCreationAlgorithm::addZValueDataset(
const QString &fileName,
const QgsMesh &mesh,
const QString &driver )
206 std::unique_ptr<QgsMeshLayer> tempLayer = std::make_unique<QgsMeshLayer>( fileName,
"temp",
"mdal" );
208 tempLayer->addDatasets( zValueDatasetGroup );
209 const int datasetGroupIndex = tempLayer->datasetGroupCount() - 1;
210 tempLayer->saveDataset( fileName, datasetGroupIndex, driver );
213bool QgsTinMeshCreationAlgorithm::canExecute( QString *errorMessage )
const
215 if ( mAvailableFormat.count() == 0 )
217 *errorMessage = QObject::tr(
"MDAL not available" );
ProcessingTinInputLayerType
Defines the type of input layer for a Processing TIN input.
@ BreakLines
Input that adds vertices and break lines.
@ Vertices
Input that adds only vertices.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool isCanceled() const
Tells whether the operation has been canceled already.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
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.
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.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
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.