QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
24 : mGroupIndex( group ), mDatasetIndex( dataset )
65 if ( std::isnan( mY ) )
69 else if ( std::isnan( mX ) )
71 return std::numeric_limits<double>::quiet_NaN();
75 return std::sqrt( ( mX ) * ( mX ) + ( mY ) * ( mY ) );
106 bool equal = std::isnan( mX ) == std::isnan( other.
x() );
107 equal &= std::isnan( mY ) == std::isnan( other.
y() );
111 if ( std::isnan( mY ) )
130 int maximumVerticalLevels,
131 const QDateTime &referenceTime,
133 const QMap<QString, QString> &extraOptions )
136 , mIsScalar( isScalar )
137 , mDataType( dataType )
138 , mMinimumValue( minimum )
139 , mMaximumValue( maximum )
140 , mExtraOptions( extraOptions )
141 , mMaximumVerticalLevelsCount( maximumVerticalLevels )
142 , mReferenceTime( referenceTime )
143 , mIsTemporal( isTemporal )
149 return mExtraOptions;
179 return mMinimumValue;
184 return mMaximumValue;
189 return mMaximumVerticalLevelsCount;
194 return mReferenceTime;
207 int maximumVerticalLevels )
209 , mIsValid( isValid )
210 , mMinimumValue( minimum )
211 , mMaximumValue( maximum )
212 , mMaximumVerticalLevelsCount( maximumVerticalLevels )
228 return mMinimumValue;
233 return mMaximumValue;
238 return mMaximumVerticalLevelsCount;
242 : mType( ActiveFlagInteger )
264 return (
count() > 0 ) && ( mIsValid );
278 mDoubleBuffer[2 * index],
279 mDoubleBuffer[2 * index + 1]
290 if ( mIntegerBuffer.empty() )
293 return bool( mIntegerBuffer[index] );
299 Q_ASSERT( vals.size() ==
count() );
301 mIntegerBuffer = vals;
308 return mIntegerBuffer;
315 return mDoubleBuffer;
323 mDoubleBuffer = vals;
338 , mIsVector( isVector )
359 if ( mFaceToVolumeIndex.empty() )
361 return mFaceToVolumeIndex[0];
366 if ( mFaceToVolumeIndex.empty() || mVerticalLevelsCount.empty() )
368 const int lastVolumeStartIndex = mFaceToVolumeIndex[mFaceToVolumeIndex.size() - 1];
369 const int volumesCountInLastRow = mVerticalLevelsCount[mVerticalLevelsCount.size() - 1];
370 return lastVolumeStartIndex + volumesCountInLastRow;
381 return mVerticalLevelsCount;
399 return mVerticalLevels;
411 return mFaceToVolumeIndex;
417 return mDoubleBuffer;
429 mDoubleBuffer[2 * volumeIndex],
430 mDoubleBuffer[2 * volumeIndex + 1]
437 mDoubleBuffer = doubleBuffer;
450 : mOriginalName( defaultName )
451 , mSourceName( sourceName )
452 , mIsVector( isVector )
453 , mDatasetGroupIndex( index )
460 if ( itemElement.hasAttribute( QStringLiteral(
"display-name" ) ) )
461 mUserName = itemElement.attribute( QStringLiteral(
"display-name" ), mUserName );
463 if ( itemElement.hasAttribute( QStringLiteral(
"original-name" ) ) )
464 mOriginalName = itemElement.attribute( QStringLiteral(
"original-name" ), mOriginalName );
466 if ( itemElement.hasAttribute( QStringLiteral(
"source-name" ) ) )
467 mSourceName = itemElement.attribute( QStringLiteral(
"source-name" ), mSourceName );
469 if ( itemElement.hasAttribute( QStringLiteral(
"is-vector" ) ) )
470 mIsVector = itemElement.attribute( QStringLiteral(
"is-vector" ) ).toInt();
472 if ( itemElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
473 mDatasetGroupIndex = itemElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt();
475 if ( itemElement.hasAttribute( QStringLiteral(
"is-enabled" ) ) )
476 mIsEnabled = itemElement.attribute( QStringLiteral(
"is-enabled" ) ).toInt();
478 if ( itemElement.hasAttribute( QStringLiteral(
"dataset-group-type" ) ) )
479 mDatasetGroupType =
static_cast<QgsMeshDatasetGroup::Type>( itemElement.attribute( QStringLiteral(
"dataset-group-type" ) ) .toInt() ) ;
481 if ( itemElement.hasAttribute( QStringLiteral(
"description" ) ) )
482 mDescription = itemElement.attribute( QStringLiteral(
"description" ) );
484 QDomElement dependOnElement = itemElement.firstChildElement( QStringLiteral(
"dependent-on-item" ) );
485 while ( !dependOnElement.isNull() )
487 if ( dependOnElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
488 mDatasetGroupDependentOn.append( dependOnElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt() );
489 dependOnElement = dependOnElement.nextSiblingElement( QStringLiteral(
"dependent-on-item" ) );
492 QDomElement dependencieElement = itemElement.firstChildElement( QStringLiteral(
"dependency-item" ) );
493 while ( !dependencieElement.isNull() )
495 if ( dependencieElement.hasAttribute( QStringLiteral(
"dataset-index" ) ) )
496 mDatasetGroupDependencies.append( dependencieElement.attribute( QStringLiteral(
"dataset-index" ) ).toInt() );
497 dependencieElement = dependencieElement.nextSiblingElement( QStringLiteral(
"dependency-item" ) );
500 QDomElement childElement = itemElement.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
501 while ( !childElement.isNull() )
504 childElement = childElement.nextSiblingElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
513 freeFromDependencies();
514 qDeleteAll( mChildren );
517 mParent->mDatasetGroupIndexToChild.remove( mDatasetGroupIndex );
518 mParent->mChildren.removeOne(
this );
527 other->mChildren.clear();
528 other->mDatasetGroupIndexToChild.clear();
529 if ( !mChildren.empty() )
530 for (
int i = 0; i < mChildren.count(); ++i )
538 mChildren.append( item );
539 item->mParent =
this;
550 if (
row < mChildren.count() )
551 return mChildren.at(
row );
558 if ( mDatasetGroupIndexToChild.empty() )
561 const QMap<int, QgsMeshDatasetGroupTreeItem *>::iterator it = mDatasetGroupIndexToChild.find( index );
563 if ( it != mDatasetGroupIndexToChild.end() )
568 for (
int i = 0; i < mChildren.count(); ++i )
570 item = mChildren.at( i )->childFromDatasetGroupIndex( index );
580 return mChildren.count();
586 for (
int i = 0; i < mChildren.count(); ++i )
589 count += mChildren.at( i )->totalChildCount();
596 QList<int> indexesList;
598 for (
int i = 0; i < mChildren.count(); ++i )
600 if ( mChildren.at( i )->isEnabled() )
601 indexesList.append( mChildren.at( i )->datasetGroupIndex() );
602 indexesList.append( mChildren.at( i )->enabledDatasetGroupIndexes() );
623 if ( mUserName.isEmpty() )
624 return mOriginalName;
636 return mDatasetGroupIndex;
646 mIsEnabled = enabled;
651 return mOriginalName;
656 return mDatasetGroupType;
669 mDatasetGroupType = datasetGroup->
type();
671 for (
const QString &varName : datasetGroupNames )
686 mDatasetGroupDependentOn.clear();
694 QDomElement itemElement = doc.createElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
695 itemElement.setAttribute( QStringLiteral(
"display-name" ), mUserName );
696 itemElement.setAttribute( QStringLiteral(
"source-name" ), mSourceName );
697 itemElement.setAttribute( QStringLiteral(
"original-name" ), mOriginalName );
698 itemElement.setAttribute( QStringLiteral(
"is-vector" ), mIsVector ?
true :
false );
699 itemElement.setAttribute( QStringLiteral(
"dataset-index" ), mDatasetGroupIndex );
700 itemElement.setAttribute( QStringLiteral(
"is-enabled" ), mIsEnabled ?
true :
false );
701 itemElement.setAttribute( QStringLiteral(
"dataset-group-type" ), mDatasetGroupType );
702 itemElement.setAttribute( QStringLiteral(
"description" ), mDescription );
704 for (
const int index : mDatasetGroupDependentOn )
706 QDomElement dependOnElement = doc.createElement( QStringLiteral(
"dependent-on-item" ) );
707 dependOnElement.setAttribute( QStringLiteral(
"dataset-index" ), index );
708 itemElement.appendChild( dependOnElement );
711 for (
const int index : mDatasetGroupDependencies )
713 QDomElement dependencieElement = doc.createElement( QStringLiteral(
"dependency-item" ) );
714 dependencieElement.setAttribute( QStringLiteral(
"dataset-index" ), index );
715 itemElement.appendChild( dependencieElement );
718 for (
int i = 0; i < mChildren.count(); ++i )
719 itemElement.appendChild( mChildren.at( i )->writeXml( doc, context ) );
726 QList<int> dependencies;
728 for (
const int index : mDatasetGroupDependencies )
730 if ( !dependencies.contains( index ) )
731 dependencies.append( index );
749 QList<QgsMeshDatasetGroupTreeItem *> itemToCheck;
750 itemToCheck.append( baseItem );
751 while ( baseItem && baseItem->
providerName() != sourceName && !itemToCheck.isEmpty() )
753 for (
int i = 0; i < baseItem->
childCount(); ++i )
754 itemToCheck.append( baseItem->
child( i ) );
755 itemToCheck.removeOne( baseItem );
756 if ( !itemToCheck.empty() )
757 baseItem = itemToCheck.first();
774 void QgsMeshDatasetGroupTreeItem::freeAsDependency()
777 for (
const int index : mDatasetGroupDependentOn )
785 void QgsMeshDatasetGroupTreeItem::freeFromDependencies()
788 for (
const int index : mDatasetGroupDependencies )
809 if ( valueIndex >= 0 && valueIndex <
values.count() )
810 return values[valueIndex];
818 QVector<double> buf( isScalar ? count : 2 * count );
819 for (
int i = 0; i < count; ++i )
821 const int idx = valueIndex + i;
822 if ( ( idx < 0 ) || ( idx >=
values.size() ) )
830 buf[2 * i] = val.
x();
831 buf[2 * i + 1] = val.
y();
843 ( faceIndex + count >
active.size() )
858 double min = std::numeric_limits<double>::max();
859 double max = std::numeric_limits<double>::lowest();
865 bool firstIteration =
true;
866 for (
int i = 0; i <
values.size(); ++i )
868 const double v =
values[i].scalar();
870 if ( std::isnan( v ) )
872 if ( firstIteration )
874 firstIteration =
false;
896 return active.at( faceIndex );
973 return QDomElement();
983 mIsStatisticObsolete =
true;
988 return QStringList();
998 mReferenceTime = referenceTime;
1001 void QgsMeshDatasetGroup::updateStatictic()
const
1003 if ( !mIsStatisticObsolete )
1006 double min = std::numeric_limits<double>::max();
1007 double max = std::numeric_limits<double>::lowest();
1010 for (
int i = 0; i < count; ++i )
1013 min = std::min( min, meta.
minimum() );
1014 max = std::max( max, meta.
maximum() );
1019 mIsStatisticObsolete =
false;
1031 : mName( name ), mDataType( dataType ) {}
1102 if ( mMesh && valueIndex >= 0 && valueIndex < mMesh->vertexCount() )
1103 return mMesh->
vertex( valueIndex ).
z();
1105 return std::numeric_limits<double>::quiet_NaN();
1110 if ( !isScalar || !mMesh )
1114 int effectiveValueCount = std::min( count, ( mMesh->
vertexCount() - valueIndex ) );
1115 QVector<double> values( effectiveValueCount );
1116 for (
int i = valueIndex; i < effectiveValueCount; ++i )
1117 values[i] = mMesh->
vertex( i - valueIndex ).
z();
1132 double min = std::numeric_limits<double>::max();
1133 double max = -std::numeric_limits<double>::max();
1137 const double z = mMesh->
vertex( i ).
z();
1169 if ( datasetIndex != 0 )
1172 return mDataset->metadata();
1182 return mDataset.get();
int dataset() const
Returns a dataset index within group()
QVector< int > faceToVolumeIndex() const
Returns the indexing between faces and volumes.
void setValues(const QVector< double > &doubleBuffer)
Sets the values at volume centers.
QgsMeshVerticesElevationDatasetGroup(QString name, QgsMesh *mesh)
Constructor with a name and linked to mesh.
QgsMeshDatasetGroup()=default
Default constructor.
QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const override
Returns the metadata of the dataset with index datasetIndex.
void setIsScalar(bool isScalar)
Sets whether the group contain scalar values.
void initialize() override
Initialize the dataset group.
int totalChildCount() const
Returns the total count of children, that is included deeper children and disabled items.
QgsMeshDataBlock()
Constructs an invalid block.
void setMinimumMaximum(double min, double max) const
Overrides the minimum and the maximum value of the whole dataset group.
The class is used as a container of context for various read/write operations on other objects.
void setY(double y)
Sets Y value.
@ ScalarDouble
Scalar double values.
QgsMeshDataBlock areFacesActive(int faceIndex, int count) const override
Returns whether faces are active.
QVector< int > active() const
Returns active flag array.
int valuesCount() const override
Returns the values count.
QList< int > enabledDatasetGroupIndexes() const
Returns a list of enabled dataset group indexes, included deeper children.
QgsMeshDatasetGroupTreeItem * parentItem() const
Returns the parent item, nullptr if it is root item.
bool isValid() const
Whether the block is valid.
~QgsMesh3dDataBlock()
Dtor.
virtual int datasetCount() const =0
Returns the count of datasets in the group.
bool isActive(int faceIndex) const override
Returns whether the face is active.
int valuesCount() const override
Returns the values count.
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetMetadata metadata() const override
Returns the metadata of the dataset.
QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const override
Returns the metadata of the dataset with index datasetIndex.
Abstract class that represents a dataset.
QgsMeshVerticesElevationDataset(QgsMesh *mesh)
Constructor.
@ Persistent
Generic type used for non typed dataset group.
QString defaultName() const
void setVerticalLevelsCount(const QVector< int > &verticalLevelsCount)
Sets the vertical level counts.
Tree item for display of the mesh dataset groups. Dataset group is set of datasets with the same name...
Mesh - vertices, edges and faces.
QVector< double > values() const
Returns the values at volume centers.
bool operator!=(QgsMeshDatasetIndex other) const
Inequality operator.
QgsMeshDatasetIndex(int group=-1, int dataset=-1)
Creates an index. -1 represents invalid group/dataset.
QgsMeshDatasetGroupTreeItem * clone() const
Clones the item.
DataType type() const
Type of data stored in the block.
void setReferenceTime(const QDateTime &referenceTime)
Sets the reference time of the dataset group.
QgsMeshDatasetGroup::Type datasetGroupType() const
void addDataset(std::shared_ptr< QgsMeshMemoryDataset > dataset)
Adds a memory dataset to the group.
QgsMeshDataBlock areFacesActive(int faceIndex, int count) const override
Returns whether faces are active.
int lastVolumeIndex() const
Index of the last volume stored in the buffer (absolute)
double maximum() const
Returns the maximum value of the whole dataset group.
Class that represents a dataset with elevation value of the vertices of a existing mesh that can be e...
QgsMesh3dDataBlock()
Constructs an invalid block.
int faceCount() const
Returns number of faces.
int group() const
Returns a group index.
int vertexCount() const
Returns number of vertices.
void removeChild(QgsMeshDatasetGroupTreeItem *item)
Removes a item child if exists.
QgsMeshDatasetValue datasetValue(int valueIndex) const override
Returns the value with index valueIndex.
QgsMeshDatasetGroupTreeItem()
Constructor for an empty dataset group tree item.
int childCount() const
Returns the count of children.
@ Vector2DDouble
Vector double pairs (x1, y1, x2, y2, ... )
QgsMeshDatasetGroupTreeItem * childFromDatasetGroupIndex(int index)
Returns the child with dataset group index Searches as depper as needed on the child hierarchy.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g. wind speed) and a dataset in thi...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setPersistentDatasetGroup(const QString &uri)
Set parameters of the item in accordance with the persistent dataset group with uri.
QVector< int > verticalLevelsCount() const
Returns number of vertical level above 2d faces.
QString description() const
Returns description about the dataset group (URI, formula,...)
QString name() const
Returns the name of the item This name is the default name if the name has not been overridden (.
QgsMeshDatasetValue datasetValue(int valueIndex) const override
Returns the value with index valueIndex.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
bool isVector() const
Whether we store vector values.
void set(double scalar)
Sets scalar value.
bool operator==(QgsMeshDatasetIndex other) const
Equality operator.
double x() const
Returns x value.
void calculateMinMax()
Calculates the minimum and the maximum of this group.
std::shared_ptr< const QgsMeshMemoryDataset > constDataset(int index) const
Returns the dataset with index.
DataType
Type of data stored in the block.
int count() const
Number of 2d faces for which the volume data is stored in the block.
QgsMeshDataset * dataset(int index) const override
Returns the dataset with index.
void addExtraMetadata(QString key, QString value)
Adds extra metadata to the group.
void setDatasetGroup(QgsMeshDatasetGroup *datasetGroup)
Set parameters of the item in accordance with the dataset group.
double minimum() const
Returns the minimum value of the whole dataset group.
void setFaceToVolumeIndex(const QVector< int > &faceToVolumeIndex)
Sets the indexing between faces and volumes.
QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const override
Returns count values from valueIndex.
virtual QgsMeshDatasetGroup::Type type() const =0
Returns the type of dataset group.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
void setValid(bool valid)
Sets block validity.
bool isScalar() const
Returns whether the group contain scalar values.
Abstract class that represents a dataset group.
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
QgsMeshDatasetGroupMetadata::DataType mDataType
QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const override
Returns count values from valueIndex.
QList< int > groupIndexDependencies() const
Returns a list of group index corresponding to dataset group that depends on the dataset group repres...
QgsMeshDatasetGroup::Type type() const override
Returns the type of dataset group.
QMap< QString, QString > mMetadata
void calculateStatistic() const
Calculates the statistics (minimum and maximum)
void setActive(const QVector< int > &vals)
Sets active flag values.
QgsMeshMemoryDatasetGroup()=default
Constructor.
QVector< double > values() const
Returns buffer to the array with values For vector it is pairs (x1, y1, x2, y2, .....
QgsMeshDataset * dataset(int index) const override
Returns the dataset with index.
@ ActiveFlagInteger
Integer boolean flag whether face is active.
virtual QString description() const
Returns some information about the dataset group.
void appendChild(QgsMeshDatasetGroupTreeItem *item)
Appends a child item.
int volumesCount() const
Returns number of volumes stored in the buffer.
QMap< QString, QString > extraMetadata() const
Returns all the extra metadata of the group.
Type
Type of the dataset group.
void setValues(const QVector< double > &vals)
Sets values.
QgsMeshDatasetGroupMetadata::DataType dataType() const
Returns the data type of the dataset group.
int datasetCount() const override
Returns the count of datasets in the group.
bool operator==(QgsMeshDatasetValue other) const
double y() const
Returns y value.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Writes the item and its children in a DOM document.
virtual QStringList datasetGroupNamesDependentOn() const
Returns the dataset group variable name which this dataset group depends on.
QVector< std::shared_ptr< QgsMeshMemoryDataset > > memoryDatasets
Contains all the memory datasets.
QVector< double > verticalLevels() const
Returns the vertical levels height.
void setX(double x)
Sets X value.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
virtual ~QgsMeshDatasetGroup()
void initialize() override
Initialize the dataset group.
int datasetGroupIndex() const
QString name() const
Returns the name of the dataset group.
~QgsMeshDatasetGroupTreeItem()
Destructor, destructs also the children.
QgsMeshDatasetGroupMetadata groupMetadata() const
Returns the metadata of the dataset group.
QgsMeshDatasetMetadata metadata() const override
Returns the metadata of the dataset.
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
void setName(const QString &name)
Overrides the default name with the name to display.
void setStatisticObsolete() const
Sets statistic obsolete, that means statistic will be recalculated when requested.
int firstVolumeIndex() const
Index of the first volume stored in the buffer (absolute)
void setIsEnabled(bool isEnabled)
Sets whether the item is enabled, that is if it is displayed in view.
QgsMeshDatasetValue value(int volumeIndex) const
Returns the value at volume centers.
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
void setValid(bool valid)
Sets block validity.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.
int datasetCount() const override
Returns the count of datasets in the group.
virtual int valuesCount() const =0
Returns the values count.
void setName(const QString &name)
Sets the name of the dataset group.
bool checkValueCountPerDataset(int count) const
Returns whether all the datasets contain count values.
void setVerticalLevels(const QVector< double > &verticalLevels)
Sets the vertical levels height.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns a invalid DOM element.
QString providerName() const
Returns the name used by the provider to identify the dataset.
void clearDatasets()
Removes all the datasets from the group.
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
int row() const
Returns the position of the item in the parent.
void setDataType(const QgsMeshDatasetGroupMetadata::DataType &dataType)
Sets the data type of the dataset group.
@ Memory
Dataset group store in a file.
bool isValid() const
Whether the block is valid.
int count() const
Number of items stored in the block.
QVector< QgsMeshDatasetValue > values