29 QString QgsTinMeshCreationAlgorithm::group()
const
31 return QObject::tr(
"Mesh" );
34 QString QgsTinMeshCreationAlgorithm::groupId()
const
36 return QStringLiteral(
"mesh" );
39 QString QgsTinMeshCreationAlgorithm::shortDescription()
const
41 return QObject::tr(
"Creates a TIN mesh layer from vector layers" );
44 QString QgsTinMeshCreationAlgorithm::shortHelpString()
const
46 return QObject::tr(
"This algorithm creates a TIN mesh layer from vector layers." );
49 QString QgsTinMeshCreationAlgorithm::name()
const
51 return QStringLiteral(
"tinmeshcreation" );
54 QString QgsTinMeshCreationAlgorithm::displayName()
const
56 return QObject::tr(
"TIN Mesh Creation" );
61 return new QgsTinMeshCreationAlgorithm();
64 void 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.type() != QVariant::List )
94 const QVariantList layersList = layersVariant.toList();
100 for (
const QVariant &layer : layersList )
105 if ( layer.type() != QVariant::Map )
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;
204 void 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 );
213 bool QgsTinMeshCreationAlgorithm::canExecute( QString *errorMessage )
const
215 if ( mAvailableFormat.count() == 0 )
217 *errorMessage = QObject::tr(
"MDAL not available" );