furqaankhan commented on code in PR #1150:
URL: https://github.com/apache/sedona/pull/1150#discussion_r1433208848
##########
common/src/main/java/org/apache/sedona/common/raster/MapAlgebra.java:
##########
@@ -180,6 +174,82 @@ public static GridCoverage2D mapAlgebra(GridCoverage2D
gridCoverage2D, String pi
}
}
+ public static GridCoverage2D mapAlgebra(GridCoverage2D gridCoverage2D,
String pixelType, String script) {
+ return mapAlgebra(gridCoverage2D, pixelType, script, null);
+ }
+
+ private static ColorModel fetchColorModel(ColorModel originalColorModel,
WritableRaster resultRaster) {
+ if (originalColorModel.isCompatibleRaster(resultRaster)) {
+ return originalColorModel;
+ }else {
+ return PlanarImage.createColorModel(resultRaster.getSampleModel());
+ }
+ }
+
+ public static GridCoverage2D mapAlgebra(GridCoverage2D rast0,
GridCoverage2D rast1, String pixelType, String script, Double noDataValue) {
+ if (rast0 == null || rast1 == null || script == null) {
+ return null;
+ }
+ RasterUtils.isRasterSameShape(rast0, rast1);
+
+ RenderedImage renderedImageRast0 = rast0.getRenderedImage();
+ int rasterDataType = pixelType != null ?
RasterUtils.getDataTypeCode(pixelType) :
renderedImageRast0.getSampleModel().getDataType();
+ int width = renderedImageRast0.getWidth();
+ int height = renderedImageRast0.getHeight();
+ // ImageUtils.createConstantImage is slow, manually constructing a
buffered image proved to be faster.
+ // It also eliminates the data-copying overhead when converting raster
data types after running jiffle script.
+ WritableRaster resultRaster =
RasterFactory.createBandedRaster(DataBuffer.TYPE_DOUBLE, width, height, 1,
null);
+
+ ColorModel cmRast0 =
fetchColorModel(renderedImageRast0.getColorModel(), resultRaster);
+ RenderedImage renderedImageRast1 = rast1.getRenderedImage();
+ ColorModel cmRast1 =
fetchColorModel(renderedImageRast1.getColorModel(), resultRaster);
+
+ if (!cmRast0.equals(cmRast1)) {
+ throw new IllegalArgumentException("Color Model did not match.
Provide rasters that has the same properties.");
+ }
Review Comment:
@jiayuasu @Kontinuation Is this required to check the color models of the
two input rasters?
--
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]