27 #include "qgsmeshmemorydataprovider.h"
32 const QString &outputFile,
37 : mFormulaString( formulaString )
38 , mOutputDriver( QStringLiteral(
"DAT" ) )
39 , mOutputFile( outputFile )
40 , mOutputExtent( outputExtent )
42 , mStartTime( startTime )
46 if ( !mOutputFile.isEmpty() )
47 mOutputGroupName = QFileInfo( mOutputFile ).baseName();
51 const QString &outputFile,
56 : mFormulaString( formulaString )
57 , mOutputDriver( QStringLiteral(
"DAT" ) )
58 , mOutputFile( outputFile )
59 , mOutputMask( outputMask )
61 , mStartTime( startTime )
65 if ( !mOutputFile.isEmpty() )
66 mOutputGroupName = QFileInfo( mOutputFile ).baseName();
71 const QString &outputDriver,
72 const QString &outputGroupName,
73 const QString &outputFile,
78 : mFormulaString( formulaString )
79 , mOutputDriver( outputDriver )
80 , mOutputGroupName( outputGroupName )
81 , mOutputFile( outputFile )
82 , mOutputExtent( outputExtent )
85 , mStartTime( startTime )
92 const QString &outputDriver,
93 const QString &outputGroupName,
94 const QString &outputFile,
99 : mFormulaString( formulaString )
100 , mOutputDriver( outputDriver )
101 , mOutputGroupName( outputGroupName )
102 , mOutputFile( outputFile )
103 , mOutputMask( outputMask )
106 , mStartTime( startTime )
107 , mEndTime( endTime )
108 , mMeshLayer( layer )
113 const QString &outputGroupName,
119 : mFormulaString( formulaString )
120 , mOutputGroupName( outputGroupName )
121 , mOutputExtent( outputExtent )
123 , mDestination( destination )
124 , mStartTime( startTime )
125 , mEndTime( endTime )
126 , mMeshLayer( layer )
131 const QString &outputGroupName,
137 : mFormulaString( formulaString )
138 , mOutputGroupName( outputGroupName )
139 , mOutputMask( outputMask )
141 , mDestination( destination )
142 , mStartTime( startTime )
143 , mEndTime( endTime )
144 , mMeshLayer( layer )
149 const QString &formulaString,
157 const QString &formulaString,
162 std::unique_ptr< QgsMeshCalcNode > calcNode( QgsMeshCalcNode::parseMeshCalcString( formulaString, errorString ) );
172 QgsMeshDriverMetadata::MeshDriverCapability::CanWriteVertexDatasets;
195 std::unique_ptr< QgsMeshCalcNode > calcNode( QgsMeshCalcNode::parseMeshCalcString( mFormulaString, errorString ) );
205 std::unique_ptr<QgsMeshDatasetGroup> virtualDatasetGroup =
206 std::make_unique<QgsMeshVirtualDatasetGroup> ( mOutputGroupName, mFormulaString, mMeshLayer, mStartTime * 3600 * 1000, mEndTime * 3600 * 1000 );
207 virtualDatasetGroup->initialize();
209 err = !mMeshLayer->
addDatasets( virtualDatasetGroup.release() );
223 const QgsMeshCalcUtils dsu( mMeshLayer, calcNode->usedDatasetGroupNames(), mStartTime, mEndTime );
224 if ( !dsu.isValid() )
229 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = std::make_unique<QgsMeshMemoryDatasetGroup> ( mOutputGroupName, dsu.outputType() );
232 const bool ok = calcNode->calculate( dsu, *outputGroup );
250 dsu.filter( *outputGroup, mOutputMask );
254 dsu.filter( *outputGroup, mOutputExtent );
256 outputGroup->setIsScalar(
true );
269 QVector<QgsMeshDataBlock> datasetValues;
270 QVector<QgsMeshDataBlock> datasetActive;
271 QVector<double> times;
273 const auto datasize = outputGroup->datasetCount();
274 datasetValues.reserve( datasize );
275 times.reserve( datasize );
277 for (
int i = 0; i < datasize; ++i )
279 const std::shared_ptr<QgsMeshMemoryDataset> dataset = outputGroup->memoryDatasets.at( i );
281 times.push_back( dataset->time );
282 datasetValues.push_back(
283 dataset->datasetValues( outputGroup->isScalar(),
285 dataset->values.size() )
287 if ( !dataset->active.isEmpty() )
289 datasetActive.push_back(
290 dataset->areFacesActive(
292 dataset->active.size() )
298 outputGroup->initialize();
305 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.