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


##########
common/src/main/java/org/apache/sedona/common/raster/RasterBandAccessors.java:
##########
@@ -134,6 +138,39 @@ public static double[] getSummaryStats(GridCoverage2D 
raster) {
 //        return getSummaryStats(raster, 1, excludeNoDataValue);
 //    }
 
+    public static GridCoverage2D getBand(GridCoverage2D rasterGeom, int[] 
bandIndexes) throws FactoryException {
+        Double noDataValue;
+        double[] metadata = RasterAccessors.metadata(rasterGeom);
+        int width = (int) metadata[2], height = (int) metadata[3];
+        GridCoverage2D resultRaster = 
RasterConstructors.makeEmptyRaster(bandIndexes.length, width, height,
+                metadata[0], metadata[1], metadata[4], metadata[5], 
metadata[6], metadata[7], (int) metadata[8]);
+
+        // Get band data that's required
+        int[] bandsDistinct = Arrays.stream(bandIndexes).distinct().toArray();
+        double [][] bandData = new double[bandsDistinct.length][height * 
width];
+        for (int curBand: bandsDistinct) {
+            RasterUtils.ensureBand(rasterGeom, curBand);
+            bandData[curBand - 1] = MapAlgebra.bandAsArray(rasterGeom, 
curBand);

Review Comment:
   The code here has a bug. It cannot handle cases such as `3, 3, 3` and will 
throw index out of bound error



-- 
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