R-变量存储为Formal类RasterLayer,数据内容丢失

时间:2018-02-01 13:41:49

标签: r geospatial spatial raster r-raster

定义新的栅格图层(Sentinel 2 MSI)

> ras1 = raster ("T45QVG_20161209T045202_B02.jp2")
> summary (ras1)
1st Qu.                       1160
Median                        1230
3rd Qu.                       1300
Max.                          2221
NA's                             0
Warning message:
In .local(object, ...) :
  summary is an estimate based on a sample of 1e+05 cells (0.08% of all cells)

现在,将定义的栅格图层指定给另一个变量

> ras2 = raster (ras1)
> summary (ras2)
layer
Min.       NA
1st Qu.    NA
Max.       NA
NA's       NA

此外,

> ras1
class       : RasterLayer 
dimensions  : 10980, 10980, 120560400  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent      : 399960, 509760, 2590200, 2700000  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=45 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : /home/riyas/Data/Work files/Data samples/Sentinel 2-MSI/S2A_MSIL1C_20161209T045202_N0204_R076_T45QVG_20161209T045602.SAFE/GRANULE/L1C_T45QVG_A007652_20161209T045602/IMG_DATA/T45QVG_20161209T045202_B02.jp2 
names       : T45QVG_20161209T045202_B02 
values      : 0, 65535  (min, max)

包含所有值,但

> ras2
class       : RasterLayer 
dimensions  : 10980, 10980, 120560400  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent      : 399960, 509760, 2590200, 2700000  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=45 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 

在分配给一个新变量后,一切都搞砸了!!

1 个答案:

答案 0 :(得分:2)

raster对象上调用RasterLayer只会创建一个空的RasterLayer对象,该对象与原始对象具有相同的属性(例如范围,分辨率,大小)但是没有值。

含义,ras2 <- raster(ras1)将创建ras2,这是一个具有Sentinel-2维度的空栅格。这也是调用summary正在返回NA s。

的原因

如果您想将其分配给新变量,那么制作简单副本就可以运行ras2 <- ras1