Find the spatial overlap between a raster and a set of polygons
Source:R/overlay_weights.R
overlay_weights.Rd
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.
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
Examples
overlay_output_with_secondary_weights <- overlay_weights(
polygons = tigris::counties("nj"), # 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
#> Retrieving data for the year 2022
#>
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================= | 34%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|============================== | 44%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|===================================== | 54%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|========================================================== | 84%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================= | 94%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
#> 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 = tigris::counties("nj"), # 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
#> Retrieving data for the year 2022
#> 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