Skip to content

Commit

Permalink
[feature] Support datasets with data defined on faces in mesh calcula…
Browse files Browse the repository at this point in the history
…tor (#33248)

* [feature] support datasets with data defined on faces in mesh calculator, fix #30219, fix #30170

added "driver" and "group name" to the calculator interface.
MDAL now supports 3 drivers for storing results, so user must be able to choose appropriate driver and dataset group name (some drivers store multiple groups to 1 file)
  • Loading branch information
PeterPetrik committed Dec 6, 2019
1 parent 60c401a commit b93dfdd
Show file tree
Hide file tree
Showing 23 changed files with 906 additions and 227 deletions.
76 changes: 73 additions & 3 deletions python/analysis/auto_generated/mesh/qgsmeshcalculator.sip.in
Expand Up @@ -22,8 +22,7 @@ Resulting dataset group is added to the mesh layer.
Result can be filtered by extent or a vector layer mask
spatially and by selection of times.

Note: only dataset groups defined on vertices are
implemented and supported
Resulting dataset is always scalar

.. versionadded:: 3.6
%End
Expand All @@ -45,7 +44,49 @@ implemented and supported
MemoryError,
};

QgsMeshCalculator( const QString &formulaString,
const QString &outputFile,
const QgsRectangle &outputExtent,
double startTime,
double endTime,
QgsMeshLayer *layer ) /Deprecated/;
%Docstring
Creates calculator with bounding box (rectangular) mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputFile: file to store the resulting dataset group data
:param outputExtent: spatial filter defined by rectangle
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString

.. deprecated::
QGIS 3.12
%End

QgsMeshCalculator( const QString &formulaString,
const QString &outputFile,
const QgsGeometry &outputMask,
double startTime,
double endTime,
QgsMeshLayer *layer ) /Deprecated/;
%Docstring
Creates calculator with geometry mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputFile: file to store the resulting dataset group data
:param outputMask: spatial filter defined by geometry
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString

.. deprecated::
QGIS 3.12
%End

QgsMeshCalculator( const QString &formulaString,
const QString &outputDriver,
const QString &outputGroupName,
const QString &outputFile,
const QgsRectangle &outputExtent,
double startTime,
Expand All @@ -55,14 +96,20 @@ implemented and supported
Creates calculator with bounding box (rectangular) mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputDriver: output driver name
:param outputGroupName: output group name
:param outputFile: file to store the resulting dataset group data
:param outputExtent: spatial filter defined by rectangle
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString

.. versionadded:: 3.12
%End

QgsMeshCalculator( const QString &formulaString,
const QString &outputDriver,
const QString &outputGroupName,
const QString &outputFile,
const QgsGeometry &outputMask,
double startTime,
Expand All @@ -72,11 +119,15 @@ Creates calculator with bounding box (rectangular) mask
Creates calculator with geometry mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputDriver: output driver name
:param outputGroupName: output group name
:param outputFile: file to store the resulting dataset group data
:param outputMask: spatial filter defined by geometry
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString

.. versionadded:: 3.12
%End

Result processCalculation( QgsFeedback *feedback = 0 );
Expand All @@ -88,14 +139,33 @@ Starts the calculation, writes new dataset group to file and adds it to the mesh
:return: QgsMeshCalculator.Success in case of success
%End

static Result expression_valid( const QString &formulaString, QgsMeshLayer *layer );
static Result expression_valid( const QString &formulaString,
QgsMeshLayer *layer ) /Deprecated/;
%Docstring
Returns whether formula is valid for particular mesh layer

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param layer: mesh layer with dataset groups references in formulaString

:return: QgsMeshCalculator.Success in case of success

.. deprecated::
QGIS 3.12 - use expressionIsValid
%End

static Result expressionIsValid( const QString &formulaString,
QgsMeshLayer *layer,
QgsMeshDriverMetadata::MeshDriverCapability &requiredCapability );
%Docstring
Returns whether formula is valid for particular mesh layer

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param layer: mesh layer with dataset groups references in formulaString
:param requiredCapability: returns required capability of driver to store results of the calculation

:return: QgsMeshCalculator.Success in case of success

.. versionadded:: 3.12
%End

};
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_additions/qgsprovidermetadata.py
@@ -1,4 +1,7 @@
# The following has been generated automatically from src/core/qgsprovidermetadata.h
QgsMeshDriverMetadata.MeshDriverCapability.baseClass = QgsMeshDriverMetadata
QgsMeshDriverMetadata.MeshDriverCapabilities.baseClass = QgsMeshDriverMetadata
MeshDriverCapabilities = QgsMeshDriverMetadata # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
QgsProviderMetadata.FilterType.FilterVector.__doc__ = ""
QgsProviderMetadata.FilterType.FilterRaster.__doc__ = ""
Expand Down
9 changes: 8 additions & 1 deletion python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Expand Up @@ -214,6 +214,13 @@ For scalar and vector 2d the behavior is undefined
%End


QVector<double> values() const;
%Docstring
Returns buffer to the array with values

.. versionadded:: 3.12
%End


};

