jiayuasu commented on code in PR #3114:
URL: https://github.com/apache/sedona/pull/3114#discussion_r3609971321
##########
common/src/main/java/org/apache/sedona/common/raster/Rasterization.java:
##########
@@ -85,6 +99,23 @@ protected static List<Object> rasterize(
return objects;
}
+ /**
+ * Fills every pixel of the freshly-allocated raster with the background
value, so pixels never
+ * covered by the geometry read back as that value instead of the allocation
default of 0. A null
+ * or zero background keeps the zero-initialized allocation as-is.
+ */
+ private static void fillBackground(WritableRaster writableRaster, Double
backgroundValue) {
+ if (backgroundValue == null || backgroundValue == 0) {
+ return;
+ }
+ int width = writableRaster.getWidth();
+ double[] row = new double[width];
+ Arrays.fill(row, backgroundValue);
Review Comment:
Would it be worth normalizing `backgroundValue` to `pixelType` before
writing it here? I may be missing validation elsewhere, but the integer sample
conversion seems able to produce a pixel value that differs from the nodata
metadata.
For example:
```sql
WITH r AS (
SELECT RS_AsRaster(
ST_GeomFromWKT('POLYGON ((0 3, 1 3, 1 2, 0 2, 0 3))'),
RS_MakeEmptyRaster(1, 'B', 3, 3, 0.0, 3.0, 1.0, -1.0, 0.0, 0.0, 0),
'B', false, 1.0, -1.0, false
) AS rast
)
SELECT RS_BandAsArray(rast, 1), RS_BandNoDataValue(rast, 1)
FROM r;
```
On this branch I get background pixels of `255`, while `RS_BandNoDataValue`
returns `-1.0`. Changing `-1.0` to `300.0` gives background pixels of `44` with
nodata metadata `300.0`.
That would leave the background counted as data for those inputs. PostGIS
looks like it clamps/truncates nodata to the band pixel type. Could we either
convert once and use the converted value for both the fill and metadata, or
reject values that the pixel type cannot represent?
--
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]