Skip to content

Commit

Permalink
Default to no data value when processing statistics
Browse files Browse the repository at this point in the history
In GridToPointConverter, default to the no data value when processing zonal statistics. This ensures the no data value of the output matches the input.
  • Loading branch information
Tom Brauer committed Oct 26, 2024
1 parent 62996f2 commit 48dadd3
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ private ZonalStatistics computeZonalStatistics(String id, Integer[] mask, float[

double sum = validValues.stream().mapToDouble(f -> f).sum();
int count = validValues.size();
double average = Double.NaN;
double min = Double.NaN;
double max = Double.NaN;
double median = Double.NaN;
double firstQuartile = Double.NaN;
double thirdQuartile = Double.NaN;
float pctCellsGreaterThanZero = Float.NaN;
float pctCellsGreaterThanFirstQuartile = Float.NaN;
double average = noDataValue;
double min = noDataValue;
double max = noDataValue;
double median = noDataValue;
double firstQuartile = noDataValue;
double thirdQuartile = noDataValue;
double pctCellsGreaterThanZero = noDataValue;
double pctCellsGreaterThanFirstQuartile = noDataValue;
int numCellsGreaterThanZero = 0;
int numCellsGreaterThanFirstQuartile = 0;

Expand All @@ -245,7 +245,7 @@ private ZonalStatistics computeZonalStatistics(String id, Integer[] mask, float[
}
}

pctCellsGreaterThanZero = (float) (100 * numCellsGreaterThanZero) / count;
pctCellsGreaterThanZero = (double) (100 * numCellsGreaterThanZero) / count;

}

Expand All @@ -265,7 +265,7 @@ private ZonalStatistics computeZonalStatistics(String id, Integer[] mask, float[
numCellsGreaterThanFirstQuartile++;
}
}
pctCellsGreaterThanFirstQuartile = (float) (100 * numCellsGreaterThanFirstQuartile) / count;
pctCellsGreaterThanFirstQuartile = (double) (100 * numCellsGreaterThanFirstQuartile) / count;

}

Expand Down

0 comments on commit 48dadd3

Please sign in to comment.