Skip to content
Permalink
Browse files

Use a QHash instead of std::unordered_map

Because it turns out MUCH MUCH faster
  • Loading branch information
nyalldawson committed Jan 22, 2019
1 parent 60a6fc1 commit ee34431214aae227515a0500b3a78a2637ee1755
@@ -6706,6 +6706,8 @@ tests:
OUTPUT_TABLE:
name: expected/raster_zonal_stats.csv
type: vector
pk:
- zone

- algorithm: native:rasterlayerzonalstats
name: Raster layer zonal stats, reprojected
@@ -6722,6 +6724,8 @@ tests:
OUTPUT_TABLE:
name: expected/raster_zonal_stats_reproj.csv
type: vector
pk:
- zone

- algorithm: native:rasterlayerzonalstats
name: Raster layer zonal stats, zones ref
@@ -6739,6 +6743,8 @@ tests:
OUTPUT_TABLE:
name: expected/raster_zonal_stats_zone_ref.csv
type: vector
pk:
- zone

- algorithm: native:rasterlayerzonalstats
name: Raster layer zonal stats reprojected, zones ref
@@ -6756,6 +6762,8 @@ tests:
OUTPUT_TABLE:
name: expected/raster_zonal_stats_zone_crs_ref.csv
type: vector
pk:
- zone

- algorithm: native:antimeridiansplit
name: Antimeridian split, lines
@@ -19,7 +19,6 @@
#include "qgsstringutils.h"
#include "qgsstatisticalsummary.h"
#include "qgsrasterprojector.h"
#include <unordered_map>

///@cond PRIVATE

@@ -196,7 +195,7 @@ QVariantMap QgsRasterLayerZonalStatsAlgorithm::processAlgorithm( const QVariantM
// up trying to store EVERY pixel value from the input in memory
QgsStatisticalSummary s{ QgsStatisticalSummary::Count | QgsStatisticalSummary::Sum | QgsStatisticalSummary::Min | QgsStatisticalSummary::Max | QgsStatisticalSummary::Mean };
};
std::unordered_map<double, StatCalculator, std::hash<double>, std::equal_to<double> > zoneStats;
QHash<double, StatCalculator > zoneStats;
qgssize noDataCount = 0;

qgssize layerSize = static_cast< qgssize >( mLayerWidth ) * static_cast< qgssize >( mLayerHeight );
@@ -280,9 +279,9 @@ QVariantMap QgsRasterLayerZonalStatsAlgorithm::processAlgorithm( const QVariantM
for ( auto it = zoneStats.begin(); it != zoneStats.end(); ++it )
{
QgsFeature f;
it->second.s.finalize();
f.setAttributes( QgsAttributes() << it->first << it->second.s.count() * pixelArea << it->second.s.sum() << it->second.s.count() <<
it->second.s.min() << it->second.s.max() << it->second.s.mean() );
it->s.finalize();
f.setAttributes( QgsAttributes() << it.key() << it->s.count() * pixelArea << it->s.sum() << it->s.count() <<
it->s.min() << it->s.max() << it->s.mean() );
sink->addFeature( f, QgsFeatureSink::FastInsert );
}
outputs.insert( QStringLiteral( "OUTPUT_TABLE" ), tableDest );

0 comments on commit ee34431

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