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


##########
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:
   If this happens, please choose `minLim` as the default value.
   
   Please describe the behavior in the document.



##########
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) {

Review Comment:
   Please add 2 more optional parameters to this function which takes the 
minValue and maxValue from users. If the 2 values are not given, we compute the 
min and max ourselves.



-- 
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: issues-unsubscr...@sedona.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to