26 QString QgsTinMeshCreationAlgorithm::group()
const
28 return QObject::tr(
"Mesh" );
31 QString QgsTinMeshCreationAlgorithm::groupId()
const
33 return QStringLiteral(
"mesh" );
36 QString QgsTinMeshCreationAlgorithm::shortHelpString()
const
38 return QObject::tr(
"TIN mesh creation from vector layers" );
41 QString QgsTinMeshCreationAlgorithm::name()
const
43 return QStringLiteral(
"tinmeshcreation" );
46 QString QgsTinMeshCreationAlgorithm::displayName()
const
48 return QObject::tr(
"TIN Mesh Creation" );
53 return new QgsTinMeshCreationAlgorithm();
56 void QgsTinMeshCreationAlgorithm::initAlgorithm(
const QVariantMap &configuration )
58 Q_UNUSED( configuration );
63 QList<QgsMeshDriverMetadata> driverList;
69 mAvailableFormat.append( driverMeta.name() );
71 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"MESH_FORMAT" ), QObject::tr(
"Output format" ), mAvailableFormat,
false, 0 ) );
72 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output Coordinate System" ), QVariant(),
true ) );
78 const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral(
"SOURCE_DATA" ) )->name() );
79 if ( layersVariant.type() != QVariant::List )
82 const QVariantList layersList = layersVariant.toList();
88 for (
const QVariant &layer : layersList )
93 if ( layer.type() != QVariant::Map )
95 const QVariantMap layerMap = layer.toMap();
96 const QString layerSource = layerMap.value( QStringLiteral(
"source" ) ).toString();
99 int attributeIndex = layerMap.value( QStringLiteral(
"attributeIndex" ) ).toInt();
103 if ( !featureSource )
107 int featureCount = featureSource->featureCount();
111 mVerticesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
114 mBreakLinesLayer.append( {featureSource->getFeatures(), transform, attributeIndex, featureCount} );
121 if ( mVerticesLayer.isEmpty() && mBreakLinesLayer.isEmpty() )
133 triangulation.
setCrs( destinationCrs );
135 if ( !mVerticesLayer.isEmpty() && feedback )
136 feedback->
setProgressText( QObject::tr(
"Adding vertices layer(s) to the triangulation" ) );
137 for ( Layer &l : mVerticesLayer )
141 triangulation.
addVertices( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
144 if ( !mBreakLinesLayer.isEmpty() && feedback )
145 feedback->
setProgressText( QObject::tr(
"Adding break lines layer(s) to the triangulation" ) );
146 for ( Layer &l : mBreakLinesLayer )
150 triangulation.
addBreakLines( l.fit, l.attributeIndex, l.transform, feedback, l.featureCount );
154 return QVariantMap();
156 const QString fileName = parameterAsFile( parameters, QStringLiteral(
"OUTPUT_MESH" ), context );
157 int driverIndex = parameterAsEnum( parameters, QStringLiteral(
"MESH_FORMAT" ), context );
158 const QString driver = mAvailableFormat.at( driverIndex );
160 feedback->
setProgressText( QObject::tr(
"Creating mesh from triangulation" ) );
164 return QVariantMap();
170 if ( providerMetadata )
171 providerMetadata->
createMeshData( mesh, fileName, driver, destinationCrs );
179 if ( driver ==
"SELAFIN" )
181 addZValueDataset( fileName, mesh, driver );
185 ret[QStringLiteral(
"OUTPUT_MESH" )] = fileName;
190 void QgsTinMeshCreationAlgorithm::addZValueDataset(
const QString &fileName,
const QgsMesh &mesh,
const QString &driver )
192 std::unique_ptr<QgsMeshLayer> tempLayer = qgis::make_unique<QgsMeshLayer>( fileName,
"temp",
"mdal" );
194 tempLayer->addDatasets( zValueDatasetGroup );
195 int datasetGroupIndex = tempLayer->datasetGroupCount() - 1;
196 tempLayer->saveDataset( fileName, datasetGroupIndex, driver );
199 bool QgsTinMeshCreationAlgorithm::canExecute( QString *errorMessage )
const
201 if ( mAvailableFormat.count() == 0 )
203 *errorMessage = QObject::tr(
"MDAL not available" );