2017-05-16 17 views
1

我在繪製某個光柵時會看到一些奇怪的行爲。 這是我從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([email protected]$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 

enter image description here

任何想法?我怎樣才能讓這些柵格正確顯示?

> 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 

回答

0

這取決於在呼叫中的maxpixels參數raster::plot:要使用的情節細胞

maxpixels 整數> 0的最大數目。如果maxpixels < ncell(x),則在繪圖之前使用sampleRegular。如果網格= TRUE maxpixels可以忽略得到更大的樣本

當您繪製的「全」圖,圖像會自動向下取樣,以節省您的記憶和減少渲染時間。您可以更改`maxpixels'的值以獲得所需級別的「詳細信息」。參見例如:

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

enter image description here

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

enter image description here

儘管這一 「縮放級別」 是不明顯的,第二圖像是更爲詳細。因爲我還沒有使用「全」像素

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

enter image description here

仍然沒有「好」的先驗冒出一個(:您可以通過在你的耕地面積「放大」明白這一點),但已經更好了。

實際上,這是渲染時間/內存和輸出質量之間的折衷。顯然,如果您只需要繪製該區域的一部分,事先裁剪圖像效率會更高。

HTH。