Expand Down Expand Up @@ -630,7 +637,7 @@ persists it into a destination path

On success, the mesh's dataset group count is changed

:param path: destination path of the stored file
:param path: destination path of the stored file in form DRIVER_NAME:path
:param meta: new group's metadata
:param datasetValues: scalar/vector values for all datasets and all faces/vertices in the group
:param datasetActive: active flag values for all datasets in the group. Empty array represents can be used
Expand Down
71 changes: 69 additions & 2 deletions python/core/auto_generated/qgsprovidermetadata.sip.in
Expand Up @@ -13,6 +13,66 @@



class QgsMeshDriverMetadata
{
%Docstring
Holds metadata about mesh driver

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgsprovidermetadata.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum MeshDriverCapability
{
CanWriteFaceDatasets,
CanWriteVertexDatasets,
};

typedef QFlags<QgsMeshDriverMetadata::MeshDriverCapability> MeshDriverCapabilities;


QgsMeshDriverMetadata();
%Docstring
Constructs default metadata without any capabilities
%End

QgsMeshDriverMetadata( const QString &name,
const QString &description,
const MeshDriverCapabilities &capabilities );
%Docstring
Constructs driver metadata with selected capabilities

:param name: name/key of the driver
:param description: short description of the driver
:param capabilities: driver's capabilities
%End

MeshDriverCapabilities capabilities() const;
%Docstring
Returns the capabilities for this driver.
%End

QString name() const;
%Docstring
Returns the name (key) for this driver.
%End

QString description() const;
%Docstring
Returns the description for this driver.
%End

};

QFlags<QgsMeshDriverMetadata::MeshDriverCapability> operator|(QgsMeshDriverMetadata::MeshDriverCapability f1, QFlags<QgsMeshDriverMetadata::MeshDriverCapability> f2);


class QgsProviderMetadata
{
Expand All @@ -24,10 +84,10 @@ which are native providers that are included in the core QGIS installation
and accessed through function pointers.

For library based providers, the metadata class is used in a lazy load
implementation in QgsProviderRegistry. To save memory, data providers
implementation in :py:class:`QgsProviderRegistry`. To save memory, data providers
are only actually loaded via QLibrary calls if they're to be used. (Though they're all
iteratively loaded once to get their metadata information, and then
unloaded when the QgsProviderRegistry is created.) QgsProviderMetadata
unloaded when the QgsProviderRegistry is created.) :py:class:`QgsProviderMetadata`
supplies enough information to be able to later load the associated shared
library object.
%End
Expand Down Expand Up @@ -104,6 +164,13 @@ Builds the list of file filter strings (supported formats)
Suitable for use in a QFileDialog.getOpenFileNames() call.

.. versionadded:: 3.10
%End

virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
%Docstring
Builds the list of available mesh drivers metadata

.. versionadded:: 3.12
%End

virtual QgsDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options ) /Factory/;
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/mesh/qgsmeshcalcnode.cpp
Expand Up @@ -113,8 +113,8 @@ bool QgsMeshCalcNode::calculate( const QgsMeshCalcUtils &dsu, QgsMeshMemoryData
}
else if ( mType == tOperator )
{
QgsMeshMemoryDatasetGroup leftDatasetGroup( "left" );
QgsMeshMemoryDatasetGroup rightDatasetGroup( "right" );
QgsMeshMemoryDatasetGroup leftDatasetGroup( "left", dsu.outputType() );
QgsMeshMemoryDatasetGroup rightDatasetGroup( "right", dsu.outputType() );

if ( !mLeft || !mLeft->calculate( dsu, leftDatasetGroup ) )
{
Expand All @@ -125,7 +125,7 @@ bool QgsMeshCalcNode::calculate( const QgsMeshCalcUtils &dsu, QgsMeshMemoryData
return false;
}

QgsMeshMemoryDatasetGroup condition( "condition" );
QgsMeshMemoryDatasetGroup condition( "condition", dsu.outputType() );
switch ( mOperator )
{
case opIF:
Expand Down

0 comments on commit b93dfdd

Please sign in to comment.