我正在使用landfire. gov中的Biophysical settings栅格数据集。当我最初用terra::rast()读入数据集时,一切看起来都正常。但是,当我尝试使用多边形裁剪数据时,所有0-255范围之外的值都被替换为NA。如果我尝试将此栅格投影到新的坐标参考系,则此范围之外的值也会被丢弃。有人能解释一下为什么此栅格被限制为数据类型INT 1U的值,以及我如何绕过此问题吗?
下面我提供了一个可重复的代码示例,说明我是如何处理这个数据集的。这个示例依赖于两个公共数据集:
- 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)
将生物物理设置栅格裁剪到北卡罗来纳州边界后,将显示警告“检测到数据类型INT 1U限制之外的值”。
我尝试使用terraOptions()将默认数据类型设置为INT 2S,但没有成功。如果有人能解释为什么会发生这种情况,以及我如何纠正它,那就太好了!
1条答案
按热度按时间uxhixvfz1#
您使用的是当前版本的“terra”吗?我这么问是因为这对我来说很好用: