# `cube_polygon_weights()`
**Category:** Grid geometry
**Status:** experimental

## Purpose
Compute sparse polygon-cell intersection weights.

## When to use
Use it when its declared input and output match the workflow. Prefer a narrower selection before any operation that may materialise values.

## When not to use
Do not use it to calculate `spatind` indicators or to bypass coordinate, CRS, unit, and provenance checks.

## Real signature
```r
cube_polygon_weights(x, polygons, id_col = NULL, crs = NULL, dimension = c("2d",      "3d"), depth_bounds = NULL, include_zero = FALSE)
```

## Arguments
- `x`: see the installed Rd manual for validation and defaults.
- `polygons`: see the installed Rd manual for validation and defaults.
- `id_col`: see the installed Rd manual for validation and defaults.
- `crs`: see the installed Rd manual for validation and defaults.
- `dimension`: see the installed Rd manual for validation and defaults.
- `depth_bounds`: see the installed Rd manual for validation and defaults.
- `include_zero`: see the installed Rd manual for validation and defaults.

## Input and output
Input: **ocean_cube + polygon**. Output: **data.frame**.

## Backend support
Memory: **TRUE**. NetCDF: **TRUE**. Backend operations retain read-only semantics; materialisation is explicit.

## Dimensional effect
Preserves the relevant cube contract or returns metadata/geometry without silently dropping axes.

## Metadata
Units, coordinates, provenance, masks, and QA metadata are retained or reported where meaningful.

## Minimal executable check
```r
library(oceancube)
stopifnot(is.function(oceancube::cube_polygon_weights))
names(formals(oceancube::cube_polygon_weights))
```

## Example in a workflow
Typical position: `cube_cell_area` → `cube_polygon_weights()` → `spatind`. See the workflow scripts for a checked end-to-end example.

## Frequent errors and limitations
Invalid dimensions, selectors, units, CRS, source-file identity, optional dependencies, or unsupported grids are rejected explicitly. Read the function Rd page for exact diagnostics.

## Related functions
Previous: `cube_cell_area`. Next: `spatind`.
