Skip to content
Permalink
Browse files

Fixup zonal stats implementation

  • Loading branch information
m-kuhn committed Sep 9, 2020
1 parent 7f4e12f commit 42b4a03e27f296feae9e9000978fa166757df909
@@ -57,8 +57,6 @@ QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer *polygonLayer, QgsRasterI

QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback *feedback )
{
QgsVectorDataProvider *vectorProvider = nullptr;

if ( !mRasterInterface )
{
return RasterInvalid;
@@ -74,7 +72,7 @@ QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback
return LayerTypeWrong;
}

vectorProvider = mPolygonLayer->dataProvider();
QgsVectorDataProvider *vectorProvider = mPolygonLayer->dataProvider();
if ( !vectorProvider )
{
return LayerInvalid;
@@ -83,6 +81,7 @@ QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback
QMap<QgsZonalStatistics::Statistic, int> statFieldIndexes;

//add the new fields to the provider
int oldFieldCount = vectorProvider->fields().count();
QList<QgsField> newFieldList;
for ( QgsZonalStatistics::Statistic stat :
{
@@ -105,7 +104,7 @@ QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback
QString fieldName = getUniqueFieldName( mAttributePrefix + QgsZonalStatistics::shortName( stat ), newFieldList );
QgsField field( fieldName, QVariant::Double, QStringLiteral( "double precision" ) );
newFieldList.push_back( field );
statFieldIndexes.insert( stat, newFieldList.count() - 1 );
statFieldIndexes.insert( stat, oldFieldCount + newFieldList.count() - 1 );
}
}

@@ -288,7 +287,7 @@ QString QgsZonalStatistics::shortName( QgsZonalStatistics::Statistic statistic )
return QString();
}

QMap<QgsZonalStatistics::Statistic, QVariant> QgsZonalStatistics::calculateStatistics( QgsRasterInterface *rasterInterface, const QgsGeometry &geometry, int cellSizeX, int cellSizeY, int rasterBand, QgsZonalStatistics::Statistics statistics )
QMap<QgsZonalStatistics::Statistic, QVariant> QgsZonalStatistics::calculateStatistics( QgsRasterInterface *rasterInterface, const QgsGeometry &geometry, double cellSizeX, double cellSizeY, int rasterBand, QgsZonalStatistics::Statistics statistics )
{
QMap<QgsZonalStatistics::Statistic, QVariant> results;

@@ -155,7 +155,7 @@ class ANALYSIS_EXPORT QgsZonalStatistics
*
* \since QGIS 3.16
*/
static QMap<QgsZonalStatistics::Statistic, QVariant> calculateStatistics( QgsRasterInterface *rasterInterface, const QgsGeometry &geometry, int cellSizeX, int cellSizeY, int rasterBand, QgsZonalStatistics::Statistics statistics );
static QMap<QgsZonalStatistics::Statistic, QVariant> calculateStatistics(QgsRasterInterface *rasterInterface, const QgsGeometry &geometry, double cellSizeX, double cellSizeY, int rasterBand, QgsZonalStatistics::Statistics statistics );

private:
QgsZonalStatistics() = default;
@@ -5,6 +5,7 @@
<MDI key="STATISTICS_MEAN">865.86666666667</MDI>
<MDI key="STATISTICS_MINIMUM">826</MDI>
<MDI key="STATISTICS_STDDEV">17.808206597584</MDI>
<MDI key="STATISTICS_VALID_PERCENT">53.57</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>

0 comments on commit 42b4a03

Please sign in to comment.
You can’t perform that action at this time.