首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在R中保持栅格计算后的分辨率和坐标基准不变

如何在R中保持栅格计算后的分辨率和坐标基准不变
EN

Stack Overflow用户
提问于 2021-07-09 17:23:36
回答 1查看 14关注 0票数 0
代码语言:javascript
复制
#####first import all files in a single folder as a list #####
rastlist <- list.files(path = ".", pattern='.tif$', all.files=TRUE, full.names=FALSE)

######load them in a stack  ######
allrasters <- stack(rastlist)
input_stack1 <- stack(brick(allrasters)) 

####### create array #######
try <- array(input_stack1, dim=c(13056, 4846,  2,1))

####### replace -3000 with NA #######
try[try==-3000]<-NA
input_array<-aperm(try, c(2,1,3,4))

####### convert back #######
output_stack1<-stack(brick(array(input_array, c(4846, 13056,  2))))

>input_stack1 
class      : RasterStack 
dimensions : 4846, 13056, 63269376, 2  (nrow, ncol, ncell, nlayers)
**resolution : 250, 250  (x, y)**
extent     : -1253475, 2010525, 2211480, 3422980  (xmin, xmax, ymin, ymax)
**crs        : +proj=utm +zone=51 +datum=WGS84 +units=m +no_defs** 
names      : MOSAIC_TMP_2019001.hdfout.250m_16_days_NDVI, MOSAIC_TMP_2019017.hdfout.250m_16_days_NDVI 
min values :                                       -3000,                                       -3000 
max values :                                        9996,                                        9996 

>output_stack1
class      : RasterStack 
dimensions : 4846, 13056, 63269376, 2  (nrow, ncol, ncell, nlayers)
**resolution : 7.659314e-05, 0.0002063558  (x, y)**
extent     : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
**crs        : NA** 
names      : layer.1, layer.2 
min values :   -2000,   -2000 
max values :    9996,    9996 

不知道为什么output_stack1中的分辨率和crs会发生变化。大家可以告诉我,在output_stack1中将-3000替换为NA后,如何保持input_stack1中的分辨率和crs

EN

回答 1

Stack Overflow用户

发布于 2021-07-10 00:45:52

我不确定您为什么要这样做,但它建议您可能想要查看raster包的手册或学习here材料

使用文件名列表创建RasterStack

代码语言:javascript
复制
library(raster)
f <- system.file("external/rlogo.grd", package="raster")
rastlist <- rep(f, 3)

s <- stack(rastlist)

(在此之后不要调用stack(brick());这不会做任何有用的事情,但可能会花费很多时间。)

现在对RasterStack进行重新分类。在本例中,使用255而不是-3000。

代码语言:javascript
复制
r <- reclassify(s, cbind(255, NA))
r 
#class      : RasterBrick 
#dimensions : 77, 101, 7777, 9  (nrow, ncol, ncell, nlayers)
#resolution : 1, 1  (x, y)
#extent     : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
#crs        : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
#source     : memory
#names      : red.1, green.1, blue.1, red.2, green.2, blue.2, red.3, green.3, blue.3 
#min values :     0,       0,      0,     0,       0,      0,     0,       0,      0 
#max values :   254,     254,    254,   254,     254,    254,   254,     254,    254 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68314415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档