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


##########
common/src/main/java/org/apache/sedona/common/raster/RasterAccessors.java:
##########
@@ -127,6 +128,70 @@ public static String getGeoReference(GridCoverage2D 
raster, String format) {
         }
     }
 
+
+    public static double[] getGeoTransform(GridCoverage2D raster) throws 
FactoryException {
+        // size of a pixel along the transformed i axis
+        double magnitudeI;
+
+        // size of a pixel along the transformed j axis
+        double magnitudeJ;
+
+        // angle by which the raster is rotated (Radians positive clockwise)
+        double thetaI;
+
+        // angle from transformed i axis to transformed j axis (Radians 
positive counter-clockwise)
+        double thetaIJ;
+
+        RenderedImage renderedImage = raster.getRenderedImage();
+
+        // x ordinate of the upper-left corner of the upper-left pixel
+        double offsetX = renderedImage.getTileGridXOffset();
+
+        // y ordinate of the upper-left corner of the upper-left pixel
+        double offsetY = renderedImage.getTileGridYOffset();
+
+        double[] metadata = metadata(raster);
+        double scaleX = metadata[4];
+        double scaleY =  metadata[5];
+        double skewX = metadata[6];
+        double skewY = metadata[7];
+
+        // pixel size in i direction - west-east
+        magnitudeI = Math.sqrt(scaleX * scaleX + skewY * skewY);
+
+        // pixel size in j direction - north-south
+        magnitudeJ = Math.sqrt(scaleY * scaleY + skewX * skewX);
+
+        // Rotation
+        thetaI = Math.acos(scaleX / magnitudeI);
+        double thetaTest = Math.acos(skewY / magnitudeI);
+        if (thetaTest < Math.PI / 2) {
+            thetaI = -thetaI;
+        }
+
+        // Angular separation
+        thetaIJ = Math.acos((((scaleX * skewX) + (skewY * scaleY)) / 
(magnitudeI * magnitudeJ)));

Review Comment:
   can `magnitude` be zero or other invalid values? If so, we need to add 
handlers and test cases.



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