Skip to content

Commit

Permalink
Fix in place version of zonal stats
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 9, 2020
1 parent be86443 commit 7f4e12f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -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 :
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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 );
Expand Down
1 change: 0 additions & 1 deletion src/analysis/vector/qgszonalstatistics.h
Expand Up @@ -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 )
Expand Down

0 comments on commit 7f4e12f

Please sign in to comment.