30using namespace Qt::StringLiterals;
34QString QgsTinMeshCreationAlgorithm::group()
const
36 return QObject::tr(
"Mesh" );
39QString QgsTinMeshCreationAlgorithm::groupId()
const
44QString QgsTinMeshCreationAlgorithm::shortDescription()
const
46 return QObject::tr(
"Creates a TIN mesh layer from vector layers." );
49QString QgsTinMeshCreationAlgorithm::shortHelpString()
const
51 return QObject::tr(
"This algorithm creates a TIN mesh layer from vector layers." );
54QStringList QgsTinMeshCreationAlgorithm::tags()
const
56 return QObject::tr(
"tin,mesh,vector,triangulation,irregular,network" ).split(
',' );
59QString QgsTinMeshCreationAlgorithm::name()
const
61 return u
"tinmeshcreation"_s;
64QString QgsTinMeshCreationAlgorithm::displayName()
const
66 return QObject::tr(
"TIN Mesh Creation" );
71 return new QgsTinMeshCreationAlgorithm();
74void QgsTinMeshCreationAlgorithm::initAlgorithm(
const QVariantMap &configuration )
76 Q_UNUSED( configuration );
81 QList<QgsMeshDriverMetadata> driverList;
88 const QString name = driverMeta.name();
89 mDriverSuffix[name] = driverMeta.writeMeshFrameOnFileSuffix();
90 mAvailableFormat.append( name );
93 addParameter(
new QgsProcessingParameterEnum( u
"MESH_FORMAT"_s, QObject::tr(
"Output format" ), mAvailableFormat,
false, 0 ) );
94 addParameter(
new QgsProcessingParameterCrs( u
"CRS_OUTPUT"_s, QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
100 const QVariant layersVariant = parameters.value( parameterDefinition( u
"SOURCE_DATA"_s )->name() );
101 if ( layersVariant.userType() != QMetaType::Type::QVariantList )
104 const QVariantList layersList = layersVariant.toList();
110 for (
const QVariant &layer : layersList )
115 if ( layer.userType() != QMetaType::Type::QVariantMap )
117 const QVariantMap layerMap = layer.toMap();
118 const QString layerSource = layerMap.value( u
"source"_s ).toString();
120 const int attributeIndex = layerMap.value( u
"attributeIndex"_s ).toInt();
124 if ( !featureSource )
128 const long long featureCount = featureSource->featureCount();
132 mVerticesLayer.append( { featureSource->getFeatures(), transform, attributeIndex, featureCount } );
135 mBreakLinesLayer.append( { featureSource->getFeatures(), transform, attributeIndex, featureCount } );
142 if ( mVerticesLayer.isEmpty() && mBreakLinesLayer.isEmpty() )
150 QGS_MARK_ALGORITHM_SOURCE
156 triangulation.setCrs( destinationCrs );
158 if ( !mVerticesLayer.isEmpty() && feedback )
159 feedback->
setProgressText( QObject::tr(
"Adding vertices layer(s) to the triangulation" ) );
160 for ( Layer &l : mVerticesLayer )
164 triangulation.addVertices( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
167 if ( !mBreakLinesLayer.isEmpty() && feedback )
168 feedback->
setProgressText( QObject::tr(
"Adding break lines layer(s) to the triangulation" ) );
169 for ( Layer &l : mBreakLinesLayer )
173 triangulation.addBreakLines( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
177 return QVariantMap();
179 QString fileName = parameterAsFile( parameters, u
"OUTPUT_MESH"_s, context );
180 const int driverIndex = parameterAsEnum( parameters, u
"MESH_FORMAT"_s, context );
181 const QString driver = mAvailableFormat.at( driverIndex );
183 feedback->
setProgressText( QObject::tr(
"Creating mesh from triangulation" ) );
184 const QgsMesh mesh = triangulation.triangulatedMesh( feedback );
187 return QVariantMap();
195 if ( providerMetadata )
196 providerMetadata->
createMeshData( mesh, fileName, driver, destinationCrs );
201 if ( driver ==
"SELAFIN" )
203 addZValueDataset( fileName, mesh, driver );
207 ret[u
"OUTPUT_MESH"_s] = fileName;
212void QgsTinMeshCreationAlgorithm::addZValueDataset(
const QString &fileName,
const QgsMesh &mesh,
const QString &driver )
214 auto tempLayer = std::make_unique<QgsMeshLayer>( fileName,
"temp",
"mdal" );
216 tempLayer->addDatasets( zValueDatasetGroup );
217 const int datasetGroupIndex = tempLayer->datasetGroupCount() - 1;
218 tempLayer->saveDataset( fileName, datasetGroupIndex, driver );
221bool QgsTinMeshCreationAlgorithm::canExecute( QString *errorMessage )
const
223 if ( mAvailableFormat.count() == 0 )
225 *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.
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.
Handles mesh creation with Delaunay constrained triangulation.
Convenience class that can be used to obtain a dataset group on vertices that represents the Z value ...
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.