MCPcopy Create free account
hub / github.com/OSGeo/gdal / SetStatFields

Function SetStatFields

alg/zonal.cpp:780–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

778 }
779
780 void SetStatFields(OGRFeature &feature, int iBand,
781 const gdal::RasterStats<double> &stats) const
782 {
783 if (auto iField = GetFieldIndex(iBand, CENTER_X); iField != -1)
784 {
785 const auto &center_x = stats.center_x();
786 feature.SetField(iField, static_cast<int>(center_x.size()),
787 center_x.data());
788 }
789 if (auto iField = GetFieldIndex(iBand, CENTER_Y); iField != -1)
790 {
791 const auto &center_y = stats.center_y();
792 feature.SetField(iField, static_cast<int>(center_y.size()),
793 center_y.data());
794 }
795 if (auto iField = GetFieldIndex(iBand, COUNT); iField != -1)
796 {
797 feature.SetField(iField, stats.count());
798 }
799 if (auto iField = GetFieldIndex(iBand, COVERAGE); iField != -1)
800 {
801 const auto &cov = stats.coverage_fractions();
802 std::vector<double> doubleCov(cov.begin(), cov.end());
803 // TODO: Add float* overload to Feature::SetField to avoid this copy
804 feature.SetField(iField, static_cast<int>(doubleCov.size()),
805 doubleCov.data());
806 }
807 if (auto iField = GetFieldIndex(iBand, FRAC); iField != -1)
808 {
809 const auto count = stats.count();
810 const auto &freq = stats.freq();
811 std::vector<double> values;
812 values.reserve(freq.size());
813 for (const auto &[_, valueCount] : freq)
814 {
815 values.push_back(valueCount.m_sum_ci / count);
816 }
817 feature.SetField(iField, static_cast<int>(values.size()),
818 values.data());
819 }
820 if (auto iField = GetFieldIndex(iBand, MAX); iField != -1)
821 {
822 const auto &max = stats.max();
823 if (max.has_value())
824 feature.SetField(iField, max.value());
825 }
826 if (auto iField = GetFieldIndex(iBand, MAX_CENTER_X); iField != -1)
827 {
828 const auto &loc = stats.max_xy();
829 if (loc.has_value())
830 feature.SetField(iField, loc.value().first);
831 }
832 if (auto iField = GetFieldIndex(iBand, MAX_CENTER_Y); iField != -1)
833 {
834 const auto &loc = stats.max_xy();
835 if (loc.has_value())
836 feature.SetField(iField, loc.value().second);
837 }

Callers 3

ProcessRasterZonesFunction · 0.85

Calls 15

valueMethod · 0.80
max_xyMethod · 0.80
meanMethod · 0.80
minorityMethod · 0.80
min_xyMethod · 0.80
modeMethod · 0.80
varietyMethod · 0.80
weighted_meanMethod · 0.80
weighted_stdevMethod · 0.80
weighted_sumMethod · 0.80
weighted_varianceMethod · 0.80
GetFieldIndexFunction · 0.70

Tested by

no test coverage detected