【问题标题】:Why won't my raster image display with levelplot?为什么我的光栅图像不能用 levelplot 显示?
【发布时间】:2020-06-26 17:57:36
【问题描述】:

我正在尝试覆盖包含夏威夷上空气溶胶高度数据的 netcdf4 栅格。有一个示例文件here. 我感兴趣的变量是纬度、经度、时间和气溶胶高度。这是一些可重复的数据。

s1 <- data.frame(as.vector(lon), as.vector(lat), as.vector(ah))
s1
#    as.vector.lon. as.vector.lat. as.vector.ah.
#1       -127.45199      -79.15431            NA
#2       -126.99632      -79.16919            NA
#3       -126.54577      -79.18321            NA
#4       -126.10027      -79.19641            NA
#5       -125.65974      -79.20880            NA
#6       -125.22412      -79.22042            NA
#7       -124.79333      -79.23129            NA

crsLatLon <- "+proj=longlat +datum=WGS84"
ex <- extent(c(-180,180,-90,90))

#empty raster with 0.1 degree resolution
pmraster <- raster(ncol=360*10, nrow=180*10, crs=crsLatLon,ext=ex)

#fills the empty raster with values from dataframe, s1
pmraster <- rasterize(s1[,1:2], pmraster, s1[,3], fun=mean, na.rm=T)

show(pmraster)
#class      : RasterLayer 
#dimensions : 1800, 3600, 6480000  (nrow, ncol, ncell)
#resolution : 0.1, 0.1  (x, y)
#extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
#source     : r_tmp_2020-06-26_114048_16840_75885.grd 
#names      : layer 
#values     : 0.1314196, 9424.118  (min, max)

#specifies region over Hawaii
exHI <- extent(c(-180,-140,10,30))

levelplot(crop(pmraster,exHI))

#Error: $ operator is invalid for atomic vectors
#In addition: Warning messages:
#1: In min(x) : no non-missing arguments to min; returning Inf
#2: In max(x) : no non-missing arguments to max; returning -Inf
#3: In min(x) : no non-missing arguments to min; returning Inf
#4: In max(x) : no non-missing arguments to max; returning -Inf

谁能帮助解释我收到此错误消息的原因以及如何继续生成所需的光栅图像?提前谢谢!

【问题讨论】:

  • 您应该提供一个最小的、自包含的、可重现的示例,使用代码创建一些数据或使用 R 包附带的数据。您的问题是关于将 levelplot 与 Raster 对象一起使用,这很容易完成,但没有示例数据就不容易回答,而且您的问题充满了我们无法运行的代码,与手头的问题无关。请编辑您的问题。
  • 对此我很抱歉,罗伯特。感谢您对我的 R 问题的回应。我已经修改了这个问题,希望能更简洁并提供一些可重复的数据。

标签: geospatial raster rasterizing satellite


【解决方案1】:

这是一个最小且可重现的示例:

library(raster)
library(lattice)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
levelplot(r)
#Error in UseMethod("levelplot") : 
#  no applicable method for 'levelplot' applied to an object of class "c('RasterLayer', #'Raster', 'BasicRaster')"

lattice 包方法不知道 Raster* 是什么。因此你不能像这样使用levelplot。好消息是rasterVis 包为Raster* 对象实现了lattice 方法;所以你需要做的就是

library(rasterVis)
levelplot(r)

查看?rasterVis 了解更多使用 levelplot 的方法

ssplot 也是基于 levelplot 构建的

spplot(r)

【讨论】:

    【解决方案2】:

    在对不同的文件进行了尝试后,我发现在我隔离的特定区域上没有可用的数据,这让我很困惑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 2011-04-22
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      • 2013-09-20
      相关资源
      最近更新 更多