Skip to contents

The overlay_weights() function generates a table of weights mapping each grid cell to its respective polygon(s) for use in the staggregate_*() family of functions.

Usage

overlay_weights(
  polygons,
  polygon_id_col,
  grid = era5_grid,
  secondary_weights = NULL
)

Arguments

polygons

a simple features polygon or multipolygon object

polygon_id_col

the name of a column in the polygons object with a unique identifier for each polygon

grid

a raster layer with the same spatial resolution as the data

secondary_weights

an optional table of secondary weights, output from the secondary_weights() function

Value

a data.table of area weights and possibly secondary weights for each cell within each polygon

Examples

overlay_output_with_secondary_weights <- overlay_weights(
  polygons = nj_counties, # Polygons outlining the 21 counties of New Jersey
  polygon_id_col = "COUNTYFP", # The name of the column with the unique
                               # county identifiers
  grid = era5_grid, # The grid to use when extracting area weights (era5_grid is the
                    # default)
  secondary_weights = cropland_world_2015_era5 # Output from
                                               # secondary_weights
                                               # (cropland_world_2015_era5 is
                                               # available to the# user)
  )
#> Checking for raster/polygon alignment
#> Aligning longitudes to standard coordinates.
#> Extracting raster polygon overlap
#> Secondary weights fully overlap with the administrative regions.
#> Checking sum of weights within polygons
#> All weights sum to 1.

head(overlay_output_with_secondary_weights)
#>        x     y poly_id      w_area      weight
#>    <num> <num>  <char>       <num>       <num>
#> 1: 284.5 39.25     011 0.017221145 0.033565672
#> 2: 284.5 39.25     033 0.005816417 0.006236843
#> 3: 284.5 39.50     011 0.017033115 0.028784469
#> 4: 284.5 39.50     033 0.355072708 0.330109034
#> 5: 284.5 39.75     015 0.021931677 0.024382703
#> 6: 284.5 39.75     033 0.182386051 0.156198032



overlay_output_without_secondary_weights <- overlay_weights(
  polygons = nj_counties, # Polygons outlining the 21 counties of New Jersey
  polygon_id_col = "COUNTYFP" # The name of the column with the unique county
                              # identifiers
  )
#> Checking for raster/polygon alignment
#> Aligning longitudes to standard coordinates.
#> Extracting raster polygon overlap
#> Checking sum of weights within polygons
#> All weights sum to 1.

head(overlay_output_without_secondary_weights)
#>         x     y poly_id       w_area w_sum
#>     <num> <num>  <char>        <num> <num>
#> 1: 285.00 41.25     037 0.0140156458     1
#> 2: 285.25 41.25     037 0.3241450630     1
#> 3: 285.50 41.25     037 0.2178277183     1
#> 4: 285.75 41.25     037 0.0002487302     1
#> 5: 285.00 41.00     037 0.0470109628     1
#> 6: 285.25 41.00     037 0.3165378806     1