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


##########
common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java:
##########
@@ -91,6 +92,45 @@ public static Geometry getPixelAsPoint(GridCoverage2D 
raster, int colX, int rowY
         return GEOMETRY_FACTORY.createPoint(pointCoord);
     }
 
+    public static List<PixelRecord> getPixelAsPoints(GridCoverage2D 
rasterGeom, int band) throws TransformException, FactoryException {
+        RasterUtils.ensureBand(rasterGeom, band);
+
+        int width = RasterAccessors.getWidth(rasterGeom);
+        int height = RasterAccessors.getHeight(rasterGeom);
+
+        Raster r = RasterUtils.getRaster(rasterGeom.getRenderedImage());
+        double[] pixels = r.getSamples(0, 0, width, height, band - 1, 
(double[]) null);
+
+        AffineTransform2D gridToCRS = 
RasterUtils.getGDALAffineTransform(rasterGeom);
+        double cellSizeX = gridToCRS.getScaleX();
+        double cellSizeY = gridToCRS.getScaleY();
+        double shearX = gridToCRS.getShearX();
+        double shearY = gridToCRS.getShearY();
+
+        int srid = RasterAccessors.srid(rasterGeom);
+        GeometryFactory geometryFactory = srid != 0 ? new GeometryFactory(new 
PrecisionModel(), srid) : GEOMETRY_FACTORY;
+
+        Point2D upperLeft = RasterUtils.getWorldCornerCoordinates(rasterGeom, 
1, 1);
+        List<PixelRecord> pointRecords = new ArrayList<>();
+
+        for (int y = 1; y <= height; y++) {

Review Comment:
   Should this share the same logic of RS_PixelAsPoint?



##########
common/src/test/java/org/apache/sedona/common/raster/FunctionsTest.java:
##########
@@ -183,6 +183,93 @@ public void testPixelAsPointFromRasterFile() throws 
IOException, TransformExcept
         assertEquals(expectedY, coordinate.getY(), 0.2d);
     }
 
+    @Test
+    public void testPixelAsPointSkewedRaster() throws FactoryException, 
TransformException {
+        // Testing with skewed raster
+        GridCoverage2D emptyRaster = RasterConstructors.makeEmptyRaster(1, 12, 
13, 240, -193, 2, 1.5, 3, 2, 0);
+        String actual = 
Functions.asWKT(PixelFunctions.getPixelAsPoint(emptyRaster, 3, 3));
+        String expected = "POINT (250 -186)";
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testPixelAsPointsOutputSize() throws FactoryException, 
TransformException {
+        GridCoverage2D raster = RasterConstructors.makeEmptyRaster(1, 5, 10, 
123, -230, 8);
+        List<PixelRecord> points = PixelFunctions.getPixelAsPoints(raster, 1);
+        assertEquals(50, points.size());
+    }
+
+    @Test
+    public void testPixelAsPointsValues() throws FactoryException, 
TransformException {
+        GridCoverage2D emptyRaster = RasterConstructors.makeEmptyRaster(1, 5, 
10, 123, -230, 8);
+        List<PixelRecord> points = 
PixelFunctions.getPixelAsPoints(emptyRaster, 1);
+
+        PixelRecord point1 = points.get(0);
+        Geometry geom1 = (Geometry) point1.geom;
+        assertEquals(123, geom1.getCoordinate().x, 0.2d);
+        assertEquals(-230, geom1.getCoordinate().y, 0.2d);
+        assertEquals(0.0, point1.value, 0.2d);
+
+        PixelRecord point2 = points.get(22);
+        Geometry geom2 = (Geometry) point2.geom;
+        assertEquals(139, geom2.getCoordinate().x, 0.2d);
+        assertEquals(-262, geom2.getCoordinate().y, 0.2d);
+        assertEquals(0.0, point2.value, 0.2d);
+    }
+
+    @Test
+    public void testPixelAsPointsCustomSRIDPlanar() throws FactoryException, 
TransformException {
+        int srid = 3857;
+        GridCoverage2D emptyRaster = RasterConstructors.makeEmptyRaster(1, 5, 
5, -123, 54, 5, 5, 0, 0, srid);
+        List<PixelRecord> points = 
PixelFunctions.getPixelAsPoints(emptyRaster, 1);
+        PixelRecord point1 = points.get(0);
+        Geometry geom1 = (Geometry) point1.geom;
+        assertEquals(-123, geom1.getCoordinate().x, 1e-9);

Review Comment:
   Please coordinate with @furqaankhan . If you need a delta value for float 
comparion, better set up a global value under `RasterTestBase`



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