apache / apache/sedona

[Sedona Core] Sedona doesn't clip raster to geometry extent in zonal statistics which can lead to inefficient queries

Open
#2,409 1 comment 0 reactions 0 assignees View on GitHub
sedona-core
Dominant language
Java
Stars
2.4k
Forks
784
Avg merge
1d 12h
Merged PRs (30d)
58

Description

In the Sedona core raster function, which is used in the zonal statistics

```java
private static List getStatObjects(GridCoverage2D raster, Geometry roi, int band, boolean allTouched, boolean excludeNoData, boolean lenient)
```

We loop through all elements of the raster data array rather than clipping it to the geometry's boundary. This leads to long processing runs, especially when the geometry's area is much smaller than the raster's size.

Example of zonal stats for a relatively small polygon in comparison to the raster

Image

exploding the rasters before calculating zonal stats, like below

```python
.selectExpr("rp", "Explode(RS_Tile(rast, 64, 64)) AS col")
```

Improves the speed of the processing a lot

Clipping before zonal stats is an easy improvement we can add.

cc: @jiayuasu

Contributor guide

Open the contributing guide

Research direction

Search the Sedona core raster code for getStatObjects(GridCoverage2D raster, Geometry roi, int band, boolean allTouched, boolean excludeNoData, boolean lenient). Review how zonal statistics currently loops through the raster data array, then investigate clipping the raster to the geometry boundary before that processing. Done means small geometries avoid processing the full raster while zonal-statistics results remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.