【发布时间】:2022-12-15 01:39:38
【问题描述】:
我正在使用来自 landfire.gov 的生物物理设置栅格数据集。当我最初使用 terra::rast() 读取数据集时,一切似乎都在工作。但是,当我尝试使用多边形裁剪数据时,0-255 范围之外的所有值都将替换为 NA。如果我尝试将此栅格投影到新的坐标参考系统,超出此范围的值也会被删除。谁能解释为什么这个栅格被限制为数据类型 INT1U 的值以及我如何绕过它?
下面我提供了一个可重现的代码示例,说明我如何尝试处理此数据集。此示例依赖于两个公共数据集:
- Biophysical Settings from Landfire.gov
-
North Carolina state boundary from nconemap.gov(将其下载为 shapefile)
library(terra) library(dplyr) library(sf) # Establish paths to required files. # ** These will need to be replaced with your local paths bpsDirPath <- "./dataRaw/envTerr/LF2020_BPS_220_CONUS/" ncBoundaryPath <- "C:/Users/Eliot-KDV/Desktop/NCDOT_State_Boundary/NCDOT_State_Boundary.shp" # Read in biophysicall setting raster data bpsRaw <- terra::rast(paste0(bpsDirPath, "Tif/LC20_BPS_220.tif")) # Read in codebook for bps categories codeBook <- read.csv(paste0(bpsDirPath, "CSV_Data/LF20_BPS_220.csv")) # Read in North Carolina state boundary ncBoundary <- read_sf(ncBoundaryPath) # Set levels of biophysical setting to category names provided in codebook instead # of category codes. This step is unnecessary but makes plot more readable levels(bpsRaw) <- dplyr::select(codeBook, VALUE, BPS_NAME) # Take a look before any spatial operations, note that North Carolina countains # numerous different levels plot(bpsRaw) # Transform ncBoundary to epsg:5070 so bps and ncBoundary share the same CRS ncBoundary <- st_transform(ncBoundary, "epsg:5070") # Crop bps to north carolina boundary bpsNc <- terra::crop(bpsRaw, vect(ncBoundary), mask = TRUE) # Look after cropping to NC boundary, now it only contains Open Water and # Barren-Rock/Sand/Clay plot(bpsNc)将生物物理设置栅格裁剪到北卡罗来纳州边界后,会显示警告“检测到的值超出数据类型 INT1U 的限制”。
我尝试使用 terraOptions() 将默认数据类型设置为 INT2S 但无济于事。如果有人能解释为什么会发生这种情况以及我如何纠正它,那就太好了!
更新:
现有植被高度代码:
# This does not work as expected library(terra) evhRaw <- terra::rast("./dataRaw/envTerr/LF2022_EVH_220_CONUS/Tif/LC22_EVH_220.tif") nc <- terra::vect("./dataTidy/cadastral/NCDOT_State_Boundary/NCDOT_State_Boundary.shp") ncp <- project(nc, evhRaw) evhNc <- terra::crop(evhRaw, ncp, mask = TRUE) # This is where the issue occurs evhNcPlane <- terra::project(evhNc, "epsg:2264")生物物理设置代码:
# This code works as expected library(terra) bpsRaw <- terra::rast("./dataRaw/envTerr/LF2020_BPS_220_CONUS/Tif/LC20_BPS_220.tif") nc <- terra::vect("./dataTidy/cadastral/NCDOT_State_Boundary/NCDOT_State_Boundary.shp") ncp <- project(nc, bpsRaw) bpsNc <- terra::crop(bpsRaw, ncp, mask = TRUE) bpsNcPlane <- terra::project(bpsNc, "epsg:2264")
【问题讨论】: