prantogg commented on code in PR #1125:
URL: https://github.com/apache/sedona/pull/1125#discussion_r1400874342
##########
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:
It shares the same logic as RS_PixelAsPoint to retrieve upper left world
coordinates of first pixel in the raster.
For all other pixels, upper left world coordinates are calculated based on
pixel size and skew of raster. This eliminates the need to do transformations
from grid coords to world coords for every pixel.
I tested it against results of RS_PixelAsPoint to make sure the calculations
are accurate.
##########
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:
@jiayuasu It shares the same logic as RS_PixelAsPoint to retrieve upper left
world coordinates of first pixel in the raster.
For all other pixels, upper left world coordinates are calculated based on
pixel size and skew of raster. This eliminates the need to do transformations
from grid coords to world coords for every pixel.
I tested it against results of RS_PixelAsPoint to make sure the calculations
are accurate.
--
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]