Skip to content

Commit 0e900b6

Browse files
committed
Addition of the strategy argument for _zonal_stats_exactextract, allows for the specification of feature-sequential or raster-sequential
1 parent 5affd7a commit 0e900b6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

xvec/zonal.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def _zonal_stats_exactextract(
309309
y_coords: Hashable,
310310
stats: str | Callable | Sequence[str | Callable | tuple] = "mean",
311311
name: str = "geometry",
312+
strategy: str = "feature-sequential"
312313
) -> xr.DataArray | xr.Dataset:
313314
"""Extract the values from a dataset indexed by a set of geometries
314315
@@ -363,7 +364,7 @@ def _zonal_stats_exactextract(
363364
raise ValueError(f"{stat} is not a valid aggregation.")
364365

365366
results, original_shape, coords_info, locs = _agg_exactextract(
366-
acc, geometry, crs, x_coords, y_coords, stats, name, original_is_ds
367+
acc, geometry, crs, x_coords, y_coords, stats, name, original_is_ds, strategy
367368
)
368369
i = 0
369370
for stat in stats: # type: ignore
@@ -393,7 +394,7 @@ def _zonal_stats_exactextract(
393394
)
394395
elif isinstance(stats, str):
395396
results, original_shape, coords_info, _ = _agg_exactextract(
396-
acc, geometry, crs, x_coords, y_coords, stats, name, original_is_ds
397+
acc, geometry, crs, x_coords, y_coords, stats, name, original_is_ds, strategy
397398
)
398399
# Unstack the result
399400
arr = results.values.reshape(original_shape)
@@ -429,6 +430,7 @@ def _agg_exactextract(
429430
stats: str | Callable | Iterable[str | Callable | tuple] = "mean",
430431
name: str = "geometry",
431432
original_is_ds: bool = False,
433+
strategy: str = "feature-sequential"
432434
):
433435
"""Extract the values from a dataset indexed by a set of geometries
434436
@@ -492,7 +494,7 @@ def _agg_exactextract(
492494

493495
# Aggregation result
494496
gdf = gpd.GeoDataFrame(geometry=geometry, crs=crs)
495-
results = exactextract.exact_extract(rast=data, vec=gdf, ops=stats, output="pandas")
497+
results = exactextract.exact_extract(rast=data, vec=gdf, ops=stats, output="pandas", strategy=strategy)
496498
# Get all the dimensions execpt x_coords, y_coords, they will be used to stack the
497499
# dataarray later
498500
if original_is_ds is True:

0 commit comments

Comments
 (0)