35static QgsFields createFields(
const QList<QgsMeshDatasetGroupMetadata> &groupMetadataList,
int vectorOption )
40 if ( meta.isVector() )
42 if ( vectorOption == 0 || vectorOption == 2 )
44 fields.
append(
QgsField( QStringLiteral(
"%1_x" ).arg( meta.name() ), QMetaType::Type::Double ) );
45 fields.
append(
QgsField( QStringLiteral(
"%1_y" ).arg( meta.name() ), QMetaType::Type::Double ) );
48 if ( vectorOption == 1 || vectorOption == 2 )
50 fields.
append(
QgsField( QStringLiteral(
"%1_mag" ).arg( meta.name() ), QMetaType::Type::Double ) );
51 fields.
append(
QgsField( QStringLiteral(
"%1_dir" ).arg( meta.name() ), QMetaType::Type::Double ) );
62 QVector<double> ret( exportOption == 2 ? 4 : 2 );
64 if ( exportOption == 0 || exportOption == 2 )
69 if ( exportOption == 1 || exportOption == 2 )
73 double magnitude = sqrt( x * x + y * y );
74 double direction = ( asin( x / magnitude ) ) / M_PI * 180;
76 direction = 180 - direction;
78 if ( exportOption == 1 )
83 if ( exportOption == 2 )
96 QVector<double> vectorValues = vectorValue( value, vectorOption );
97 for (
double v : vectorValues )
99 if ( v == std::numeric_limits<double>::quiet_NaN() )
100 attributes.append( QVariant() );
102 attributes.append( v );
107 if ( value.
scalar() == std::numeric_limits<double>::quiet_NaN() )
108 attributes.append( QVariant() );
110 attributes.append( value.
scalar() );
117 int triangularFaceIndex,
124 bool faceActive = activeFaces.
active( nativeFaceIndex );
136 value = datasetValues.
value( nativeFaceIndex );
143 const int v1 = face[0], v2 = face[1], v3 = face[2];
148 const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
x(), val2.
x(), val3.
x(), point );
149 double y = std::numeric_limits<double>::quiet_NaN();
150 bool isVector = metadata.
isVector();
152 y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.
y(), val2.
y(), val3.
y(), point );
163QString QgsExportMeshOnElement::group()
const
165 return QObject::tr(
"Mesh" );
168QString QgsExportMeshOnElement::groupId()
const
170 return QStringLiteral(
"mesh" );
173QString QgsExportMeshVerticesAlgorithm::shortHelpString()
const
175 return QObject::tr(
"This algorithm exports a mesh layer's vertices to a point vector layer, with the dataset values on vertices as attribute values." );
178QString QgsExportMeshVerticesAlgorithm::shortDescription()
const
180 return QObject::tr(
"Exports mesh vertices to a point vector layer" );
183QString QgsExportMeshVerticesAlgorithm::name()
const
185 return QStringLiteral(
"exportmeshvertices" );
188QString QgsExportMeshVerticesAlgorithm::displayName()
const
190 return QObject::tr(
"Export mesh vertices" );
195 return new QgsExportMeshVerticesAlgorithm();
198QgsGeometry QgsExportMeshVerticesAlgorithm::meshElement(
int index )
const
203void QgsExportMeshOnElement::initAlgorithm(
const QVariantMap &configuration )
205 Q_UNUSED( configuration );
211 QStringLiteral(
"DATASET_GROUPS" ),
212 QObject::tr(
"Dataset groups" ),
213 QStringLiteral(
"INPUT" ),
214 supportedDataType(),
true
218 QStringLiteral(
"DATASET_TIME" ),
219 QObject::tr(
"Dataset time" ),
220 QStringLiteral(
"INPUT" ),
221 QStringLiteral(
"DATASET_GROUPS" )
224 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
226 QStringList exportVectorOptions;
227 exportVectorOptions << QObject::tr(
"Cartesian (x,y)" )
228 << QObject::tr(
"Polar (magnitude,degree)" )
229 << QObject::tr(
"Cartesian and Polar" );
230 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"VECTOR_OPTION" ), QObject::tr(
"Export vector option" ), exportVectorOptions,
false, 0 ) );
240 if ( timeType == QLatin1String(
"dataset-time-step" ) )
245 else if ( timeType == QLatin1String(
"defined-date-time" ) )
248 if ( dateTime.isValid() )
249 relativeTime =
QgsInterval( layerReferenceTime.secsTo( dateTime ) );
251 else if ( timeType == QLatin1String(
"current-context-time" ) )
254 if ( dateTime.isValid() )
255 relativeTime =
QgsInterval( layerReferenceTime.secsTo( dateTime ) );
264 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
266 if ( !meshLayer || !meshLayer->
isValid() )
289 QVariant parameterTimeVariant = parameters.value( QStringLiteral(
"DATASET_TIME" ) );
290 QgsInterval relativeTime = datasetRelativetime( parameterTimeVariant, meshLayer, context );
292 switch ( meshElementType() )
295 mElementCount = mNativeMesh.faceCount();
298 mElementCount = mNativeMesh.vertexCount();
301 mElementCount = mNativeMesh.edgeCount();
305 for (
int i = 0; i < datasetGroups.count(); ++i )
307 int groupIndex = datasetGroups.at( i );
312 if ( supportedDataType().contains( dataGroup.metadata.dataType() ) )
314 dataGroup.datasetValues = meshLayer->
datasetValues( datasetIndex, 0, mElementCount );
315 mDataPerGroup.append( dataGroup );
318 feedback->
setProgress( 100 * i / datasetGroups.count() );
321 mExportVectorOption = parameterAsInt( parameters, QStringLiteral(
"VECTOR_OPTION" ), context );
331 return QVariantMap();
333 feedback->
setProgressText( QObject::tr(
"Creating output vector layer" ) );
336 QList<QgsMeshDatasetGroupMetadata> metaList;
337 metaList.reserve( mDataPerGroup.size() );
338 for (
const DataGroup &dataGroup : std::as_const( mDataPerGroup ) )
339 metaList.append( dataGroup.metadata );
340 QgsFields fields = createFields( metaList, mExportVectorOption );
344 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, identifier, fields, sinkGeometryType(),
outputCrs ) );
346 return QVariantMap();
351 return QVariantMap();
353 feedback->
setProgressText( QObject::tr(
"Creating points for each vertices" ) );
356 for (
int i = 0; i < mElementCount; ++i )
359 for (
const DataGroup &dataGroup : std::as_const( mDataPerGroup ) )
362 addAttributes( value, attributes, dataGroup.metadata.isVector(), mExportVectorOption );
373 geom = meshElement( i );
375 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
386 return QVariantMap();
394 ret[QStringLiteral(
"OUTPUT" )] = identifier;
399QString QgsExportMeshFacesAlgorithm::shortHelpString()
const
401 return QObject::tr(
"This algorithm exports a mesh layer's faces to a polygon vector layer, with the dataset values on faces as attribute values." );
404QString QgsExportMeshFacesAlgorithm::shortDescription()
const
406 return QObject::tr(
"Exports mesh faces to a polygon vector layer" );
409QString QgsExportMeshFacesAlgorithm::name()
const
411 return QStringLiteral(
"exportmeshfaces" );
414QString QgsExportMeshFacesAlgorithm::displayName()
const
416 return QObject::tr(
"Export mesh faces" );
421 return new QgsExportMeshFacesAlgorithm();
424QgsGeometry QgsExportMeshFacesAlgorithm::meshElement(
int index )
const
426 const QgsMeshFace &face = mNativeMesh.face( index );
427 QVector<QgsPoint> vertices( face.size() );
428 for (
int i = 0; i < face.size(); ++i )
429 vertices[i] = mNativeMesh.vertex( face.at( i ) );
430 std::unique_ptr<QgsPolygon> polygon = std::make_unique<QgsPolygon>();
435QString QgsExportMeshEdgesAlgorithm::shortHelpString()
const
437 return QObject::tr(
"This algorithm exports a mesh layer's edges to a line vector layer, with the dataset values on edges as attribute values." );
440QString QgsExportMeshEdgesAlgorithm::shortDescription()
const
442 return QObject::tr(
"Exports mesh edges to a line vector layer" );
445QString QgsExportMeshEdgesAlgorithm::name()
const
447 return QStringLiteral(
"exportmeshedges" );
450QString QgsExportMeshEdgesAlgorithm::displayName()
const
452 return QObject::tr(
"Export mesh edges" );
457 return new QgsExportMeshEdgesAlgorithm();
460QgsGeometry QgsExportMeshEdgesAlgorithm::meshElement(
int index )
const
462 const QgsMeshEdge &edge = mNativeMesh.edge( index );
463 QVector<QgsPoint> vertices( 2 );
464 vertices[0] = mNativeMesh.vertex( edge.first );
465 vertices[1] = mNativeMesh.vertex( edge.second );
470QString QgsExportMeshOnGridAlgorithm::name()
const {
return QStringLiteral(
"exportmeshongrid" ); }
472QString QgsExportMeshOnGridAlgorithm::displayName()
const {
return QObject::tr(
"Export mesh on grid" ); }
474QString QgsExportMeshOnGridAlgorithm::group()
const {
return QObject::tr(
"Mesh" ); }
476QString QgsExportMeshOnGridAlgorithm::groupId()
const {
return QStringLiteral(
"mesh" ); }
478QString QgsExportMeshOnGridAlgorithm::shortHelpString()
const
480 return QObject::tr(
"This algorithm exports a mesh layer's dataset values to a gridded point vector layer, with the dataset values on each point as attribute values.\n"
481 "For data on volume (3D stacked dataset values), the exported dataset values are averaged on faces using the method defined in the mesh layer properties (default is Multi level averaging method).\n"
482 "1D meshes are not supported." );
485QString QgsExportMeshOnGridAlgorithm::shortDescription()
const
487 return QObject::tr(
"Exports mesh dataset values to a gridded point vector layer" );
492 return new QgsExportMeshOnGridAlgorithm();
495void QgsExportMeshOnGridAlgorithm::initAlgorithm(
const QVariantMap &configuration )
497 Q_UNUSED( configuration );
502 QStringLiteral(
"DATASET_GROUPS" ),
503 QObject::tr(
"Dataset groups" ),
504 QStringLiteral(
"INPUT" ),
509 QStringLiteral(
"DATASET_TIME" ),
510 QObject::tr(
"Dataset time" ),
511 QStringLiteral(
"INPUT" ),
512 QStringLiteral(
"DATASET_GROUPS" )
517 addParameter(
new QgsProcessingParameterDistance( QStringLiteral(
"GRID_SPACING" ), QObject::tr(
"Grid spacing" ), 10, QStringLiteral(
"INPUT" ),
false ) );
519 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
521 QStringList exportVectorOptions;
522 exportVectorOptions << QObject::tr(
"Cartesian (x,y)" )
523 << QObject::tr(
"Polar (magnitude,degree)" )
524 << QObject::tr(
"Cartesian and Polar" );
525 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"VECTOR_OPTION" ), QObject::tr(
"Export vector option" ), exportVectorOptions,
false, 0 ) );
529static void extractDatasetValues(
const QList<int> &datasetGroups,
QgsMeshLayer *meshLayer,
const QgsMesh &nativeMesh,
const QgsInterval &relativeTime,
const QSet<int> supportedDataType, QList<DataGroup> &datasetPerGroup,
QgsProcessingFeedback *feedback )
531 for (
int i = 0; i < datasetGroups.count(); ++i )
533 int groupIndex = datasetGroups.at( i );
538 if ( supportedDataType.contains( dataGroup.metadata.dataType() ) )
541 dataGroup.datasetValues = meshLayer->
datasetValues( datasetIndex, 0, valueCount );
545 dataGroup.dataset3dStakedValue = meshLayer->
dataset3dValues( datasetIndex, 0, valueCount );
547 datasetPerGroup.append( dataGroup );
550 feedback->
setProgress( 100 * i / datasetGroups.count() );
556 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
558 if ( !meshLayer || !meshLayer->
isValid() )
578 QVariant parameterTimeVariant = parameters.value( QStringLiteral(
"DATASET_TIME" ) );
579 QgsInterval relativeTime = datasetRelativetime( parameterTimeVariant, meshLayer, context );
581 extractDatasetValues( datasetGroups, meshLayer, nativeMesh, relativeTime, supportedDataType(), mDataPerGroup, feedback );
582 mTriangularMesh.update( meshLayer->
nativeMesh(), mTransform );
584 mExportVectorOption = parameterAsInt( parameters, QStringLiteral(
"VECTOR_OPTION" ), context );
594 return QVariantMap();
596 feedback->
setProgressText( QObject::tr(
"Creating output vector layer" ) );
601 for ( DataGroup &dataGroup : mDataPerGroup )
603 if ( dataGroup.dataset3dStakedValue.isValid() )
604 dataGroup.datasetValues = avgMethod->
calculate( dataGroup.dataset3dStakedValue );
607 QList<QgsMeshDatasetGroupMetadata> metaList;
608 metaList.reserve( mDataPerGroup.size() );
609 for (
const DataGroup &dataGroup : std::as_const( mDataPerGroup ) )
610 metaList.append( dataGroup.metadata );
611 QgsFields fields = createFields( metaList, mExportVectorOption );
616 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, identifier, fields,
Qgis::WkbType::Point,
outputCrs ) );
618 return QVariantMap();
623 return QVariantMap();
629 const double gridSpacing = parameterAsDouble( parameters, QStringLiteral(
"GRID_SPACING" ), context );
635 QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context );
637 extent = mTriangularMesh.extent();
638 int pointXCount = int( extent.
width() / gridSpacing ) + 1;
639 int pointYCount = int( extent.
height() / gridSpacing ) + 1;
641 for (
int ix = 0; ix < pointXCount; ++ix )
643 for (
int iy = 0; iy < pointYCount; ++iy )
646 int triangularFaceIndex = mTriangularMesh.faceIndexForPoint_v2( point );
647 if ( triangularFaceIndex >= 0 )
651 int nativeFaceIndex = mTriangularMesh.trianglesToNativeFaces().at( triangularFaceIndex );
652 for (
int i = 0; i < mDataPerGroup.count(); ++i )
654 const DataGroup &dataGroup = mDataPerGroup.at( i );
655 bool faceActive = dataGroup.activeFaces.active( nativeFaceIndex );
663 dataGroup.activeFaces,
664 dataGroup.datasetValues,
668 if ( dataGroup.metadata.isVector() )
670 QVector<double> vector = vectorValue( dataGroup.datasetValues.value( i ), mExportVectorOption );
671 for (
double v : vector )
673 attributes.append( v );
677 attributes.append( value.
scalar() );
688 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
693 sink->addFeature( feat );
701 ret[QStringLiteral(
"OUTPUT" )] = identifier;
706QSet<int> QgsExportMeshOnGridAlgorithm::supportedDataType()
715QString QgsMeshRasterizeAlgorithm::name()
const
717 return QStringLiteral(
"meshrasterize" );
720QString QgsMeshRasterizeAlgorithm::displayName()
const
722 return QObject::tr(
"Rasterize mesh dataset" );
725QString QgsMeshRasterizeAlgorithm::group()
const
727 return QObject::tr(
"Mesh" );
730QString QgsMeshRasterizeAlgorithm::groupId()
const
732 return QStringLiteral(
"mesh" );
735QString QgsMeshRasterizeAlgorithm::shortHelpString()
const
737 return QObject::tr(
"This algorithm creates a raster layer from a mesh dataset.\n"
738 "For data on volume (3D stacked dataset values), the exported dataset values are averaged on faces using the method defined in the mesh layer properties (default is Multi level averaging method).\n"
739 "1D meshes are not supported." );
742QString QgsMeshRasterizeAlgorithm::shortDescription()
const
744 return QObject::tr(
"Creates a raster layer from a mesh dataset" );
749 return new QgsMeshRasterizeAlgorithm();
752void QgsMeshRasterizeAlgorithm::initAlgorithm(
const QVariantMap &configuration )
754 Q_UNUSED( configuration );
759 QStringLiteral(
"DATASET_GROUPS" ),
760 QObject::tr(
"Dataset groups" ),
761 QStringLiteral(
"INPUT" ),
767 QStringLiteral(
"DATASET_TIME" ),
768 QObject::tr(
"Dataset time" ),
769 QStringLiteral(
"INPUT" ),
770 QStringLiteral(
"DATASET_GROUPS" )
774 addParameter(
new QgsProcessingParameterDistance( QStringLiteral(
"PIXEL_SIZE" ), QObject::tr(
"Pixel size" ), 1, QStringLiteral(
"INPUT" ),
false ) );
775 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
777 std::unique_ptr<QgsProcessingParameterString> createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
778 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
780 addParameter( createOptsParam.release() );
787 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
789 if ( !meshLayer || !meshLayer->
isValid() )
799 mTriangularMesh.update( meshLayer->
nativeMesh(), mTransform );
809 QVariant parameterTimeVariant = parameters.value( QStringLiteral(
"DATASET_TIME" ) );
810 QgsInterval relativeTime = datasetRelativetime( parameterTimeVariant, meshLayer, context );
812 extractDatasetValues( datasetGroups, meshLayer, *meshLayer->
nativeMesh(), relativeTime, supportedDataType(), mDataPerGroup, feedback );
824 return QVariantMap();
831 for ( DataGroup &dataGroup : mDataPerGroup )
833 if ( dataGroup.dataset3dStakedValue.isValid() )
834 dataGroup.datasetValues = avgMethod->
calculate( dataGroup.dataset3dStakedValue );
838 const double pixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
844 QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context );
846 extent = mTriangularMesh.extent();
848 int width = extent.
width() / pixelSize;
849 int height = extent.
height() / pixelSize;
851 const QString createOptions = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context ).trimmed();
852 const QString fileName = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
853 const QFileInfo fileInfo( fileName );
856 rasterFileWriter.setOutputProviderKey( QStringLiteral(
"gdal" ) );
857 if ( !createOptions.isEmpty() )
859 rasterFileWriter.setCreateOptions( createOptions.split(
'|' ) );
861 rasterFileWriter.setOutputFormat( outputFormat );
863 std::unique_ptr<QgsRasterDataProvider> rasterDataProvider(
864 rasterFileWriter.createMultiBandRaster(
Qgis::DataType::Float64, width, height, extent, mTransform.destinationCrs(), mDataPerGroup.count() )
866 rasterDataProvider->setEditable(
true );
868 for (
int i = 0; i < mDataPerGroup.count(); ++i )
870 const DataGroup &dataGroup = mDataPerGroup.at( i );
875 if ( dataGroup.datasetValues.isValid() )
879 dataGroup.datasetValues,
880 dataGroup.activeFaces,
881 dataGroup.metadata.dataType(),
888 rasterDataProvider->writeBlock( block.get(), i + 1 );
889 rasterDataProvider->setNoDataValue( i + 1, block->noDataValue() );
892 rasterDataProvider->setNoDataValue( i + 1, std::numeric_limits<double>::quiet_NaN() );
897 return QVariantMap();
898 feedback->
setProgress( 100 * i / mDataPerGroup.count() );
902 rasterDataProvider->setEditable(
false );
908 ret[QStringLiteral(
"OUTPUT" )] = fileName;
913QSet<int> QgsMeshRasterizeAlgorithm::supportedDataType()
922QString QgsMeshContoursAlgorithm::name()
const
924 return QStringLiteral(
"meshcontours" );
927QString QgsMeshContoursAlgorithm::displayName()
const
929 return QObject::tr(
"Export contours" );
932QString QgsMeshContoursAlgorithm::group()
const
934 return QObject::tr(
"Mesh" );
937QString QgsMeshContoursAlgorithm::groupId()
const
939 return QStringLiteral(
"mesh" );
942QString QgsMeshContoursAlgorithm::shortHelpString()
const
944 return QObject::tr(
"This algorithm creates contours as a vector layer from a mesh scalar dataset." );
947QString QgsMeshContoursAlgorithm::shortDescription()
const
949 return QObject::tr(
"Creates contours as vector layer from mesh scalar dataset" );
954 return new QgsMeshContoursAlgorithm();
957void QgsMeshContoursAlgorithm::initAlgorithm(
const QVariantMap &configuration )
959 Q_UNUSED( configuration );
964 QStringLiteral(
"DATASET_GROUPS" ),
965 QObject::tr(
"Dataset groups" ),
966 QStringLiteral(
"INPUT" ),
971 QStringLiteral(
"DATASET_TIME" ),
972 QObject::tr(
"Dataset time" ),
973 QStringLiteral(
"INPUT" ),
974 QStringLiteral(
"DATASET_GROUPS" )
988 std::unique_ptr<QgsProcessingParameterString> contourLevelList = std::make_unique<QgsProcessingParameterString>(
989 QStringLiteral(
"CONTOUR_LEVEL_LIST" ), QObject::tr(
"List of contours level" ), QVariant(),
false,
true
991 contourLevelList->setHelp( QObject::tr(
"Comma separated list of values to export. If filled, the increment, minimum and maximum settings are ignored." ) );
992 addParameter( contourLevelList.release() );
994 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
1003 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
1005 if ( !meshLayer || !meshLayer->
isValid() )
1015 mTriangularMesh.update( meshLayer->
nativeMesh(), mTransform );
1021 QString levelsString = parameterAsString( parameters, QStringLiteral(
"CONTOUR_LEVEL_LIST" ), context );
1022 if ( !levelsString.isEmpty() )
1024 QStringList levelStringList = levelsString.split(
',' );
1025 if ( !levelStringList.isEmpty() )
1027 for (
const QString &stringVal : levelStringList )
1030 double val = stringVal.toDouble( &ok );
1032 mLevels.append( val );
1034 throw QgsProcessingException( QObject::tr(
"Invalid format for level values, must be numbers separated with comma" ) );
1036 if ( mLevels.count() >= 2 )
1037 if ( mLevels.last() <= mLevels.at( mLevels.count() - 2 ) )
1038 throw QgsProcessingException( QObject::tr(
"Invalid format for level values, must be different numbers and in increasing order" ) );
1043 if ( mLevels.isEmpty() )
1045 double minimum = parameterAsDouble( parameters, QStringLiteral(
"MINIMUM" ), context );
1046 double maximum = parameterAsDouble( parameters, QStringLiteral(
"MAXIMUM" ), context );
1047 double interval = parameterAsDouble( parameters, QStringLiteral(
"INCREMENT" ), context );
1049 if ( interval <= 0 )
1052 if ( minimum >= maximum )
1053 throw QgsProcessingException( QObject::tr(
"Invalid minimum and maximum values, minimum must be lesser than maximum" ) );
1055 if ( interval > ( maximum - minimum ) )
1056 throw QgsProcessingException( QObject::tr(
"Invalid minimum, maximum and interval values, difference between minimum and maximum must be greater or equal than interval" ) );
1058 int intervalCount = ( maximum - minimum ) / interval;
1060 mLevels.reserve( intervalCount );
1061 for (
int i = 0; i < intervalCount; ++i )
1063 mLevels.append( minimum + i * interval );
1076 QVariant parameterTimeVariant = parameters.value( QStringLiteral(
"DATASET_TIME" ) );
1077 QgsInterval relativeTime = datasetRelativetime( parameterTimeVariant, meshLayer, context );
1081 extractDatasetValues( datasetGroups, meshLayer, mNativeMesh, relativeTime, supportedDataType(), mDataPerGroup, feedback );
1092 for ( DataGroup &dataGroup : mDataPerGroup )
1094 if ( dataGroup.dataset3dStakedValue.isValid() )
1095 dataGroup.datasetValues = avgMethod->
calculate( dataGroup.dataset3dStakedValue );
1101 polygonFields.
append(
QgsField( QObject::tr(
"group" ), QMetaType::Type::QString ) );
1102 polygonFields.
append(
QgsField( QObject::tr(
"time" ), QMetaType::Type::QString ) );
1103 polygonFields.
append(
QgsField( QObject::tr(
"min_value" ), QMetaType::Type::Double ) );
1104 polygonFields.
append(
QgsField( QObject::tr(
"max_value" ), QMetaType::Type::Double ) );
1105 lineFields.
append(
QgsField( QObject::tr(
"group" ), QMetaType::Type::QString ) );
1106 lineFields.
append(
QgsField( QObject::tr(
"time" ), QMetaType::Type::QString ) );
1107 lineFields.
append(
QgsField( QObject::tr(
"value" ), QMetaType::Type::Double ) );
1111 QString lineIdentifier;
1112 QString polygonIdentifier;
1113 std::unique_ptr<QgsFeatureSink> sinkPolygons( parameterAsSink(
1115 QStringLiteral(
"OUTPUT_POLYGONS" ),
1122 std::unique_ptr<QgsFeatureSink> sinkLines( parameterAsSink(
1124 QStringLiteral(
"OUTPUT_LINES" ),
1132 if ( !sinkLines || !sinkPolygons )
1133 return QVariantMap();
1136 for (
int i = 0; i < mDataPerGroup.count(); ++i )
1138 DataGroup dataGroup = mDataPerGroup.at( i );
1140 int count = scalarDataOnVertices ? mNativeMesh.vertices.count() : mNativeMesh.faces.count();
1142 QVector<double> values;
1143 if ( dataGroup.datasetValues.isValid() )
1146 values = QgsMeshLayerUtils::calculateMagnitudes( dataGroup.datasetValues );
1150 values = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
1153 if ( ( !scalarDataOnVertices ) )
1155 values = QgsMeshLayerUtils::interpolateFromFacesData(
1158 &dataGroup.activeFaces,
1163 QgsMeshContours contoursExported( mTriangularMesh, mNativeMesh, values, dataGroup.activeFaces );
1166 firstAttributes.append( dataGroup.metadata.name() );
1167 firstAttributes.append( mDateTimeString );
1169 for (
double level : std::as_const( mLevels ) )
1171 QgsGeometry line = contoursExported.exportLines( level, feedback );
1173 return QVariantMap();
1177 lineAttributes.append( level );
1184 throw QgsProcessingException( writeFeatureError( sinkLines.get(), parameters, QStringLiteral(
"OUTPUT_LINES" ) ) );
1187 for (
int l = 0; l < mLevels.count() - 1; ++l )
1189 QgsGeometry polygon = contoursExported.exportPolygons( mLevels.at( l ), mLevels.at( l + 1 ), feedback );
1191 return QVariantMap();
1196 polygonAttributes.append( mLevels.at( l ) );
1197 polygonAttributes.append( mLevels.at( l + 1 ) );
1202 sinkPolygons->addFeature( polygonFeature );
1207 feedback->
setProgress( 100 * i / mDataPerGroup.count() );
1212 sinkPolygons->finalize();
1214 sinkLines->finalize();
1217 ret[QStringLiteral(
"OUTPUT_LINES" )] = lineIdentifier;
1218 ret[QStringLiteral(
"OUTPUT_POLYGONS" )] = polygonIdentifier;
1223QString QgsMeshExportCrossSection::name()
const
1225 return QStringLiteral(
"meshexportcrosssection" );
1228QString QgsMeshExportCrossSection::displayName()
const
1230 return QObject::tr(
"Export cross section dataset values on lines from mesh" );
1233QString QgsMeshExportCrossSection::group()
const
1235 return QObject::tr(
"Mesh" );
1238QString QgsMeshExportCrossSection::groupId()
const
1240 return QStringLiteral(
"mesh" );
1243QString QgsMeshExportCrossSection::shortHelpString()
const
1245 return QObject::tr(
"This algorithm extracts mesh's dataset values from line contained in a vector layer.\n"
1246 "Each line is discretized with a resolution distance parameter for extraction of values on its vertices." );
1249QString QgsMeshExportCrossSection::shortDescription()
const
1251 return QObject::tr(
"Extracts a mesh dataset's values from lines contained in a vector layer" );
1256 return new QgsMeshExportCrossSection();
1259void QgsMeshExportCrossSection::initAlgorithm(
const QVariantMap &configuration )
1261 Q_UNUSED( configuration );
1266 QStringLiteral(
"DATASET_GROUPS" ),
1267 QObject::tr(
"Dataset groups" ),
1268 QStringLiteral(
"INPUT" ),
1273 QStringLiteral(
"DATASET_TIME" ),
1274 QObject::tr(
"Dataset time" ),
1275 QStringLiteral(
"INPUT" ),
1276 QStringLiteral(
"DATASET_GROUPS" )
1279 QList<int> datatype;
1282 QStringLiteral(
"INPUT_LINES" ), QObject::tr(
"Lines for data export" ), datatype, QVariant(),
false
1286 QStringLiteral(
"RESOLUTION" ), QObject::tr(
"Line segmentation resolution" ), 10.0, QStringLiteral(
"INPUT_LINES" ),
false, 0
1298 QStringLiteral(
"OUTPUT" ), QObject::tr(
"Exported data CSV file" ), QObject::tr(
"CSV file (*.csv)" )
1304 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
1306 if ( !meshLayer || !meshLayer->
isValid() )
1309 mMeshLayerCrs = meshLayer->
crs();
1310 mTriangularMesh.update( meshLayer->
nativeMesh() );
1319 QVariant parameterTimeVariant = parameters.value( QStringLiteral(
"DATASET_TIME" ) );
1320 QgsInterval relativeTime = datasetRelativetime( parameterTimeVariant, meshLayer, context );
1322 extractDatasetValues( datasetGroups, meshLayer, *meshLayer->
nativeMesh(), relativeTime, supportedDataType(), mDataPerGroup, feedback );
1335 for ( DataGroup &dataGroup : mDataPerGroup )
1337 if ( dataGroup.dataset3dStakedValue.isValid() )
1338 dataGroup.datasetValues = avgMethod->
calculate( dataGroup.dataset3dStakedValue );
1340 double resolution = parameterAsDouble( parameters, QStringLiteral(
"RESOLUTION" ), context );
1341 int datasetDigits = parameterAsInt( parameters, QStringLiteral(
"DATASET_DIGITS" ), context );
1342 int coordDigits = parameterAsInt( parameters, QStringLiteral(
"COORDINATES_DIGITS" ), context );
1344 std::unique_ptr<QgsProcessingFeatureSource> featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT_LINES" ), context ) );
1345 if ( !featureSource )
1350 QString outputFileName = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
1351 QFile file( outputFileName );
1352 if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1355 QTextStream textStream( &file );
1356#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
1357 textStream.setCodec(
"UTF-8" );
1360 header << QStringLiteral(
"fid" ) << QStringLiteral(
"x" ) << QStringLiteral(
"y" ) << QObject::tr(
"offset" );
1361 for (
const DataGroup &datagroup : std::as_const( mDataPerGroup ) )
1362 header << datagroup.metadata.name();
1363 textStream << header.join(
',' ) << QStringLiteral(
"\n" );
1365 long long featCount = featureSource->featureCount();
1366 long long featCounter = 0;
1380 feedback->
reportError( QObject::tr(
"Could not transform line to mesh CRS" ) );
1386 while ( offset <= line.
length() )
1389 return QVariantMap();
1391 QStringList textLine;
1393 int triangularFaceIndex = mTriangularMesh.faceIndexForPoint_v2( point );
1394 textLine << QString::number( fid ) << QString::number( point.
x(),
'f', coordDigits ) << QString::number( point.
y(),
'f', coordDigits ) << QString::number( offset,
'f', coordDigits );
1395 if ( triangularFaceIndex >= 0 )
1399 int nativeFaceIndex = mTriangularMesh.trianglesToNativeFaces().at( triangularFaceIndex );
1400 for (
int i = 0; i < mDataPerGroup.count(); ++i )
1402 const DataGroup &dataGroup = mDataPerGroup.at( i );
1403 bool faceActive = dataGroup.activeFaces.active( nativeFaceIndex );
1409 triangularFaceIndex,
1411 dataGroup.activeFaces,
1412 dataGroup.datasetValues,
1416 if ( abs( value.
x() ) == std::numeric_limits<double>::quiet_NaN() )
1417 textLine << QString(
' ' );
1419 textLine << QString::number( value.
scalar(),
'f', datasetDigits );
1423 for (
int i = 0; i < mDataPerGroup.count(); ++i )
1424 textLine << QString(
' ' );
1426 textStream << textLine.join(
',' ) << QStringLiteral(
"\n" );
1428 offset += resolution;
1433 feedback->
setProgress( 100.0 * featCounter / featCount );
1435 return QVariantMap();
1442 ret[QStringLiteral(
"OUTPUT" )] = outputFileName;
1446QString QgsMeshExportTimeSeries::name()
const
1448 return QStringLiteral(
"meshexporttimeseries" );
1451QString QgsMeshExportTimeSeries::displayName()
const
1453 return QObject::tr(
"Export time series values from points of a mesh dataset" );
1456QString QgsMeshExportTimeSeries::group()
const
1458 return QObject::tr(
"Mesh" );
1461QString QgsMeshExportTimeSeries::groupId()
const
1463 return QStringLiteral(
"mesh" );
1466QString QgsMeshExportTimeSeries::shortHelpString()
const
1468 return QObject::tr(
"This algorithm extracts mesh's dataset time series values from points contained in a vector layer.\n"
1469 "If the time step is kept to its default value (0 hours), the time step used is the one of the two first datasets of the first selected dataset group." );
1472QString QgsMeshExportTimeSeries::shortDescription()
const
1474 return QObject::tr(
"Extracts a mesh dataset's time series values from points contained in a vector layer" );
1479 return new QgsMeshExportTimeSeries();
1482void QgsMeshExportTimeSeries::initAlgorithm(
const QVariantMap &configuration )
1484 Q_UNUSED( configuration );
1489 QStringLiteral(
"DATASET_GROUPS" ),
1490 QObject::tr(
"Dataset groups" ),
1491 QStringLiteral(
"INPUT" ),
1496 QStringLiteral(
"STARTING_TIME" ),
1497 QObject::tr(
"Starting time" ),
1498 QStringLiteral(
"INPUT" ),
1499 QStringLiteral(
"DATASET_GROUPS" )
1503 QStringLiteral(
"FINISHING_TIME" ),
1504 QObject::tr(
"Finishing time" ),
1505 QStringLiteral(
"INPUT" ),
1506 QStringLiteral(
"DATASET_GROUPS" )
1513 QList<int> datatype;
1516 QStringLiteral(
"INPUT_POINTS" ), QObject::tr(
"Points for data export" ), datatype, QVariant(),
false
1528 QStringLiteral(
"OUTPUT" ), QObject::tr(
"Exported data CSV file" ), QObject::tr(
"CSV file (*.csv)" )
1534 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
1536 if ( !meshLayer || !meshLayer->
isValid() )
1539 mMeshLayerCrs = meshLayer->
crs();
1540 mTriangularMesh.update( meshLayer->
nativeMesh() );
1550 QVariant parameterStartTimeVariant = parameters.value( QStringLiteral(
"STARTING_TIME" ) );
1551 QgsInterval relativeStartTime = datasetRelativetime( parameterStartTimeVariant, meshLayer, context );
1553 QVariant parameterEndTimeVariant = parameters.value( QStringLiteral(
"FINISHING_TIME" ) );
1554 QgsInterval relativeEndTime = datasetRelativetime( parameterEndTimeVariant, meshLayer, context );
1557 qint64 timeStepInterval = parameterAsDouble( parameters, QStringLiteral(
"TIME_STEP" ), context ) * 1000 * 3600;
1558 if ( timeStepInterval == 0 )
1561 for (
int groupIndex : datasetGroups )
1575 mRelativeTimeSteps.clear();
1576 mTimeStepString.clear();
1577 if ( timeStepInterval != 0 )
1579 mRelativeTimeSteps.append( relativeStartTime.
seconds() * 1000 );
1580 while ( mRelativeTimeSteps.last() < relativeEndTime.
seconds() * 1000 )
1581 mRelativeTimeSteps.append( mRelativeTimeSteps.last() + timeStepInterval );
1583 for ( qint64 relativeTimeStep : std::as_const( mRelativeTimeSteps ) )
1585 mTimeStepString.append( meshLayer->
formatTime( relativeTimeStep / 3600.0 / 1000.0 ) );
1590 for (
int i = 0; i < datasetGroups.count(); ++i )
1592 int groupIndex = datasetGroups.at( i );
1594 if ( supportedDataType().contains( meta.
dataType() ) )
1596 mGroupIndexes.append( groupIndex );
1597 mGroupsMetadata[groupIndex] = meta;
1600 if ( !mRelativeTimeSteps.isEmpty() )
1604 for ( qint64 relativeTimeStep : std::as_const( mRelativeTimeSteps ) )
1606 QMap<int, int> &groupIndexToData = mRelativeTimeToData[relativeTimeStep];
1607 QgsInterval timeStepInterval( relativeTimeStep / 1000.0 );
1609 if ( !datasetIndex.
isValid() )
1611 if ( datasetIndex != lastDatasetIndex )
1613 DataGroup dataGroup;
1614 dataGroup.metadata = meta;
1615 dataGroup.datasetValues = meshLayer->
datasetValues( datasetIndex, 0, valueCount );
1619 dataGroup.dataset3dStakedValue = meshLayer->
dataset3dValues( datasetIndex, 0, valueCount );
1621 mDatasets.append( dataGroup );
1622 lastDatasetIndex = datasetIndex;
1624 groupIndexToData[groupIndex] = mDatasets.count() - 1;
1630 QMap<int, int> &groupIndexToData = mRelativeTimeToData[0];
1632 DataGroup dataGroup;
1633 dataGroup.metadata = meta;
1634 dataGroup.datasetValues = meshLayer->
datasetValues( datasetIndex, 0, valueCount );
1638 dataGroup.dataset3dStakedValue = meshLayer->
dataset3dValues( datasetIndex, 0, valueCount );
1640 mDatasets.append( dataGroup );
1641 groupIndexToData[groupIndex] = mDatasets.
count() - 1;
1646 feedback->
setProgress( 100 * i / datasetGroups.count() );
1662 for ( DataGroup &dataGroup : mDatasets )
1664 if ( dataGroup.dataset3dStakedValue.isValid() )
1665 dataGroup.datasetValues = avgMethod->
calculate( dataGroup.dataset3dStakedValue );
1668 int datasetDigits = parameterAsInt( parameters, QStringLiteral(
"DATASET_DIGITS" ), context );
1669 int coordDigits = parameterAsInt( parameters, QStringLiteral(
"COORDINATES_DIGITS" ), context );
1671 std::unique_ptr<QgsProcessingFeatureSource> featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT_POINTS" ), context ) );
1672 if ( !featureSource )
1677 QString outputFileName = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
1678 QFile file( outputFileName );
1679 if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1682 QTextStream textStream( &file );
1683#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
1684 textStream.setCodec(
"UTF-8" );
1687 header << QStringLiteral(
"fid" ) << QStringLiteral(
"x" ) << QStringLiteral(
"y" ) << QObject::tr(
"time" );
1689 for (
int gi : std::as_const( mGroupIndexes ) )
1690 header << mGroupsMetadata.value( gi ).name();
1692 textStream << header.join(
',' ) << QStringLiteral(
"\n" );
1694 long long featCount = featureSource->featureCount();
1695 long long featCounter = 0;
1709 feedback->
reportError( QObject::tr(
"Could not transform line to mesh CRS" ) );
1716 int triangularFaceIndex = mTriangularMesh.faceIndexForPoint_v2( point );
1718 if ( triangularFaceIndex >= 0 )
1720 int nativeFaceIndex = mTriangularMesh.trianglesToNativeFaces().at( triangularFaceIndex );
1721 if ( !mRelativeTimeSteps.isEmpty() )
1723 for (
int timeIndex = 0; timeIndex < mRelativeTimeSteps.count(); ++timeIndex )
1725 qint64 timeStep = mRelativeTimeSteps.at( timeIndex );
1726 QStringList textLine;
1727 textLine << QString::number( fid )
1728 << QString::number( point.
x(),
'f', coordDigits )
1729 << QString::number( point.
y(),
'f', coordDigits )
1730 << mTimeStepString.at( timeIndex );
1732 if ( mRelativeTimeToData.contains( timeStep ) )
1734 const QMap<int, int> &groupToData = mRelativeTimeToData.value( timeStep );
1735 for (
int groupIndex : std::as_const( mGroupIndexes ) )
1737 if ( !groupToData.contains( groupIndex ) )
1739 int dataIndex = groupToData.value( groupIndex );
1740 if ( dataIndex < 0 || dataIndex > mDatasets.count() - 1 )
1743 const DataGroup &dataGroup = mDatasets.at( dataIndex );
1744 QgsMeshDatasetValue value = extractDatasetValue( point, nativeFaceIndex, triangularFaceIndex, mTriangularMesh, dataGroup.activeFaces, dataGroup.datasetValues, dataGroup.metadata );
1745 if ( abs( value.
x() ) == std::numeric_limits<double>::quiet_NaN() )
1746 textLine << QString(
' ' );
1748 textLine << QString::number( value.
scalar(),
'f', datasetDigits );
1751 textStream << textLine.join(
',' ) << QStringLiteral(
"\n" );
1756 QStringList textLine;
1757 textLine << QString::number( fid )
1758 << QString::number( point.
x(),
'f', coordDigits )
1759 << QString::number( point.
y(),
'f', coordDigits )
1760 << QObject::tr(
"static dataset" );
1761 const QMap<int, int> &groupToData = mRelativeTimeToData.value( 0 );
1762 for (
int groupIndex : std::as_const( mGroupIndexes ) )
1764 if ( !groupToData.contains( groupIndex ) )
1766 int dataIndex = groupToData.value( groupIndex );
1767 if ( dataIndex < 0 || dataIndex > mDatasets.count() - 1 )
1769 const DataGroup &dataGroup = mDatasets.at( dataIndex );
1770 QgsMeshDatasetValue value = extractDatasetValue( point, nativeFaceIndex, triangularFaceIndex, mTriangularMesh, dataGroup.activeFaces, dataGroup.datasetValues, dataGroup.metadata );
1771 if ( abs( value.
x() ) == std::numeric_limits<double>::quiet_NaN() )
1772 textLine << QString(
' ' );
1774 textLine << QString::number( value.
scalar(),
'f', datasetDigits );
1776 textStream << textLine.join(
',' ) << QStringLiteral(
"\n" );
1782 feedback->
setProgress( 100.0 * featCounter / featCount );
1784 return QVariantMap();
1791 ret[QStringLiteral(
"OUTPUT" )] = outputFileName;
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ Float64
Sixty four bit floating point (double)
@ LineStringZ
LineStringZ.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Custom exception class for Coordinate Reference System related exceptions.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void canceled()
Internal routines can connect to this signal if they use event loop.
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
void setProgress(double progress)
Sets the current progress for the feedback object.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
double length() const
Returns the planar, 2-dimensional length of geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
A representation of the interval between two datetime values.
double seconds() const
Returns the interval duration in seconds.
double hours() const
Returns the interval duration in hours.
Line string geometry type, with support for z-dimension and m-values.
QgsCoordinateReferenceSystem crs
Abstract class to interpolate 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.
int count() const
Number of 2d faces for which the volume data is stored in the block.
Exporter of contours lines or polygons from a mesh layer.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
bool active(int index) const
Returns a value for active flag by the index For scalar and vector 2d the behavior is undefined.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
QgsMeshDatasetValue represents single dataset value.
double y() const
Returns y value.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
double x() const
Returns x value.
Implementation of map layer temporal properties for mesh layers.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
int datasetCount(const QgsMeshDatasetIndex &index) const
Returns the dataset count in the dataset groups.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh)
QgsMeshDatasetIndex datasetIndexAtRelativeTime(const QgsInterval &relativeTime, int datasetGroupIndex) const
Returns dataset index from datasets group depending on the relative time from the layer reference tim...
QgsMeshDataBlock datasetValues(const QgsMeshDatasetIndex &index, int valueIndex, int count) const
Returns N vector/scalar values from the index from the dataset.
bool isEditable() const override
Returns true if the layer can be edited.
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether the faces are active for particular dataset.
QgsInterval datasetRelativeTime(const QgsMeshDatasetIndex &index)
Returns the relative time of the dataset from the reference time of its group.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
qint64 datasetRelativeTimeInMilliseconds(const QgsMeshDatasetIndex &index)
Returns the relative time (in milliseconds) of the dataset from the reference time of its group.
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.
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.
@ NeighbourAverage
Does a simple average of values defined for all surrounding faces/vertices.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
QgsDateTimeRange currentTimeRange() const
Returns the current time range to use for temporal operations.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
A coordinate reference system parameter for processing algorithms.
A double numeric parameter for distance values.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A rectangular map extent parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
A parameter for processing algorithms that need a list of mesh dataset groups.
static QList< int > valueAsDatasetGroup(const QVariant &value)
Returns the value as a list if dataset group indexes.
A parameter for processing algorithms that need a list of mesh dataset index from time parameter.
static QString valueAsTimeType(const QVariant &value)
Returns the dataset value time type as a string : current-context-time : the time is store in the pro...
static QgsMeshDatasetIndex timeValueAsDatasetIndex(const QVariant &value)
Returns the value as a QgsMeshDatasetIndex if the value has "dataset-time-step" type.
static QDateTime timeValueAsDefinedDateTime(const QVariant &value)
Returns the value as a QDateTime if the value has "defined-date-time" type.
A mesh layer parameter for processing algorithms.
A numeric parameter for processing algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
Feedback object tailored for raster block reading.
The raster file writer which allows you to save a raster to a new file.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
A rectangle specified with double values.
T begin() const
Returns the beginning of the range.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
CORE_EXPORT QgsRasterBlock * exportRasterBlock(const QgsMeshLayer &layer, const QgsMeshDatasetIndex &datasetIndex, const QgsCoordinateReferenceSystem &destinationCrs, const QgsCoordinateTransformContext &transformContext, double mapUnitsPerPixel, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Exports mesh layer's dataset values as raster block.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< int > QgsMeshFace
List of vertex indexes.
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
const QgsCoordinateReferenceSystem & outputCrs
Mesh - vertices, edges and faces.
QVector< QgsMeshVertex > vertices
void clear()
Remove all vertices, edges and faces.
int faceCount() const
Returns number of faces.