55#include "moc_qgsmeshlayer.cpp"
57using namespace Qt::StringLiterals;
71 flags |= Qgis::DataProviderReadFlag::LoadDefaultStyle;
73 QgsMeshLayer::setDataSourcePrivate( meshLayerPath, baseName, providerKey, providerOptions,
flags );
86void QgsMeshLayer::createSimplifiedMeshes()
90 if ( mSimplificationSettings.
isEnabled() && !hasSimplifiedMeshes() )
92 const double reductionFactor = mSimplificationSettings.
reductionFactor();
94 QVector<QgsTriangularMesh *> simplifyMeshes = mTriangularMeshes[0]->simplifyMesh( reductionFactor );
96 for (
int i = 0; i < simplifyMeshes.count(); ++i )
98 mTriangularMeshes.emplace_back( simplifyMeshes[i] );
103bool QgsMeshLayer::hasSimplifiedMeshes()
const
108 return ( mTriangularMeshes.size() > 1 );
114 delete mDataProvider;
121 return mDataProvider;
128 return mDataProvider;
138 options.transformContext = mDataProvider->transformContext();
143 layer->mElevationProperties = mElevationProperties->
clone();
144 layer->mElevationProperties->setParent( layer );
152 for (
const QString &extraDataset : mExtraDatasetUri )
167 return mMeshEditor->extent();
170 return mDataProvider->extent();
183 if ( !mDataProvider )
200 for (
const int index : groupsList )
201 assignDefaultStyleToDatasetGroup( index );
205 if ( !groupsList.isEmpty() )
208 mRendererSettings.setActiveScalarDatasetGroup( 0 );
211 if ( meta.
maximum() == std::numeric_limits<double>::quiet_NaN() && meta.
minimum() == std::numeric_limits<double>::quiet_NaN() )
220 mRendererSettings.setNativeMeshSettings( meshSettings );
222 for (
const int i : groupsList )
224 assignDefaultStyleToDatasetGroup( i );
243 applyClassificationOnScalarSettings( meta, scalarSettings );
245 mRendererSettings.setScalarSettings( i, scalarSettings );
248 if ( !groupsList.isEmpty() )
259 const int index = mDatasetGroupStore->indexFromGroupName(
name );
268 mDatasetGroupStore->removeDatasetGroup( index );
270 if ( mExtraDatasetUri.contains( groupMetadata.
uri() ) )
272 mExtraDatasetUri.removeOne( groupMetadata.
uri() );
287 if ( mDatasetGroupStore->addPersistentDatasets( path ) )
289 mExtraDatasetUri.append( path );
291 if ( !isTemporalBefore && temporalCapabilities->hasTemporalCapabilities() )
293 mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( temporalCapabilities );
297 QDateTime referenceTime = defaultReferenceTime;
298 if ( !defaultReferenceTime.isValid() )
299 referenceTime = QDateTime( QDate::currentDate(), QTime( 0, 0, 0 ), Qt::UTC );
303 mTemporalProperties->setIsActive(
true );
316 if ( mDatasetGroupStore->addDatasetGroup( std::unique_ptr< QgsMeshDatasetGroup >( datasetGroup ) ) )
328 return mDatasetGroupStore->saveDatasetGroup( path, datasetGroupIndex, driver );
335 return mNativeMesh.get();
342 return mNativeMesh.get();
349 for (
const std::unique_ptr<QgsTriangularMesh> &lod : mTriangularMeshes )
351 if ( lod && lod->averageTriangleSize() > minimumTriangleSize )
355 if ( !mTriangularMeshes.empty() )
356 return mTriangularMeshes.back().get();
365 return mTriangularMeshes.size();
372 if ( mTriangularMeshes.empty() )
375 return mTriangularMeshes.front().get();
377 if ( lodIndex >=
int( mTriangularMeshes.size() ) )
378 return mTriangularMeshes.back().get();
380 return mTriangularMeshes.at( lodIndex ).get();
395 if ( mTriangularMeshes.empty() )
398 mTriangularMeshes.emplace_back( baseMesh );
401 if ( mTriangularMeshes[0].get()->update( mNativeMesh.get(), transform ) )
402 mTriangularMeshes.resize( 1 );
404 createSimplifiedMeshes();
411 return mRendererCache.get();
418 return mRendererSettings;
425 const int oldActiveScalar = mRendererSettings.activeScalarDatasetGroup();
426 const int oldActiveVector = mRendererSettings.activeVectorDatasetGroup();
427 mRendererSettings = settings;
429 if ( oldActiveScalar != mRendererSettings.activeScalarDatasetGroup() )
432 if ( oldActiveVector != mRendererSettings.activeVectorDatasetGroup() )
447 return mTimeSettings;
454 mTimeSettings = settings;
463 return QgsMeshLayerUtils::formatTime( hours, mTemporalProperties->referenceTime(), mTimeSettings );
465 return QgsMeshLayerUtils::formatTime( hours, QDateTime(), mTimeSettings );
472 return mDatasetGroupStore->datasetGroupCount();
479 return mDatasetGroupStore->extraDatasetGroupCount();
486 return mDatasetGroupStore->datasetGroupIndexes();
493 return mDatasetGroupStore->enabledDatasetGroupIndexes();
500 return mDatasetGroupStore->datasetGroupMetadata( index );
507 return mDatasetGroupStore->datasetCount( index.
group() );
514 return mDatasetGroupStore->datasetMetadata( index );
521 return mDatasetGroupStore->datasetValue( index, valueIndex );
528 return mDatasetGroupStore->datasetValues( index, valueIndex, count );
535 return mDatasetGroupStore->dataset3dValues( index, faceIndex, count );
542 return mDatasetGroupStore->areFacesActive( index, faceIndex, count );
549 return mDatasetGroupStore->isFaceActive( index, faceIndex );
563 const QgsRectangle searchRectangle( point.
x() - searchRadius, point.
y() - searchRadius, point.
x() + searchRadius, point.
y() + searchRadius );
567 if ( faceIndex >= 0 )
584 const int v1 = face[0], v2 = face[1], v3 = face[2];
589 const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
x(), val2.
x(), val3.
x(), point );
590 double y = std::numeric_limits<double>::quiet_NaN();
593 y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
y(), val2.
y(), val3.
y(), point );
608 value = block2d.
value( 0 );
638 if ( faceIndex >= 0 )
654 const int selectedIndex = closestEdge( point, searchRadius, projectedPoint );
656 if ( selectedIndex >= 0 )
670 const int v1 = edge.first, v2 = edge.second;
674 const double edgeLength = p1.
distance( p2 );
675 const double dist1 = p1.
distance( projectedPoint.
x(), projectedPoint.
y() );
676 value = QgsMeshLayerUtils::interpolateFromVerticesData( dist1 / edgeLength, val1, val2 );
700 if ( !mTemporalProperties->isActive() )
703 const QDateTime layerReferenceTime = mTemporalProperties->referenceTime();
704 QDateTime utcTime = timeRange.
begin();
705 if ( utcTime.timeSpec() != Qt::UTC )
706 utcTime.setTimeSpec( Qt::UTC );
707 const qint64 startTime = layerReferenceTime.msecsTo( utcTime );
709 return mDatasetGroupStore->datasetIndexAtTime( startTime, datasetGroupIndex, mTemporalProperties->matchingMethod() );
716 return mDatasetGroupStore->datasetIndexAtTime( relativeTime.
seconds() * 1000, datasetGroupIndex, mTemporalProperties->matchingMethod() );
723 qint64 usedRelativeTime1 = startRelativeTime.
seconds() * 1000;
724 qint64 usedRelativeTime2 = endRelativeTime.
seconds() * 1000;
727 if ( mTemporalProperties->referenceTime().isValid() && mDataProvider && mDataProvider->isValid() && mTemporalProperties->referenceTime() != mDataProvider->temporalCapabilities()->referenceTime() )
729 usedRelativeTime1 = usedRelativeTime1 + mTemporalProperties->referenceTime().msecsTo( mDataProvider->temporalCapabilities()->referenceTime() );
730 usedRelativeTime2 = usedRelativeTime2 + mTemporalProperties->referenceTime().msecsTo( mDataProvider->temporalCapabilities()->referenceTime() );
733 return mDatasetGroupStore->datasetIndexInTimeInterval( usedRelativeTime1, usedRelativeTime2, datasetGroupIndex );
740 if ( meta.
extraOptions().contains( u
"classification"_s ) )
744 const QStringList classes = meta.
extraOptions()[u
"classification"_s].split( u
";;"_s );
750 QVector<QVector<double>> bounds;
751 for (
const QString &classe : classes )
753 const QStringList boundsStr = classe.split(
',' );
754 QVector<double> bound;
755 for (
const QString &boundStr : boundsStr )
756 bound.append( boundStr.toDouble() );
757 bounds.append( bound );
760 if ( ( bounds.count() == 1 && bounds.first().count() > 2 ) ||
761 ( bounds.count() > 1 ) )
763 const QVector<double> firstClass = bounds.first();
764 const QVector<double> lastClass = bounds.last();
765 const double minValue = firstClass.count() > 1 ? ( firstClass.first() + firstClass.last() ) / 2 : firstClass.first();
766 const double maxValue = lastClass.count() > 1 ? ( lastClass.first() + lastClass.last() ) / 2 : lastClass.first();
767 const double diff = maxValue - minValue;
768 QList<QgsColorRampShader::ColorRampItem> colorRampItemlist;
769 for (
int i = 0; i < bounds.count(); ++i )
771 const QVector<double> &boundClass = bounds.at( i );
772 QgsColorRampShader::ColorRampItem item;
774 if ( !boundClass.isEmpty() )
776 const double scalarValue = ( boundClass.first() + boundClass.last() ) / 2;
777 item.
color = colorRamp->
color( ( scalarValue - minValue ) / diff );
778 if ( i != 0 && i < bounds.count() - 1 )
780 item.
label = QString( (
"%1 - %2 %3" ) ).arg( QString::number( boundClass.first() ) ).arg( QString::number( boundClass.last() ) ).arg( units );
783 colorRampItemlist.append( item );
786 if ( firstClass.count() == 1 )
787 colorRampItemlist.first().label = QObject::tr(
"below %1 %2" ).arg( QString::number( firstClass.first() ) ).arg( units );
790 colorRampItemlist.first().label = QString( (
"%1 - %2 %3" ) ).arg( QString::number( firstClass.first() ) ).arg( QString::number( firstClass.last() ) ).arg( units );
793 if ( lastClass.count() == 1 )
794 colorRampItemlist.last().label = QObject::tr(
"above %1 %2" ).arg( QString::number( lastClass.first() ) ).arg( units );
797 colorRampItemlist.last().label = QString( (
"%1 - %2 %3" ) ).arg( QString::number( lastClass.first() ) ).arg( QString::number( lastClass.last() ) ).arg( units );
817 if ( mTemporalProperties->isActive() )
818 return datasetIndexAtTime( timeRange, group >= 0 ? group : mRendererSettings.activeScalarDatasetGroup() );
820 return QgsMeshDatasetIndex( group >= 0 ? group : mRendererSettings.activeScalarDatasetGroup(), mStaticScalarDatasetIndex );
827 if ( mTemporalProperties->isActive() )
828 return datasetIndexAtTime( timeRange, group >= 0 ? group : mRendererSettings.activeVectorDatasetGroup() );
830 return QgsMeshDatasetIndex( group >= 0 ? group : mRendererSettings.activeVectorDatasetGroup(), mStaticVectorDatasetIndex );
833void QgsMeshLayer::fillNativeMesh()
837 Q_ASSERT( !mNativeMesh );
839 mNativeMesh = std::make_unique<QgsMesh>();
847void QgsMeshLayer::onDatasetGroupsAdded(
const QList<int> &datasetGroupIndexes )
852 for (
int datasetGroupIndex : datasetGroupIndexes )
854 if ( !mRendererSettings.hasSettings( datasetGroupIndex ) )
855 assignDefaultStyleToDatasetGroup( datasetGroupIndex );
862void QgsMeshLayer::onMeshEdited()
866 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
876 return mDatasetGroupStore->datasetGroupTreeItem();
883 mDatasetGroupStore->setDatasetGroupTreeItem( rootItem );
884 updateActiveDatasetGroups();
891 return QgsMeshDatasetIndex( group >= 0 ? group : mRendererSettings.activeVectorDatasetGroup(), mStaticVectorDatasetIndex );
899 mTemporalProperties->setReferenceTime( referenceTime, lDataProvider->temporalCapabilities() );
901 mTemporalProperties->setReferenceTime( referenceTime,
nullptr );
908 mTemporalProperties->setMatchingMethod( matchingMethod );
911int QgsMeshLayer::closestEdge(
const QgsPointXY &point,
double searchRadius,
QgsPointXY &projectedPoint )
const
915 const QgsRectangle searchRectangle( point.
x() - searchRadius, point.
y() - searchRadius, point.
x() + searchRadius, point.
y() + searchRadius );
919 int selectedIndex = -1;
923 double sqrMaxDistFromPoint = pow( searchRadius, 2 );
924 for (
const int edgeIndex : edgeIndexes )
930 const double sqrDist = point.
sqrDistToSegment( vertex1.
x(), vertex1.
y(), vertex2.
x(), vertex2.
y(), projPoint, 0 );
931 if ( sqrDist < sqrMaxDistFromPoint )
933 selectedIndex = edgeIndex;
934 projectedPoint = projPoint;
935 sqrMaxDistFromPoint = sqrDist;
940 return selectedIndex;
943int QgsMeshLayer::closestVertex(
const QgsPointXY &point,
double searchRadius,
QgsPointXY &projectedPoint )
const
948 int selectedIndex = -1;
949 projectedPoint = QgsPointXY();
951 return selectedIndex;
953 const QgsRectangle rectangle( point.
x() - searchRadius, point.
y() - searchRadius, point.
x() + searchRadius, point.
y() + searchRadius );
954 double maxDistance = searchRadius;
956 const QList<int> edgeIndexes = mesh->edgeIndexesForRectangle( rectangle );
957 for (
const int edgeIndex : edgeIndexes )
959 const QgsMeshEdge &edge = mesh->edges().at( edgeIndex );
962 const double dist1 = point.
distance( vertex1 );
963 const double dist2 = point.
distance( vertex2 );
964 if ( dist1 < maxDistance )
967 projectedPoint = vertex1;
968 selectedIndex = edge.first;
970 if ( dist2 < maxDistance )
973 projectedPoint = vertex2;
974 selectedIndex = edge.second;
979 const QList<int> faceIndexes = mesh->faceIndexesForRectangle( rectangle );
980 for (
const int faceIndex : faceIndexes )
982 const QgsMeshFace &face = mesh->triangles().at( faceIndex );
983 for (
int i = 0; i < 3; ++i )
986 const double dist = point.
distance( vertex );
987 if ( dist < maxDistance )
990 projectedPoint = vertex;
991 selectedIndex = face.at( i );
996 return selectedIndex;
999int QgsMeshLayer::closestFace(
const QgsPointXY &point,
double searchRadius,
QgsPointXY &projectedPoint )
const
1004 int selectedIndex = -1;
1005 projectedPoint = QgsPointXY();
1007 return selectedIndex;
1009 const QgsRectangle rectangle( point.
x() - searchRadius, point.
y() - searchRadius, point.
x() + searchRadius, point.
y() + searchRadius );
1010 double maxDistance = std::numeric_limits<double>::max();
1012 const QList<int> faceIndexes = mesh->faceIndexesForRectangle( rectangle );
1013 for (
const int faceIndex : faceIndexes )
1015 const int nativefaceIndex = mesh->trianglesToNativeFaces().at( faceIndex );
1016 if ( nativefaceIndex < 0 && nativefaceIndex >= mesh->faceCentroids().count() )
1018 const QgsPointXY centroid = mesh->faceCentroids()[nativefaceIndex];
1019 const double dist = point.
distance( centroid );
1020 if ( dist < maxDistance )
1023 projectedPoint = centroid;
1024 selectedIndex = nativefaceIndex;
1028 return selectedIndex;
1035 mDatasetGroupStore->resetDatasetGroupTreeItem();
1036 updateActiveDatasetGroups();
1043 if ( !mDataProvider )
1045 const int groupCount = mDataProvider->datasetGroupCount();
1046 for (
int i = 0; i < groupCount; ++i )
1048 const qint64 timeStep = mDataProvider->temporalCapabilities()->firstTimeStepDuration( i );
1060 const qint64 time = mDatasetGroupStore->datasetRelativeTime( index );
1072 return mDatasetGroupStore->datasetRelativeTime( index );
1084 message = QObject::tr(
"Face %1 invalid" ).arg( error.
elementIndex );
1087 message = QObject::tr(
"Too many vertices for face %1" ).arg( error.
elementIndex );
1090 message = QObject::tr(
"Face %1 is flat" ).arg( error.
elementIndex );
1093 message = QObject::tr(
"Vertex %1 is a unique shared vertex" ).arg( error.
elementIndex );
1096 message = QObject::tr(
"Vertex %1 is invalid" ).arg( error.
elementIndex );
1099 message = QObject::tr(
"Face %1 is manifold" ).arg( error.
elementIndex );
1130 mSimplificationSettings.setEnabled(
false );
1138 mRendererCache.reset();
1139 error = mMeshEditor->initializeWithErrorsFix();
1142 error = mMeshEditor->initialize();
1146 mMeshEditor->deleteLater();
1147 mMeshEditor =
nullptr;
1154 mDataProvider->close();
1157 mExtraDatasetUri.clear();
1158 mDatasetGroupStore = std::make_unique<QgsMeshDatasetGroupStore>(
this );
1160 mDatasetGroupStore->addDatasetGroup( mMeshEditor->createZValueDatasetGroup() );
1177 QString detailsError;
1178 if ( !mMeshEditor->checkConsistency(
error ) )
1181 detailsError = tr(
"Unknown inconsistent mesh error" );
1186 detailsError = detailsErrorMessage(
error );
1189 if ( !detailsError.isEmpty() )
1197 if ( !mDataProvider )
1200 const bool res = mDataProvider->saveMeshFrame( *mNativeMesh.get() );
1202 if ( continueEditing )
1204 mMeshEditor->initialize();
1209 mMeshEditor->deleteLater();
1210 mMeshEditor =
nullptr;
1213 mDataProvider->reloadData();
1214 mDataProvider->populateMesh( mNativeMesh.get() );
1215 mDatasetGroupStore = std::make_unique<QgsMeshDatasetGroupStore>(
this );
1216 mDatasetGroupStore->setPersistentProvider( mDataProvider, QStringList() );
1227 if ( !mDataProvider )
1230 mTriangularMeshes.clear();
1231 mDataProvider->reloadData();
1232 mDataProvider->populateMesh( mNativeMesh.get() );
1234 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
1237 if ( continueEditing )
1244 mMeshEditor->deleteLater();
1245 mMeshEditor =
nullptr;
1248 mDatasetGroupStore = std::make_unique<QgsMeshDatasetGroupStore>(
this );
1249 mDatasetGroupStore->setPersistentProvider( mDataProvider, QStringList() );
1263 mMeshEditor->stopEditing();
1264 mTriangularMeshes.at( 0 )->update( mNativeMesh.get(), transform );
1265 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
1275 if ( !mMeshEditor->reindex( renumber ) )
1278 mTriangularMeshes.clear();
1280 mTriangularMeshes.at( 0 )->update( mNativeMesh.get(), transform );
1281 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
1282 mMeshEditor->resetTriangularMesh( mTriangularMeshes.at( 0 ).get() );
1299 return mMeshEditor->isModified();
1325 return mMeshEditor->validVerticesCount();
1326 else if ( mDataProvider )
1327 return mDataProvider->vertexCount();
1337 return mMeshEditor->validFacesCount();
1338 else if ( mDataProvider )
1339 return mDataProvider->faceCount();
1349 return mNativeMesh->edgeCount();
1350 else if ( mDataProvider )
1351 return mDataProvider->edgeCount();
1356void QgsMeshLayer::updateActiveDatasetGroups()
1362 if ( !mDatasetGroupStore->datasetGroupTreeItem() )
1371 if ( !activeScalarItem && treeItem->childCount() > 0 && oldActiveScalar != -1 )
1372 activeScalarItem = treeItem->
child( 0 );
1374 if ( activeScalarItem && !activeScalarItem->
isEnabled() )
1376 for (
int i = 0; i < treeItem->childCount(); ++i )
1378 activeScalarItem = treeItem->
child( i );
1382 activeScalarItem =
nullptr;
1386 if ( activeScalarItem )
1391 QgsMeshDatasetGroupTreeItem *activeVectorItem = treeItem->childFromDatasetGroupIndex( oldActiveVector );
1393 if ( !( activeVectorItem && activeVectorItem->
isEnabled() ) )
1406 QString activeScalarName;
1407 QString activeVectorName;
1408 QgsMeshRendererSettings consistentSettings = settings;
1412 for (
auto it = nameToIndex.constBegin(); it != nameToIndex.constEnd(); ++it )
1414 int index = it.value();
1415 const QString
name = it.key();
1416 int globalIndex = mDatasetGroupStore->indexFromGroupName(
name );
1417 if ( globalIndex >= 0 )
1419 QgsMeshRendererScalarSettings scalarSettings = settings.
scalarSettings( index );
1421 if ( settings.
hasVectorSettings( it.value() ) && mDatasetGroupStore->datasetGroupMetadata( globalIndex ).isVector() )
1423 QgsMeshRendererVectorSettings vectorSettings = settings.
vectorSettings( index );
1434 if ( index == activeScalar )
1435 activeScalarName =
name;
1436 if ( index == activeVector )
1437 activeVectorName =
name;
1441 for (
int globalIndex : globalIndexes )
1443 const QString
name = mDatasetGroupStore->groupName( globalIndex );
1444 if ( !nameToIndex.contains(
name ) )
1446 consistentSettings.
setScalarSettings( globalIndex, mRendererSettings.scalarSettings( globalIndex ) );
1447 if ( mDatasetGroupStore->datasetGroupMetadata( globalIndex ).isVector() )
1449 consistentSettings.
setVectorSettings( globalIndex, mRendererSettings.vectorSettings( globalIndex ) );
1454 if ( !activeScalarName.isEmpty() )
1456 if ( !activeVectorName.isEmpty() )
1459 return consistentSettings;
1470 if ( !
mDataSource.isEmpty() && !provider.isEmpty() )
1471 setDataProvider( provider, options,
flags );
1479 closestElement( elementType, point, searchRadius, projectedPoint );
1480 return projectedPoint;
1487 switch ( elementType )
1490 return closestVertex( point, searchRadius, projectedPoint );
1492 return closestEdge( point, searchRadius, projectedPoint );
1494 return closestFace( point, searchRadius, projectedPoint );
1519 expression.
prepare( &context );
1521 for (
int i = 0; i < mNativeMesh->vertexCount(); ++i )
1525 if ( expression.
evaluate( &context ).toBool() )
1552 expression.
prepare( &context );
1554 for (
int i = 0; i < mNativeMesh->faceCount(); ++i )
1558 if ( expression.
evaluate( &context ).toBool() )
1569 return QgsMeshDatasetIndex( group >= 0 ? group : mRendererSettings.activeScalarDatasetGroup(), mStaticScalarDatasetIndex );
1576 const int oldActiveVector = mRendererSettings.activeVectorDatasetGroup();
1581 if ( oldActiveVector != mRendererSettings.activeVectorDatasetGroup() )
1589 const int oldActiveScalar = mRendererSettings.activeScalarDatasetGroup();
1594 if ( oldActiveScalar != mRendererSettings.activeScalarDatasetGroup() )
1602 return mSimplificationSettings;
1609 mSimplificationSettings = simplifySettings;
1620 props[
"color1"] =
"13,8,135,255";
1621 props[
"color2"] =
"240,249,33,255";
1622 props[
"stops"] =
"0.0196078;27,6,141,255:0.0392157;38,5,145,255:0.0588235;47,5,150,255:0.0784314;56,4,154,255:0.0980392;65,4,157,255:"
1623 "0.117647;73,3,160,255:0.137255;81,2,163,255:0.156863;89,1,165,255:0.176471;97,0,167,255:0.196078;105,0,168,255:"
1624 "0.215686;113,0,168,255:0.235294;120,1,168,255:0.254902;128,4,168,255:0.27451;135,7,166,255:0.294118;142,12,164,255:"
1625 "0.313725;149,17,161,255:0.333333;156,23,158,255:0.352941;162,29,154,255:0.372549;168,34,150,255:0.392157;174,40,146,255:"
1626 "0.411765;180,46,141,255:0.431373;186,51,136,255:0.45098;191,57,132,255:0.470588;196,62,127,255:0.490196;201,68,122,255:"
1627 "0.509804;205,74,118,255:0.529412;210,79,113,255:0.54902;214,85,109,255:0.568627;218,91,105,255:0.588235;222,97,100,255:"
1628 "0.607843;226,102,96,255:0.627451;230,108,92,255:0.647059;233,114,87,255:0.666667;237,121,83,255:0.686275;240,127,79,255:"
1629 "0.705882;243,133,75,255:0.72549;245,140,70,255:0.745098;247,147,66,255:0.764706;249,154,62,255:0.784314;251,161,57,255:"
1630 "0.803922;252,168,53,255:0.823529;253,175,49,255:0.843137;254,183,45,255:0.862745;254,190,42,255:0.882353;253,198,39,255:"
1631 "0.901961;252,206,37,255:0.921569;251,215,36,255:0.941176;248,223,37,255:0.960784;246,232,38,255:0.980392;243,240,39,255";
1635void QgsMeshLayer::assignDefaultStyleToDatasetGroup(
int groupIndex )
1640 const double groupMin =
metadata.minimum();
1641 const double groupMax =
metadata.maximum();
1643 QgsColorRampShader fcn( groupMin, groupMax, _createDefaultColorRamp() );
1644 fcn.classifyColorRamp( 5, -1, QgsRectangle(),
nullptr );
1646 QgsMeshRendererScalarSettings scalarSettings;
1649 QgsInterpolatedLineWidth edgeStrokeWidth;
1652 const QgsInterpolatedLineColor edgeStrokeColor( fcn );
1653 const QgsInterpolatedLineRenderer edgeStrokePen;
1655 mRendererSettings.setScalarSettings( groupIndex, scalarSettings );
1659 QgsMeshRendererVectorSettings vectorSettings;
1661 mRendererSettings.setVectorSettings( groupIndex, vectorSettings );
1673 createSimplifiedMeshes();
1676 if ( !mRendererCache )
1677 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
1692 if (
extent.isNull() || !this->extent().intersects(
extent ) )
1702 QVector<double> scalarDatasetValues;
1712 if ( !datasetIndex.
isValid() )
1718 const int count = QgsMeshLayerUtils::datasetValuesCount( mNativeMesh.get(), scalarDataType );
1719 const QgsMeshDataBlock vals = QgsMeshLayerUtils::datasetValues(
this, datasetIndex, 0, count );
1724 scalarDatasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
1728 scalarDatasetValues = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
1733 if ( intersectedFacesIndices.isEmpty() )
1738 min = std::numeric_limits<double>::max();
1739 max = -std::numeric_limits<double>::max();
1743 for (
int intersectedFaceIndex : intersectedFacesIndices )
1750 min = std::min( min, value );
1751 max = std::max( max, value );
1757 for (
int vertexIndex : face )
1759 value = scalarDatasetValues.at( vertexIndex );
1760 min = std::min( min, value );
1761 max = std::max( max, value );
1776void QgsMeshLayer::checkSymbologyConsistency()
1780 const QList<int> groupIndexes = mDatasetGroupStore->datasetGroupIndexes();
1783 if ( !groupIndexes.empty() )
1789 if ( !groupIndexes.contains( mRendererSettings.activeVectorDatasetGroup() ) && mRendererSettings.activeVectorDatasetGroup() != -1 )
1791 mRendererSettings.setActiveVectorDatasetGroup( -1 );
1799 Q_UNUSED( errorMessage )
1802 const QDomElement elem = node.toElement();
1807 const QDomElement elemRendererSettings = elem.firstChildElement(
"mesh-renderer-settings" );
1808 if ( !elemRendererSettings.isNull() )
1811 QMap<QString, int> groupNameToGlobalIndex;
1812 QDomElement nameToIndexElem = elem.firstChildElement(
"name-to-global-index" );
1813 while ( !nameToIndexElem.isNull() )
1815 const QString
name = nameToIndexElem.attribute( u
"name"_s );
1816 int globalIndex = nameToIndexElem.attribute( u
"global-index"_s ).toInt();
1817 groupNameToGlobalIndex.insert(
name, globalIndex );
1818 nameToIndexElem = nameToIndexElem.nextSiblingElement( u
"name-to-global-index"_s );
1821 mRendererSettings = accordSymbologyWithGroupName(
rendererSettings, groupNameToGlobalIndex );
1823 checkSymbologyConsistency();
1825 const QDomElement elemSimplifySettings = elem.firstChildElement(
"mesh-simplify-settings" );
1826 if ( !elemSimplifySettings.isNull() )
1827 mSimplificationSettings.readXml( elemSimplifySettings, context );
1830 const QDomNode blendModeNode = node.namedItem( u
"blendMode"_s );
1831 if ( !blendModeNode.isNull() )
1833 const QDomElement e = blendModeNode.toElement();
1838 if ( categories.testFlag(
Labeling ) )
1842 QDomElement labelingElement = node.firstChildElement( u
"labeling"_s );
1843 if ( !labelingElement.isNull() )
1846 mLabelsEnabled = node.toElement().attribute( u
"labelsEnabled"_s, u
"0"_s ).toInt();
1854 const QDomNode layerOpacityNode = node.namedItem( u
"layerOpacity"_s );
1855 if ( !layerOpacityNode.isNull() )
1857 const QDomElement e = layerOpacityNode.toElement();
1862 if ( categories.testFlag(
Legend ) )
1866 const QDomElement legendElem = node.firstChildElement( u
"legend"_s );
1869 l->readXml( legendElem, context );
1880 Q_UNUSED( errorMessage )
1883 QDomElement elem = node.toElement();
1887 const QDomElement elemRendererSettings = mRendererSettings.writeXml( doc, context );
1888 elem.appendChild( elemRendererSettings );
1892 for (
int index : groupIndexes )
1894 QDomElement elemNameToIndex = doc.createElement( u
"name-to-global-index"_s );
1895 elemNameToIndex.setAttribute( u
"name"_s, mDatasetGroupStore->groupName( index ) );
1896 elemNameToIndex.setAttribute( u
"global-index"_s, index );
1897 elem.appendChild( elemNameToIndex );
1900 const QDomElement elemSimplifySettings = mSimplificationSettings.writeXml( doc, context );
1901 elem.appendChild( elemSimplifySettings );
1904 QDomElement blendModeElement = doc.createElement( u
"blendMode"_s );
1906 blendModeElement.appendChild( blendModeText );
1907 node.appendChild( blendModeElement );
1909 if ( categories.testFlag(
Labeling ) )
1913 QDomElement labelingElement = mLabeling->save( doc, context );
1914 elem.appendChild( labelingElement );
1916 elem.setAttribute( u
"labelsEnabled"_s, mLabelsEnabled ? u
"1"_s : u
"0"_s );
1922 QDomElement layerOpacityElem = doc.createElement( u
"layerOpacity"_s );
1923 const QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
1924 layerOpacityElem.appendChild( layerOpacityText );
1925 node.appendChild( layerOpacityElem );
1931 if ( !legendElement.isNull() )
1932 node.appendChild( legendElement );
1942 return writeSymbology( node, doc, errorMessage, context, categories );
1949 return readSymbology( node, errorMessage, context, categories );
1973 const QDomNode pkeyNode = layer_node.namedItem( u
"provider"_s );
1975 if ( pkeyNode.isNull() )
1981 const QDomElement pkeyElt = pkeyNode.toElement();
1993 const QDomElement elemExtraDatasets = layer_node.firstChildElement( u
"extra-datasets"_s );
1994 if ( !elemExtraDatasets.isNull() )
1996 QDomElement elemUri = elemExtraDatasets.firstChildElement( u
"uri"_s );
1997 while ( !elemUri.isNull() )
2000 mExtraDatasetUri.append( uri );
2001 elemUri = elemUri.nextSiblingElement( u
"uri"_s );
2005 if ( pkeyNode.toElement().hasAttribute( u
"time-unit"_s ) )
2006 mTemporalUnit =
static_cast<Qgis::TemporalUnit>( pkeyNode.toElement().attribute( u
"time-unit"_s ).toInt() );
2009 const QDomElement elemDatasetGroupsStore = layer_node.firstChildElement( u
"mesh-dataset-groups-store"_s );
2010 if ( elemDatasetGroupsStore.isNull() )
2013 mDatasetGroupStore->readXml( elemDatasetGroupsStore, context );
2020 if ( !mTemporalProperties->timeExtent().begin().isValid() || mTemporalProperties->alwaysLoadReferenceTimeFromSource() )
2024 const QDomElement elemStaticDataset = layer_node.firstChildElement( u
"static-active-dataset"_s );
2025 if ( elemStaticDataset.hasAttribute( u
"scalar"_s ) )
2027 mStaticScalarDatasetIndex = elemStaticDataset.attribute( u
"scalar"_s ).toInt();
2029 if ( elemStaticDataset.hasAttribute( u
"vector"_s ) )
2031 mStaticVectorDatasetIndex = elemStaticDataset.attribute( u
"vector"_s ).toInt();
2042 QDomElement mapLayerNode = layer_node.toElement();
2044 if ( mapLayerNode.isNull() || (
"maplayer"_L1 != mapLayerNode.nodeName() ) )
2053 if ( mDataProvider )
2055 QDomElement provider = document.createElement( u
"provider"_s );
2056 const QDomText providerText = document.createTextNode(
providerType() );
2057 provider.appendChild( providerText );
2058 layer_node.appendChild( provider );
2059 provider.setAttribute( u
"time-unit"_s,
static_cast< int >( mDataProvider->temporalCapabilities()->temporalUnit() ) );
2062 QDomElement elemExtraDatasets = document.createElement( u
"extra-datasets"_s );
2066 QDomElement elemUri = document.createElement( u
"uri"_s );
2067 elemUri.appendChild( document.createTextNode( path ) );
2068 elemExtraDatasets.appendChild( elemUri );
2070 layer_node.appendChild( elemExtraDatasets );
2073 QDomElement elemStaticDataset = document.createElement( u
"static-active-dataset"_s );
2074 elemStaticDataset.setAttribute( u
"scalar"_s, mStaticScalarDatasetIndex );
2075 elemStaticDataset.setAttribute( u
"vector"_s, mStaticVectorDatasetIndex );
2076 layer_node.appendChild( elemStaticDataset );
2080 layer_node.appendChild( mDatasetGroupStore->writeXml( document, context ) );
2084 return writeSymbology( layer_node, document, errorMsg, context );
2091 if ( !mMeshEditor && mDataProvider && mDataProvider->isValid() )
2093 mDataProvider->reloadData();
2094 mDatasetGroupStore->setPersistentProvider( mDataProvider, QStringList() );
2098 mNativeMesh = std::make_unique<QgsMesh>();
2102 if ( mTemporalProperties->alwaysLoadReferenceTimeFromSource() )
2103 mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
2106 mTriangularMeshes.clear();
2109 mRendererCache = std::make_unique<QgsMeshLayerRendererCache>();
2111 checkSymbologyConsistency();
2121 if ( mDataProvider )
2122 return mDataProvider->subLayers();
2124 return QStringList();
2132 QString myMetadata = u
"<html>\n<body>\n"_s;
2137 myMetadata += u
"<h1>"_s + tr(
"Information from provider" ) + u
"</h1>\n<hr>\n"_s;
2138 myMetadata +=
"<table class=\"list-view\">\n"_L1;
2141 myMetadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Extent" ) + u
"</td><td>"_s +
extent().
toString() + u
"</td></tr>\n"_s;
2144 QLocale locale = QLocale();
2145 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
2149 myMetadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Vertex count" ) + u
"</td><td>"_s + ( locale.toString(
static_cast<qlonglong
>(
meshVertexCount() ) ) ) + u
"</td></tr>\n"_s;
2150 myMetadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Face count" ) + u
"</td><td>"_s + ( locale.toString(
static_cast<qlonglong
>(
meshFaceCount() ) ) ) + u
"</td></tr>\n"_s;
2151 myMetadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Edge count" ) + u
"</td><td>"_s + ( locale.toString(
static_cast<qlonglong
>(
meshEdgeCount() ) ) ) + u
"</td></tr>\n"_s;
2152 myMetadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Dataset groups count" ) + u
"</td><td>"_s + ( locale.toString(
static_cast<qlonglong
>(
datasetGroupCount() ) ) ) + u
"</td></tr>\n"_s;
2153 myMetadata += provider->htmlMetadata();
2157 myMetadata +=
"</table>\n<br><br>"_L1;
2163 myMetadata += u
"<h1>"_s + tr(
"Identification" ) + u
"</h1>\n<hr>\n"_s;
2164 myMetadata += htmlFormatter.identificationSectionHtml();
2165 myMetadata +=
"<br><br>\n"_L1;
2168 myMetadata += u
"<h1>"_s + tr(
"Extent" ) + u
"</h1>\n<hr>\n"_s;
2169 myMetadata += htmlFormatter.extentSectionHtml(
isSpatial() );
2170 myMetadata +=
"<br><br>\n"_L1;
2173 myMetadata += u
"<h1>"_s + tr(
"Access" ) + u
"</h1>\n<hr>\n"_s;
2174 myMetadata += htmlFormatter.accessSectionHtml();
2175 myMetadata +=
"<br><br>\n"_L1;
2178 myMetadata += u
"<h1>"_s + tr(
"Contacts" ) + u
"</h1>\n<hr>\n"_s;
2179 myMetadata += htmlFormatter.contactsSectionHtml();
2180 myMetadata +=
"<br><br>\n"_L1;
2183 myMetadata += u
"<h1>"_s + tr(
"Links" ) + u
"</h1>\n<hr>\n"_s;
2184 myMetadata += htmlFormatter.linksSectionHtml();
2185 myMetadata +=
"<br><br>\n"_L1;
2188 myMetadata += u
"<h1>"_s + tr(
"History" ) + u
"</h1>\n<hr>\n"_s;
2189 myMetadata += htmlFormatter.historySectionHtml();
2190 myMetadata +=
"<br><br>\n"_L1;
2194 myMetadata +=
"\n</body>\n</html>\n"_L1;
2209 mDatasetGroupStore->setPersistentProvider(
nullptr, QStringList() );
2211 delete mDataProvider;
2217 mDataProvider = qobject_cast< QgsMeshDataProvider * >(
mPreloadedProvider.release() );
2221 std::unique_ptr< QgsScopedRuntimeProfile > profile;
2223 profile = std::make_unique< QgsScopedRuntimeProfile >( tr(
"Create %1 provider" ).arg( provider ), u
"projectload"_s );
2228 if ( !mDataProvider )
2234 mDataProvider->setParent(
this );
2237 setValid( mDataProvider->isValid() );
2244 if ( !mTemporalProperties->isValid() )
2246 mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities(
dataProvider()->temporalCapabilities() );
2249 mDataProvider->setTemporalUnit( mTemporalUnit );
2251 mDatasetGroupStore->setPersistentProvider( mDataProvider, mExtraDatasetUri );
2253 setCrs( mDataProvider->crs() );
2255 if ( provider ==
"mesh_memory"_L1 )
2262 for (
int i = 0; i < mDataProvider->datasetGroupCount(); ++i )
2264 int globalIndex = mDatasetGroupStore->globalDatasetGroupIndexInSource( mDataProvider, i );
2266 assignDefaultStyleToDatasetGroup( globalIndex );
2281 return mTemporalProperties;
2288 return mElevationProperties;
2295 return mLabelsEnabled &&
static_cast< bool >( mLabeling );
2302 mLabelsEnabled = enabled;
2319 if ( !mDataProvider )
2325 if ( mDataProvider->dataSourceUri().contains( path ) )
2328 return !mExtraDatasetUri.contains( path );
Provides global constants and enumerations for use throughout the application.
@ Exact
Assigns the color of the exact matching value in the color ramp item list.
@ Critical
Critical/error message.
@ TooManyVerticesInFace
A face has more vertices than the maximum number supported per face.
@ InvalidFace
An error occurs due to an invalid face (for example, vertex indexes are unordered).
@ UniqueSharedVertex
A least two faces share only one vertices.
@ ManifoldFace
ManifoldFace.
@ InvalidVertex
An error occurs due to an invalid vertex (for example, vertex index is out of range the available ver...
@ FlatFace
A flat face is present.
BlendMode
Blending modes defining the available composition modes that can be used when painting.
TemporalUnit
Temporal units.
@ Milliseconds
Milliseconds.
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
@ EqualInterval
Uses equal interval.
@ Mesh
Mesh layer. Added in QGIS 3.2.
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
Abstract base class - its implementations define different approaches to the labeling of a mesh layer...
static QgsAbstractMeshLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
Abstract base class for objects which generate elevation profiles.
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
void setClassificationMode(Qgis::ShaderClassificationMethod classificationMode)
Sets the classification mode.
QgsColorRamp * sourceColorRamp() const
Returns the source color ramp.
void setColorRampType(Qgis::ShaderInterpolationMethod colorRampType)
Sets the color ramp interpolation method.
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom color map.
Abstract base class for color ramps.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
Contains information about the context in which a coordinate transform is executed.
Base class for handling properties relating to a data provider's temporal capabilities.
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
virtual bool isValid() const =0
Returns true if this is a valid layer.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
static QgsExpressionContextScope * meshExpressionScope(QgsMesh::ElementType elementType)
Creates a new scope which contains functions relating to mesh layer element elementType.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QVariant evaluate()
Evaluate the feature and return the result.
static QgsColorRamp * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsColorRamp from a map of properties.
void setMaximumValue(double maximumValue)
Sets the maximum value used to defined the variable width.
void setMinimumValue(double minimumValue)
Sets the minimum value used to defined the variable width.
A representation of the interval between two datetime values.
double seconds() const
Returns the interval duration in seconds.
Base class for storage of map layer elevation properties.
static QString typeToString(Qgis::LayerType type)
Converts a map layer type to a string value.
An abstract interface for implementations of legends for one map layer.
static QgsMapLayerLegend * defaultMeshLegend(QgsMeshLayer *ml)
Create new legend implementation for mesh layer.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml().
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer temporal properties.
virtual void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities)=0
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsMapLayerLegend * legend() const
Can be nullptr.
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void trigger3DUpdate()
Will advise any 3D maps that this layer requires to be updated in the scene.
static Qgis::DataProviderReadFlags providerReadFlags(const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that...
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
void editingStarted()
Emitted when editing on this layer has started.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QString mLayerName
Name of the layer - used for display.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
QgsLayerMetadata metadata
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
QFlags< StyleCategory > StyleCategories
QString mProviderKey
Data provider key (name of the data provider).
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
void rendererChanged()
Signal emitted when renderer is changed.
virtual QgsError error() const
Gets current status error.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QgsMapLayer::LayerFlags flags
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
void dataChanged()
Data of layer changed.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QString mDataSource
Data source description string, varies by layer type.
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
void setValid(bool valid)
Sets whether layer is valid or not.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
void layerModified()
Emitted when modifications has been done on layer.
void setProviderType(const QString &providerType)
Sets the providerType (provider key).
QString customPropertyHtmlMetadata() const
Returns an HTML fragment containing custom property information, for use in the htmlMetadata() method...
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Abstract class for interpolating 3d stacked mesh data to 2d data.
QgsMeshDataBlock calculate(const QgsMesh3DDataBlock &block3d, QgsFeedback *feedback=nullptr) const
Calculated 2d block values from 3d stacked mesh values.
A block of 3d stacked mesh data related N faces defined on base mesh frame.
A block of integers/doubles from a mesh dataset.
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
bool isValid() const
Whether the block is valid.
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
Base class for providing data for QgsMeshLayer.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices, edges and faces.
Registers and accesses all the dataset groups related to a mesh layer.
void datasetGroupsAdded(QList< int > indexes)
Emitted after dataset groups are added.
Tree item for display of the mesh dataset groups.
int datasetGroupIndex() const
Returns the dataset group index.
QgsMeshDatasetGroupTreeItem * childFromDatasetGroupIndex(int index)
Returns the child with dataset group index Searches as depper as needed on the child hierarchy.
bool isEnabled() const
Returns true if the item is enabled, i.e.
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
Abstract class that represents a dataset group.
An index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
int group() const
Returns a group index.
Represents a single mesh dataset value.
double y() const
Returns y value.
double x() const
Returns x value.
Represents an error which occurred during mesh editing.
Qgis::MeshEditingErrorType errorType
Handles edit operations on a mesh layer.
void meshEdited()
Emitted when the mesh is edited.
Mesh layer specific subclass of QgsMapLayerElevationProperties.
QgsMeshLayerElevationProperties * clone() const override
Creates a clone of the properties.
Implementation of QgsAbstractProfileGenerator for mesh layers.
Implementation of threaded rendering for mesh layers.
Implementation of map layer temporal properties for mesh layers.
int closestElement(QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius, QgsPointXY &projectedPoint) const
Returns the index of the snapped point on the mesh element closest to point intersecting with the sea...
QList< int > selectVerticesByExpression(QgsExpression expression)
Returns a list of vertex indexes that meet the condition defined by expression with the context expre...
void setMeshSimplificationSettings(const QgsMeshSimplificationSettings &meshSimplificationSettings)
Sets mesh simplification settings.
int datasetCount(const QgsMeshDatasetIndex &index) const
Returns the dataset count in the dataset groups.
QList< int > datasetGroupsIndexes() const
Returns the list of indexes of dataset groups handled by the layer.
void stopFrameEditing(const QgsCoordinateTransform &transform)
Stops editing of the mesh, re-indexes the faces and vertices, rebuilds the triangular mesh and its sp...
QgsRectangle extent() const override
Returns the extent of the layer.
void setStaticVectorDatasetIndex(const QgsMeshDatasetIndex &staticVectorDatasetIndex)
Sets the static vector dataset index that is rendered if the temporal properties is not active.
void setStaticScalarDatasetIndex(const QgsMeshDatasetIndex &staticScalarDatasetIndex)
Sets the static scalar dataset index that is rendered if the temporal properties is not active.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDatasetIndex activeScalarDatasetIndex(QgsRenderContext &rendererContext)
Returns current active scalar dataset index for current renderer context.
QgsMeshDatasetIndex activeVectorDatasetAtTime(const QgsDateTimeRange &timeRange, int group=-1) const
Returns dataset index from active vector group depending on the time range If the temporal properties...
QList< QgsMeshDatasetIndex > datasetIndexInRelativeTimeInterval(const QgsInterval &startRelativeTime, const QgsInterval &endRelativeTime, int datasetGroupIndex) const
Returns a list of dataset indexes from datasets group that are in a interval time from the layer refe...
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
int datasetGroupCount() const
Returns the dataset groups count handle by the layer.
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
bool addDatasets(const QString &path, const QDateTime &defaultReferenceTime=QDateTime())
Adds datasets to the mesh from file with path.
bool isModified() const override
Returns whether the mesh frame has been modified since the last save.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
void reload() override
Synchronises with changes in the datasource.
QgsPointXY snapOnElement(QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius)
Returns the position of the snapped point on the mesh element closest to point intersecting with the ...
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
QStringList subLayers() const override
Returns the sublayers of this layer.
QgsMeshEditor * meshEditor()
Returns a pointer to the mesh editor own by the mesh layer.
const QgsAbstractMeshLayerLabeling * labeling() const
Access to const labeling configuration.
void setDatasetGroupTreeRootItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root items of the dataset group tree item.
QgsMeshDatasetValue dataset1dValue(const QgsMeshDatasetIndex &index, const QgsPointXY &point, double searchRadius) const
Returns the value of 1D mesh dataset defined on edge that are in the search area defined by point ans...
QgsMeshDatasetIndex staticVectorDatasetIndex(int group=-1) const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh).
QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags()) override
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
bool minimumMaximumActiveScalarDataset(const QgsRectangle &extent, const QgsMeshDatasetIndex &datasetIndex, double &min, double &max)
Extracts minimum and maximum value for active scalar dataset on mesh faces.
QgsTriangularMesh * triangularMeshByLodIndex(int lodIndex) const
Returns triangular corresponding to the index of level of details.
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
int meshFaceCount() const
Returns the faces count of the mesh frame.
QList< int > selectFacesByExpression(QgsExpression expression)
Returns a list of faces indexes that meet the condition defined by expression with the context expres...
void setRendererSettings(const QgsMeshRendererSettings &settings, const bool repaint=true)
Sets new renderer settings.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
QgsMeshLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
void timeSettingsChanged()
Emitted when time format is changed.
QList< int > enabledDatasetGroupsIndexes() const
Returns the list of indexes of enables dataset groups handled by the layer.
void resetDatasetGroupTreeItem()
Reset the dataset group tree item to default from provider.
int triangularMeshLevelOfDetailCount() const
Returns the count of levels of detail of the mesh simplification.
bool rollBackFrameEditing(const QgsCoordinateTransform &transform, bool continueEditing=true)
Rolls Back editing of the mesh frame.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
QgsMeshDatasetIndex datasetIndexAtRelativeTime(const QgsInterval &relativeTime, int datasetGroupIndex) const
Returns dataset index from datasets group depending on the relative time from the layer reference tim...
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
bool commitFrameEditing(const QgsCoordinateTransform &transform, bool continueEditing=true)
Commits editing of the mesh frame, Rebuilds the triangular mesh and its spatial index with transform,...
QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request) override
Given a profile request, returns a new profile generator ready for generating elevation profiles.
QStringList extraDatasetUris() const
Returns the list of extra dataset URIs associated with this layer.
QgsMeshDataBlock datasetValues(const QgsMeshDatasetIndex &index, int valueIndex, int count) const
Returns N vector/scalar values from the index from the dataset.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const override
Write just the symbology information for the layer into the document.
void setLabeling(QgsAbstractMeshLayerLabeling *labeling)
Sets labeling configuration.
void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
int meshEdgeCount() const
Returns the edges count of the mesh frame.
QgsMeshSimplificationSettings meshSimplificationSettings() const
Returns mesh simplification settings.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
bool isEditable() const override
Returns true if the layer can be edited.
QString loadDefaultStyle(bool &resultFlag) final
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether the faces are active for particular dataset.
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
bool isFaceActive(const QgsMeshDatasetIndex &index, int faceIndex) const
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes.
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset metadata.
bool saveDataset(const QString &path, int datasetGroupIndex, QString driver)
Saves datasets group on file with the specified driver.
bool supportsEditing() const override
Returns whether the layer supports editing or not.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsInterval firstValidTimeStep() const
Returns the first valid time step of the dataset groups, invalid QgInterval if no time step is presen...
QgsInterval datasetRelativeTime(const QgsMeshDatasetIndex &index)
Returns the relative time of the dataset from the reference time of its group.
QgsMeshDatasetIndex datasetIndexAtTime(const QgsDateTimeRange &timeRange, int datasetGroupIndex) const
Returns dataset index from datasets group depending on the time range.
Q_DECL_DEPRECATED bool startFrameEditing(const QgsCoordinateTransform &transform)
Starts editing of the mesh frame.
bool reindex(const QgsCoordinateTransform &transform, bool renumber)
Re-indexes the faces and vertices, and renumber the indexes if renumber is true.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, int valueIndex) const
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
QgsMeshLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib=u"mesh_memory"_s, const QgsMeshLayer::LayerOptions &options=QgsMeshLayer::LayerOptions())
Constructor - creates a mesh layer.
QgsMeshTimeSettings timeSettings() const
Returns time format settings.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
Write the style for the layer into the document provided.
int meshVertexCount() const
Returns the vertices count of the mesh frame.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
void setReferenceTime(const QDateTime &referenceTime)
Sets the reference time of the layer.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) override
Read the style for the current layer from the DOM node supplied.
int extraDatasetGroupCount() const
Returns the extra dataset groups count handle by the layer.
bool datasetsPathUnique(const QString &path)
Checks whether that datasets path is already added to this mesh layer.
qint64 datasetRelativeTimeInMilliseconds(const QgsMeshDatasetIndex &index)
Returns the relative time (in milliseconds) of the dataset from the reference time of its group.
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange, int group=-1) const
Returns dataset index from active scalar group depending on the time range.
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
QgsMeshDatasetIndex staticScalarDatasetIndex(int group=-1) const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
void setTemporalMatchingMethod(const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod)
Sets the method used to match the temporal dataset from a requested time, see activeVectorDatasetAtTi...
bool removeDatasets(const QString &name)
Removes datasets from the mesh with given name.
QgsMeshDatasetGroupTreeItem * datasetGroupTreeRootItem() const
Returns the root items of the dataset group tree item.
QgsMesh3DDataBlock dataset3dValues(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes.
QgsMesh3DDataBlock dataset3dValue(const QgsMeshDatasetIndex &index, const QgsPointXY &point) const
Returns the 3d values of stacked 3d mesh defined by the given point.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
void reloaded()
Emitted when the mesh layer is reloaded, see reload().
QString formatTime(double hours)
Returns (date) time in hours formatted to human readable form.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering).
void setTimeSettings(const QgsMeshTimeSettings &settings)
Sets time format settings.
Represents a mesh renderer settings for mesh objects.
void setEnabled(bool enabled)
Sets whether mesh structure rendering is enabled.
Represents a mesh renderer settings for scalar datasets.
void setClassificationMinimumMaximum(double minimum, double maximum)
Sets min/max values used for creation of the color ramp shader.
void setColorRampShader(const QgsColorRampShader &shader)
Sets color ramp shader function.
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
@ NoResampling
Does not use resampling.
@ NeighbourAverage
Does a simple average of values defined for all surrounding faces/vertices.
void setEdgeStrokeWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to render edges scalar dataset.
void setDataResamplingMethod(const DataResamplingMethod &dataResamplingMethod)
Sets data interpolation method.
Represents all mesh renderer settings.
void setActiveVectorDatasetGroup(int activeVectorDatasetGroup)
Sets the active vector dataset group.
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
bool hasVectorSettings(int groupIndex) const
Returns whether groupIndex has existing vector settings.
bool removeVectorSettings(int groupIndex)
Removes vector settings for groupIndex.
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
void setActiveScalarDatasetGroup(int activeScalarDatasetGroup)
Sets the active scalar dataset group.
void setVectorSettings(int groupIndex, const QgsMeshRendererVectorSettings &settings)
Sets new renderer settings.
bool removeScalarSettings(int groupIndex)
Removes scalar settings with groupIndex.
void setScalarSettings(int groupIndex, const QgsMeshRendererScalarSettings &settings)
Sets new renderer settings.
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Returns the color ramp shader used to render vector datasets.
Represents an overview renderer settings.
double reductionFactor() const
Returns the reduction factor used to build simplified mesh.
bool isEnabled() const
Returns if the overview is active.
Represents a mesh time settings for mesh datasets.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
double sqrDistToSegment(double x1, double y1, double x2, double y2, QgsPointXY &minDistPoint, double epsilon=Qgis::DEFAULT_SEGMENT_EPSILON) const
Returns the minimum distance between this point and a segment.
Point geometry type, with support for z-dimension and m-values.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
Allows entering a context category and takes care of leaving this category on deletion of the class.
A container for the context for various read/write operations on objects.
QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be rounded to the spec...
void setNull()
Mark a rectangle as being null (holding no spatial information).
Contains information about the context of a rendering operation.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
void setIsActive(bool active)
Sets whether the temporal property is active.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
T begin() const
Returns the beginning of the range.
static QgsMeshEditingError checkTopology(const QgsMesh &mesh, int maxVerticesPerFace)
Checks the topology of the mesh mesh, if error occurs, this mesh can't be edited.
A triangular/derived mesh with vertices in map coordinates.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
QList< int > edgeIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of edges intersecting given bounding box It uses spatial indexing.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
const QVector< QgsMeshEdge > & edges() const
Returns edges.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains mesh elements of given type.
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
int faceIndexForPoint_v2(const QgsPointXY &point) const
Finds index of triangle at given point It uses spatial indexing and don't use geos to be faster.
#define QgsDebugMsgLevel(str, level)
#define INVALID_MESHLAYER_TIME
QVector< int > QgsMeshFace
List of vertex indexes.
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
QgsPoint QgsMeshVertex
xyz coords of vertex
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.
Setting options for loading mesh layers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Mesh - vertices, edges and faces.
ElementType
Defines type of mesh elements.