-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-masks.R
More file actions
38 lines (27 loc) · 844 Bytes
/
create-masks.R
File metadata and controls
38 lines (27 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(terra)
library(sf)
# use CONUS MLRA boundaries for reasonable outline
mlra <- st_read('e:/gis_data/MLRA/MLRA_52-conus.shp')
# use ISSR800 grid system for mask
# 800m EPSG:5070
issr800 <- rast('e:/gis_data/FY2023-800m-rasters/rasters/cec.tif')
# GCS -> PCS
x <- st_transform(mlra, crs = 5070)
# retain outer-most polygon
x <- st_union(x, by_feature = FALSE)
# convert sf -> spatVect
x <- vect(x)
# check: ok
plot(x)
# new field in attribute table for rasterization
x$constant <- 1
# rasterize CONUS polygon according to ISSR800 grid system
r <- rasterize(x, issr800, field = 'constant')
# check: ok
plot(r)
lines(x)
# save
# unsigned, 8-bit integer (BYTE)
writeRaster(r, filename = 'masks/CONUS-MLRA52-mask.tif', overwrite = TRUE, datatype = 'INT1U')
# check: ok
sf::gdal_utils('info', source = 'masks/CONUS-MLRA52-mask.tif')