我想画栅格线(l
)只是为了"目标"。不考虑NA值的x
栅格分类。我试着做:
# Packages
library(stars)
library(sf)
#Vectorizing a raster object to an sf object
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)[, 1:50, 1:50, 1:2]
x[[1]] = round(x[[1]]/5)
x[[1]] = ifelse(x[[1]]<10,NA,"target")
str(x[[1]])
#Polygonizing
l = st_contour(x)
plot(l[1])
Error in CPL_write_gdal(mat, file, driver, options, type, dims, from, :
Not compatible with requested type: [type=character; target=double].
但是,不工作。拜托,能帮帮忙吗?
提前感谢,
亚历山大
您的脚本有几个错误,首先,st_contour
指示它与字符类型不兼容(指"target")您在光栅中设置的字符串)。其次,我建议使用st_contour
中的break参数来设置您希望获得轮廓的目标值。此外,您可能希望使用x[rule] <- NA
来屏蔽栅格中的某些值。我对你的代码做了其他可能有帮助的修改:
# Let's stay with only the first band, indicated in the final dimension
x = read_stars(tif)[, 1:50, 1:50, 1]
x = round(x/5)
# Calculate the min and max of the raster values
purrr::map(x, min)
# 10
purrr::map(x, max)
# 28
# Mask values lower than 10
# However, this does not make any change, because the lowest value is 10
x[x<10] <- NA
# Take a look at the image
plot(x)
# Obtain the contours
l = st_contour(x,
# Remove NA
na.rm = T,
# Obtain contour lines instead of polygons
contour_lines = TRUE,
# raster values at which to draw contour levels
breaks = 12)
# Plot the contours
plot(l)