Kontinuation commented on code in PR #1080:
URL: https://github.com/apache/sedona/pull/1080#discussion_r1392018016


##########
common/src/main/java/org/apache/sedona/common/utils/RasterUtils.java:
##########
@@ -80,6 +79,88 @@ public static GridCoverage2D create(WritableRaster raster, 
GridGeometry2D gridGe
         return create(raster, gridGeometry, bands, null);
     }
 
+    /**
+     * Create a new raster, cloning all metadata from the passed reference 
raster.
+     * @param raster The raster object to be wrapped as an image.
+     * @param referenceRaster The reference raster to clone, all metadata is 
cloned
+     * @param noDataValue Optionally, a new noDataValue, if passed null, 
noDataVal of the reference raster is used.
+     * @return cloned raster
+     */
+    public static GridCoverage2D create(WritableRaster raster, GridCoverage2D 
referenceRaster, Double noDataValue, boolean keepMetadata) {
+        GridSampleDimension[] bands = keepMetadata ? 
referenceRaster.getSampleDimensions() : null;
+        if (Objects.isNull(noDataValue)) {
+            noDataValue = 
RasterBandAccessors.getBandNoDataValue(referenceRaster, 1); //resort to using 
noDataValue of the original raster.
+        }
+        Map propertyMap = null;
+        if (keepMetadata) {
+            propertyMap = referenceRaster.getProperties();
+        }
+        ColorModel originalColorModel = 
referenceRaster.getRenderedImage().getColorModel();
+        GridGeometry2D gridGeometry = referenceRaster.getGridGeometry();
+        int numBand = raster.getNumBands();
+        int rasterDataType = raster.getDataBuffer().getDataType();
+
+        final ColorSpace cs = new BogusColorSpace(numBand);
+        final int[] nBits = new int[numBand];
+        Arrays.fill(nBits, DataBuffer.getDataTypeSize(rasterDataType));
+        ColorModel colorModel =
+                new ComponentColorModel(cs, nBits, false, true, 
Transparency.OPAQUE, rasterDataType);

Review Comment:
   I suggest moving the construction of the fallback color model object to the 
`else` branch, since it does not need to be created when the original color 
model is compatible.



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