25 #include "qgsmeshmemorydataprovider.h"
30 const QString &outputFile,
35 : mFormulaString( formulaString )
36 , mOutputDriver( QStringLiteral(
"DAT" ) )
37 , mOutputFile( outputFile )
38 , mOutputExtent( outputExtent )
40 , mStartTime( startTime )
44 if ( !mOutputFile.isEmpty() )
45 mOutputGroupName = QFileInfo( mOutputFile ).baseName();
49 const QString &outputFile,
54 : mFormulaString( formulaString )
55 , mOutputDriver( QStringLiteral(
"DAT" ) )
56 , mOutputFile( outputFile )
57 , mOutputMask( outputMask )
59 , mStartTime( startTime )
63 if ( !mOutputFile.isEmpty() )
64 mOutputGroupName = QFileInfo( mOutputFile ).baseName();
69 const QString &outputDriver,
70 const QString &outputGroupName,
71 const QString &outputFile,
76 : mFormulaString( formulaString )
77 , mOutputDriver( outputDriver )
78 , mOutputGroupName( outputGroupName )
79 , mOutputFile( outputFile )
80 , mOutputExtent( outputExtent )
83 , mStartTime( startTime )
90 const QString &outputDriver,
91 const QString &outputGroupName,
92 const QString &outputFile,
97 : mFormulaString( formulaString )
98 , mOutputDriver( outputDriver )
99 , mOutputGroupName( outputGroupName )
100 , mOutputFile( outputFile )
101 , mOutputMask( outputMask )
104 , mStartTime( startTime )
105 , mEndTime( endTime )
106 , mMeshLayer( layer )
111 const QString &outputGroupName,
117 : mFormulaString( formulaString )
118 , mOutputGroupName( outputGroupName )
119 , mOutputExtent( outputExtent )
121 , mDestination( destination )
122 , mStartTime( startTime )
123 , mEndTime( endTime )
124 , mMeshLayer( layer )
129 const QString &outputGroupName,
135 : mFormulaString( formulaString )
136 , mOutputGroupName( outputGroupName )
137 , mOutputMask( outputMask )
139 , mDestination( destination )
140 , mStartTime( startTime )
141 , mEndTime( endTime )
142 , mMeshLayer( layer )
147 const QString &formulaString,
155 const QString &formulaString,
160 std::unique_ptr< QgsMeshCalcNode > calcNode( QgsMeshCalcNode::parseMeshCalcString( formulaString, errorString ) );
170 QgsMeshDriverMetadata::MeshDriverCapability::CanWriteVertexDatasets;
193 std::unique_ptr< QgsMeshCalcNode > calcNode( QgsMeshCalcNode::parseMeshCalcString( mFormulaString, errorString ) );
203 std::unique_ptr<QgsMeshDatasetGroup> virtualDatasetGroup =
204 std::make_unique<QgsMeshVirtualDatasetGroup> ( mOutputGroupName, mFormulaString, mMeshLayer, mStartTime * 3600 * 1000, mEndTime * 3600 * 1000 );
205 virtualDatasetGroup->initialize();
207 err = !mMeshLayer->
addDatasets( virtualDatasetGroup.release() );
221 QgsMeshCalcUtils dsu( mMeshLayer, calcNode->usedDatasetGroupNames(), mStartTime, mEndTime );
222 if ( !dsu.isValid() )
227 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = std::make_unique<QgsMeshMemoryDatasetGroup> ( mOutputGroupName, dsu.outputType() );
230 bool ok = calcNode->calculate( dsu, *outputGroup );
248 dsu.filter( *outputGroup, mOutputMask );
252 dsu.filter( *outputGroup, mOutputExtent );
254 outputGroup->setIsScalar(
true );
267 QVector<QgsMeshDataBlock> datasetValues;
268 QVector<QgsMeshDataBlock> datasetActive;
269 QVector<double> times;
271 const auto datasize = outputGroup->datasetCount();
272 datasetValues.reserve( datasize );
273 times.reserve( datasize );
275 for (
int i = 0; i < datasize; ++i )
277 const std::shared_ptr<QgsMeshMemoryDataset> dataset = outputGroup->memoryDatasets.at( i );
279 times.push_back( dataset->time );
280 datasetValues.push_back(
281 dataset->datasetValues( outputGroup->isScalar(),
283 dataset->values.size() )
285 if ( !dataset->active.isEmpty() )
287 datasetActive.push_back(
288 dataset->areFacesActive(
290 dataset->active.size() )
296 outputGroup->initialize();
303 err = !mMeshLayer->
addDatasets( outputGroup.release() );
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
Result
Result of the calculation.
@ InvalidDatasets
Datasets with different time outputs or not part of the mesh.
@ CreateOutputError
Error creating output data file.
@ Success
Calculation successful.
@ EvaluateError
Error during evaluation.
@ ParserError
Error parsing formula.
@ Canceled
Calculation canceled.
@ InputLayerError
Error reading input layer.
Q_DECL_DEPRECATED QgsMeshCalculator(const QString &formulaString, const QString &outputFile, const QgsRectangle &outputExtent, double startTime, double endTime, QgsMeshLayer *layer)
Creates calculator with bounding box (rectangular) mask.
static Q_DECL_DEPRECATED Result expression_valid(const QString &formulaString, QgsMeshLayer *layer)
Returns whether formula is valid for particular mesh layer.
Result processCalculation(QgsFeedback *feedback=nullptr)
Starts the calculation, creates new dataset group and adds it to the mesh layer.
static Result expressionIsValid(const QString &formulaString, QgsMeshLayer *layer, QgsMeshDriverMetadata::MeshDriverCapability &requiredCapability)
Returns whether formula is valid for particular mesh layer.
Abstract class that represents a dataset group.
Type
Type of the dataset group.
@ Virtual
Temporary dataset group in memory.
@ Memory
Dataset group store in a file.
@ Persistent
Generic type used for non typed dataset group.
virtual Q_DECL_DEPRECATED bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > ×)
Creates a new dataset group from a data and persists it into a destination path.
Implementation of map layer temporal properties for mesh layers.
QDateTime referenceTime() const
Returns the reference time.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
bool addDatasets(const QString &path, const QDateTime &defaultReferenceTime=QDateTime())
Adds datasets to the mesh from file with path.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QString providerType() const
Returns the provider type for this layer.
A rectangle specified with double values.