光栅分辨率显示不正确

raster resolution not displaying properly

我在绘制某个栅格时看到一些奇怪的行为。 这是我从 naturalearthdata.com.You can download it here.

获得的阴影浮雕栅格

我发现根据我绘制栅格的空间比例,它绘制不同的分辨率,尽管栅格的分辨率没有改变。

library(raster)
relief <- raster('GRAY_50M_SR_W.tif')

# let's use Mexico as an example:
library(maptools)
data(wrld_simpl)
mx <- wrld_simpl[which(wrld_simpl@data$NAME == 'Mexico'),]

# Here I create a cropped version of the raster
reliefMX <- crop(relief, mx)

为了说明问题,我绘制墨西哥以获得地图范围,然后绘制栅格的完整范围,然后在顶部绘制裁剪栅格。

您可以看到栅格显示的分辨率非常不同,但它们实际上具有相同的分辨率。

plot(mx)
plot(relief, col = grey(0:100/100), legend = FALSE, axes = F, box = F, add=T)
plot(reliefMX, col = grey(0:100/100), legend = FALSE, axes = F, box = F, add=T)

> res(relief)
[1] 0.03333333 0.03333333
> res(reliefMX)
[1] 0.03333333 0.03333333

有什么想法吗?我怎样才能让这些光栅正确显示?

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] maptools_0.9-2 raster_2.5-8   sp_1.2-4      

loaded via a namespace (and not attached):
[1] compiler_3.4.0  rgdal_1.2-7     tools_3.4.0     foreign_0.8-68  Rcpp_0.12.10   
[6] grid_3.4.0      lattice_0.20-35

这取决于调用 raster::plot 时的 maxpixels 参数:

maxpixels integer > 0. Maximum number of cells to use for the plot. If maxpixels < ncell(x), sampleRegular is used before plotting. If gridded=TRUE maxpixels may be ignored to get a larger sample

绘制 "full" 地图时,图像会自动缩减采样以节省内存并减少渲染时间。您可以更改“maxpixels”的值以获得所需的 "detail" 级别。参见示例:

plot(relief, col = grey(0:100/100), legend = FALSE, axes = F, box = F, add=F)

plot(relief, col = grey(0:100/100), legend = FALSE, axes = F, box = F, add=F, maxpixels = 5000000)

虽然这里"zoom level"不明显,但第二张图更详细。您可以在裁剪区域上 "zooming in" 欣赏这一点:

plot(mx)
plot(relief, col = grey(0:100/100), legend = FALSE, axes = F, box = F, add = T, maxpixels = 5000000)

仍然不是 "good" 作为先验裁剪的(因为我仍然没有使用 "all" 像素),但已经更好了。

实际上,这都是渲染 time/memory 和输出质量之间的折衷。显然,如果您只需要绘制区域的一部分,那么事先裁剪图像会更有效率。

HTH。