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


##########
common/src/main/java/org/apache/sedona/common/raster/RasterBandEditors.java:
##########
@@ -140,4 +150,133 @@ private static void isRasterSameShape(GridCoverage2D 
raster1, GridCoverage2D ras
                     "Second raster having width of %d and height of %d", 
width1, height1, width2, height2));
         }
     }
+
+    /**
+     * Return a clipped raster with the specified ROI by the geometry
+     * @param raster Raster to clip
+     * @param band Band number to perform clipping
+     * @param geometry Specify ROI
+     * @param noDataValue no-Data value for empty cells
+     * @param crop Specifies to keep the original extent or not
+     * @return A clip Raster with defined ROI by the geometry
+     */
+    public static GridCoverage2D clip(GridCoverage2D raster, int band, 
Geometry geometry, double noDataValue, boolean crop) throws FactoryException, 
TransformException {
+
+        // Selecting the band from original raster
+        RasterUtils.ensureBand(raster, band);
+        GridCoverage2D singleBandRaster = RasterBandAccessors.getBand(raster, 
new int[]{band});
+
+        // Crop the raster
+        // this will shrink the extent of the raster to the geometry
+        Crop cropObject = new Crop();
+        ParameterValueGroup parameters = cropObject.getParameters();
+        parameters.parameter("Source").setValue(singleBandRaster);

Review Comment:
   A single band is ok for now.



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