prantogg commented on code in PR #1221:
URL: https://github.com/apache/sedona/pull/1221#discussion_r1473320725


##########
common/src/main/java/org/apache/sedona/common/raster/MapAlgebra.java:
##########
@@ -437,6 +437,57 @@ public static double[] normalize(double[] band) {
         return result;
     }
 
+    /**
+     *
+     * @param rasterGeom Raster to be normalized
+     * @return a raster with all values in all bands normalized between [0 - 
255]
+     */
+    public static GridCoverage2D normalizeAll(GridCoverage2D rasterGeom) {
+        return normalizeAll(rasterGeom, 0d, 255d);
+    }
+
+    /**
+     *
+     * @param rasterGeom Raster to be normalized
+     * @param minLim Lower limit of normalization range
+     * @param maxLim Upper limit of normalization range
+     * @return a raster with all values in all bands normalized between minLim 
and maxLim
+     */
+    public static GridCoverage2D normalizeAll(GridCoverage2D rasterGeom, 
double minLim, double maxLim) {
+        if (minLim > maxLim) {
+            throw new IllegalArgumentException("minLim cannot be greater than 
maxLim");
+        }
+
+        int numBands = rasterGeom.getNumSampleDimensions();
+
+        for (int bandIndex = 1; bandIndex <= numBands; bandIndex++) {
+            // Get the band values as an array
+            double[] bandValues = bandAsArray(rasterGeom, bandIndex);
+
+            // Find min and max values in the band
+            double minValue = 
Arrays.stream(bandValues).min().orElse(Double.NaN);
+            double maxValue = 
Arrays.stream(bandValues).max().orElse(Double.NaN);
+            System.out.println("minValue: "+minValue);
+            System.out.println("maxValue: "+maxValue);
+
+            if (minValue == maxValue) {
+                // If all values in the band are same - set middle value of 
range as default value.
+                double defaultValue = (minLim + maxLim) / 2.0;

Review Comment:
   Sure. Have described the current behavior in the PR description above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to