You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "iGN5117 (via GitHub)" <gi...@apache.org> on 2023/08/04 23:09:57 UTC

[GitHub] [sedona] iGN5117 commented on a diff in pull request #946: [SEDONA-343] Add RS_Contains and RS_Within

iGN5117 commented on code in PR #946:
URL: https://github.com/apache/sedona/pull/946#discussion_r1284900598


##########
common/src/main/java/org/apache/sedona/common/raster/RasterPredicates.java:
##########
@@ -46,20 +46,43 @@ public class RasterPredicates {
     public static boolean rsIntersects(GridCoverage2D raster, Geometry queryWindow) {
         Envelope2D rasterEnvelope2D = raster.getEnvelope2D();
         CoordinateReferenceSystem rasterCRS = rasterEnvelope2D.getCoordinateReferenceSystem();
-        int queryWindowSRID = queryWindow.getSRID();
-        if (rasterCRS != null && !(rasterCRS instanceof DefaultEngineeringCRS) && queryWindowSRID > 0) {
+        queryWindow = convertCRSIfNeeded(queryWindow, rasterCRS);
+        Envelope rasterEnvelope = JTS.toEnvelope(rasterEnvelope2D);
+        Geometry rasterGeometry = GEOMETRY_FACTORY.toGeometry(rasterEnvelope);
+        return rasterGeometry.intersects(queryWindow);
+    }
+
+    public static boolean rsContains(GridCoverage2D raster, Geometry geometry) {
+        Envelope2D rasterEnvelope2D = raster.getEnvelope2D();
+        CoordinateReferenceSystem rasterCRS = rasterEnvelope2D.getCoordinateReferenceSystem();
+        geometry = convertCRSIfNeeded(geometry, rasterCRS);
+        Envelope rasterEnvelope = JTS.toEnvelope(rasterEnvelope2D);
+        Geometry rasterGeometry = GEOMETRY_FACTORY.toGeometry(rasterEnvelope);
+        return  rasterGeometry.contains(geometry);
+    }
+
+    public static boolean rsWithin(GridCoverage2D raster, Geometry geometry) {
+        Envelope2D rasterEnvelope2D = raster.getEnvelope2D();
+        CoordinateReferenceSystem rasterCRS = rasterEnvelope2D.getCoordinateReferenceSystem();
+        geometry = convertCRSIfNeeded(geometry, rasterCRS);
+        Envelope rasterEnvelope = JTS.toEnvelope(rasterEnvelope2D);
+        Geometry rasterGeometry = GEOMETRY_FACTORY.toGeometry(rasterEnvelope);
+        return  rasterGeometry.within(geometry);
+    }
+
+    private static Geometry convertCRSIfNeeded(Geometry geometry, CoordinateReferenceSystem rasterCRS) {
+        int geomSRID = geometry.getSRID();
+        if (rasterCRS != null && !(rasterCRS instanceof DefaultEngineeringCRS) && geomSRID > 0) {

Review Comment:
   DefaultEngineeringCRS is the default CRS, as also mentioned in makeEmptyRaster()



-- 
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: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org