This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 81582e6c [SEDONA-332] Make RS_Values only fetch relevant tiles, 
instead of fetching the entire raster (#931)
81582e6c is described below

commit 81582e6c348c6b6cb2ac511adda14688ec2030ef
Author: Kristin Cowalcijk <[email protected]>
AuthorDate: Fri Jul 28 15:27:34 2023 +0800

    [SEDONA-332] Make RS_Values only fetch relevant tiles, instead of fetching 
the entire raster (#931)
---
 .../org/apache/sedona/common/raster/PixelFunctions.java   | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java 
b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java
index 6d6ca6c3..64a591d3 100644
--- a/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java
+++ b/common/src/main/java/org/apache/sedona/common/raster/PixelFunctions.java
@@ -18,15 +18,14 @@
  */
 package org.apache.sedona.common.raster;
 
-import org.geotools.coverage.grid.GridCoordinates2D;
 import org.geotools.coverage.grid.GridCoverage2D;
-import org.geotools.coverage.grid.GridGeometry2D;
 import org.geotools.geometry.DirectPosition2D;
 import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.geom.Point;
+import org.opengis.coverage.PointOutsideCoverageException;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.operation.TransformException;
 
-import java.awt.image.Raster;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -47,8 +46,6 @@ public class PixelFunctions
             // Invalid band index. Return nulls.
             return geometries.stream().map(geom -> (Double) 
null).collect(Collectors.toList());
         }
-        Raster raster = rasterGeom.getRenderedImage().getData();
-        GridGeometry2D gridGeometry = rasterGeom.getGridGeometry();
         double[] noDataValues = rasterGeom.getSampleDimension(band - 
1).getNoDataValues();
         DoublePredicate isNoData = d -> noDataValues != null && 
DoubleStream.of(noDataValues).anyMatch(noDataValue -> 
Double.compare(noDataValue, d) == 0);
         double[] pixelBuffer = new double[numBands];
@@ -59,16 +56,16 @@ public class PixelFunctions
                 result.add(null);
             } else {
                 Point point = ensurePoint(geom);
-                DirectPosition2D directPosition2D = new 
DirectPosition2D(point.getX(), point.getY());
-                GridCoordinates2D gridCoordinates2D = 
gridGeometry.worldToGrid(directPosition2D);
+                DirectPosition directPosition2D = new 
DirectPosition2D(point.getX(), point.getY());
                 try {
-                    double pixel = raster.getPixel(gridCoordinates2D.x, 
gridCoordinates2D.y, pixelBuffer)[band - 1];
+                    rasterGeom.evaluate(directPosition2D, pixelBuffer);
+                    double pixel = pixelBuffer[band - 1];
                     if (isNoData.test(pixel)) {
                         result.add(null);
                     } else {
                         result.add(pixel);
                     }
-                } catch (ArrayIndexOutOfBoundsException exc) {
+                } catch (PointOutsideCoverageException | 
ArrayIndexOutOfBoundsException exc) {
                     // Points outside the extent should return null
                     result.add(null);
                 }

Reply via email to