R 中具有数值的温度数据的栅格堆栈
Rasterstack of temperature data with numeric value in R
我想用 R 中的栅格数据做一些测试。我需要数值。但是 R 只显示整数。我怎样才能改变这个?任何的想法?提前致谢 :D
#libraries
library(raster)
library(rgdal)
setwd("C:/Users/cathe/Documents/Cropped_raster")
## polygon with crop-extend ##
shp <- readOGR("C:/Users/cathe/OneDrive/Documents/ArcGIS/Projects/CLC2000_shapefiles/CLC2000_Nichtdurchgängig städtische Prägung.shp")
## load tif files ##
infiles = list.files(path=getwd(),
pattern="*.tif$|*.TIF$")
## Filenames with desired suffix and output place ##
outfiles = file.path("C:/Users/cathe/Documents/Cropped_raster_nicht_durchgängig",
paste0(basename(tools::file_path_sans_ext(infiles)),
".tif"))
outfiles[outfiles == -9999] <- NA #alle -9999 auf NA setzen, wenn nötig
## crop and output settings (compression and datatype)
for (i in seq_along(infiles)) {
r = crop(stack(infiles[i]), shp)
writeRaster(r, filename=outfiles[i],
bylayer=FALSE,
format="GTiff",
datatype="numeric",
options="COMPRESS=ZIP",
x, NAflag=-9999,
overwrite=TRUE)
}
您的问题出在 writeRaster()
的 datatype
参数中。
来自文档:
datatype: Character. Output data type (e.g. 'INT2S' or 'FLT4S'). See
dataType. If no datatype is specified, 'FLT4S' is used, unless this
default value was changed with rasterOptions
数字只存在于R世界。在外面你有整数和浮点数,你需要什么取决于你的数据。
我想用 R 中的栅格数据做一些测试。我需要数值。但是 R 只显示整数。我怎样才能改变这个?任何的想法?提前致谢 :D
#libraries
library(raster)
library(rgdal)
setwd("C:/Users/cathe/Documents/Cropped_raster")
## polygon with crop-extend ##
shp <- readOGR("C:/Users/cathe/OneDrive/Documents/ArcGIS/Projects/CLC2000_shapefiles/CLC2000_Nichtdurchgängig städtische Prägung.shp")
## load tif files ##
infiles = list.files(path=getwd(),
pattern="*.tif$|*.TIF$")
## Filenames with desired suffix and output place ##
outfiles = file.path("C:/Users/cathe/Documents/Cropped_raster_nicht_durchgängig",
paste0(basename(tools::file_path_sans_ext(infiles)),
".tif"))
outfiles[outfiles == -9999] <- NA #alle -9999 auf NA setzen, wenn nötig
## crop and output settings (compression and datatype)
for (i in seq_along(infiles)) {
r = crop(stack(infiles[i]), shp)
writeRaster(r, filename=outfiles[i],
bylayer=FALSE,
format="GTiff",
datatype="numeric",
options="COMPRESS=ZIP",
x, NAflag=-9999,
overwrite=TRUE)
}
您的问题出在 writeRaster()
的 datatype
参数中。
来自文档:
datatype: Character. Output data type (e.g. 'INT2S' or 'FLT4S'). See dataType. If no datatype is specified, 'FLT4S' is used, unless this default value was changed with rasterOptions
数字只存在于R世界。在外面你有整数和浮点数,你需要什么取决于你的数据。