Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-707] Refactor rasterization process and add allTouched parameter for rasterization functions #1788

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

prantogg
Copy link
Contributor

@prantogg prantogg commented Feb 4, 2025

Did you read the Contributor Guide?

Is this PR related to a JIRA ticket?

What changes were proposed in this PR?

Fixes #1715

Affects API of downstream RS_Functions, introduces allTouched mode to:

  • RS_ZonalStatsAll & RS_ZonalStats
  • RS_Clip
  • RS_AsRaster
  • RS_SetValues

Algorithm Overview

The algorithm is inspired by GDAL’s GDALdllImageFilledPolygon but is implemented in Java with optimizations for duplicate handling, centroid-based inclusion, and allTouched behavior.

The rasterization process follows two main strategies:

  1. Polygon Rasterization (Scanline Algorithm)
    • Used for Polygon and MultiPolygon geometries.
    • Implements scanline-based filling with centroid-based inclusion.
    • Supports allTouched mode for including all pixels touched by the polygon.
  2. Line Rasterization (Modified Bresenham Algorithm)
    • Used for LineString and MultiLineString geometries.
    • Implements a modified Bresenham’s line-drawing algorithm with fractional steps.
    • Ensures sub-pixel accuracy using stepSize control.
    • Clips lines that extend beyond raster bounds.
  3. Optimized support for GeometryCollections and MultiPolygons
    • Decomposes into sub-geoms and computes a separate search gird for each.

How was this patch tested?

  • Passes new and existing tests
  • Benchmarked against previous rasterization process
    • Up to 31.4% faster rasterization for Polygons
    • Up to 194% faster for tests including all geometry types.

Did this PR include necessary documentation updates?

@github-actions github-actions bot added the docs label Feb 10, 2025
@prantogg prantogg marked this pull request as ready for review February 14, 2025 20:22
@prantogg prantogg requested a review from jiayuasu as a code owner February 14, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add all touched parameter to RS_ZonalStats
1 participant