Skip to content
Permalink
Browse files

Fix in place version of zonal stats

  • Loading branch information
m-kuhn committed Sep 9, 2020
1 parent be86443 commit 7f4e12f31e88342392a820fc01065c0e31f6ef44
Showing with 4 additions and 3 deletions.
  1. +4 −2 src/analysis/vector/qgszonalstatistics.cpp
  2. +0 −1 src/analysis/vector/qgszonalstatistics.h
@@ -80,6 +80,8 @@ QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback
return LayerInvalid;
}

QMap<QgsZonalStatistics::Statistic, int> statFieldIndexes;

//add the new fields to the provider
QList<QgsField> newFieldList;
for ( QgsZonalStatistics::Statistic stat :
@@ -103,7 +105,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 );
mStatFieldIndexes.insert( stat, newFieldList.count() - 1 );
statFieldIndexes.insert( stat, newFieldList.count() - 1 );
}
}

@@ -144,7 +146,7 @@ QgsZonalStatistics::Result QgsZonalStatistics::calculateStatistics( QgsFeedback
QgsAttributeMap changeAttributeMap;
for ( const auto &result : results.toStdMap() )
{
changeAttributeMap.insert( result.first, result.second );
changeAttributeMap.insert( statFieldIndexes.value( result.first ), result.second );
}

changeMap.insert( feature.id(), changeAttributeMap );
@@ -223,7 +223,6 @@ class ANALYSIS_EXPORT QgsZonalStatistics
QgsVectorLayer *mPolygonLayer = nullptr;
QString mAttributePrefix;
Statistics mStatistics = QgsZonalStatistics::All;
QMap<QgsZonalStatistics::Statistic, int> mStatFieldIndexes;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsZonalStatistics::Statistics )

0 comments on commit 7f4e12f

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