Kontinuation commented on code in PR #594:
URL: https://github.com/apache/sedona-db/pull/594#discussion_r2788772655


##########
rust/sedona-raster-functions/src/rs_envelope.rs:
##########
@@ -94,25 +94,37 @@ impl SedonaScalarKernel for RsEnvelope {
     }
 }
 
-/// Create WKB for a polygon for the raster
+/// Create WKB for the axis-aligned bounding box (envelope) of the raster.
+///
+/// This computes the four corners of the raster in world coordinates, then
+/// derives the min/max X and Y to produce an axis-aligned bounding box.
+/// For skewed/rotated rasters, this differs from the convex hull.
 fn create_envelope_wkb(raster: &dyn RasterRef, out: &mut impl std::io::Write) 
-> Result<()> {
-    // Compute the four corners of the raster in world coordinates.
-    // Due to skew/rotation in the affine transformation, each corner must be
-    // computed individually.
-
     let width = raster.metadata().width() as i64;
     let height = raster.metadata().height() as i64;
 
-    // Compute the four corners in pixel coordinates:
-    // Upper-left (0, 0), Upper-right (width, 0), Lower-right (width, height), 
Lower-left (0, height)
+    // Compute the four corners in world coordinates
     let (ulx, uly) = to_world_coordinate(raster, 0, 0);
     let (urx, ury) = to_world_coordinate(raster, width, 0);
     let (lrx, lry) = to_world_coordinate(raster, width, height);
     let (llx, lly) = to_world_coordinate(raster, 0, height);
 
+    // Compute the axis-aligned bounding box
+    let min_x = ulx.min(urx).min(lrx).min(llx);
+    let max_x = ulx.max(urx).max(lrx).max(llx);
+    let min_y = uly.min(ury).min(lry).min(lly);
+    let max_y = uly.max(ury).max(lry).max(lly);
+
     write_wkb_polygon(
         out,
-        [(ulx, uly), (urx, ury), (lrx, lry), (llx, lly), (ulx, 
uly)].into_iter(),
+        [
+            (min_x, max_y),
+            (max_x, max_y),
+            (max_x, min_y),
+            (min_x, min_y),
+            (min_x, max_y),

Review Comment:
   Fixed coordinate order and tests



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