[projectRaster使用自己的crs投影时会产生不同的输出

问题描述 投票:0回答:1

对于功能,我想使用用户设置的CRS重新投影栅格输入-本身是使用裁切和遮罩后的输出。我认为使用现有crs进行投影将无济于事,只是返回输入栅格。令我惊讶的是事实并非如此。下面是一个可复制的示例

创建虚拟栅格:

library(raster)

# Download country polygin, in this case Malawi
mwi <- raster::getData("GADM", country = "MWI", level = 0)

# Create dummy raster
grid <- raster::raster() # 1 degree raster
grid <- raster::disaggregate(grid, fact = 12) # 5 arcmin
grid <- raster::crop(grid, mwi)
values(grid) <- rep(1, ncell(grid)) # Set a value

# The input raster with dimensions 94,39,3666
grid <- raster::mask(grid, mwi)
plot(grid)
grid

# Reproject the raster using its own crs. I use ngb as it is a categorical variable.
# This raster has dimensions 102, 47, 4794 so it seems a lot of white space (NA) is added.
own_crs <- crs(grid)
grid_reproj <- raster::projectRaster(grid, crs = own_crs, method = "ngb")
plot(grid_reproj)
grid_reproj

# To remove the white space I use trim
# This results in a waster with dimensions 93, 39, 3627
grid_trim <- raster::trim(grid_reproj)
plot(grid_trim)
grid_trim

# I also decided to compare the maps visually with mapview
library(mapview)

# There seems to be a trim function in mapview which I set to FALSE
# Also use the browser for easy viewing
options(viewer = NULL)
mapviewOptions(trim = FALSE)
mapviewGetOption("trim")
mapview(grid, col.regions = "green", legend = F) +
  mapview(grid_reproj, col.regions = "red", legend = F) +
  mapview(grid_trim, col.regions = "blue", legend = F) 

比较地图,我观察到两件事:

(1)grid和grid_trim除了单个网格单元外几乎相同在上面。也许这是由于四舍五入,

(2)grid_reproj具有更大的尺寸和不同的程度。它也是与其他地图相比,该地图似乎略有偏移。这个通过修剪校正,因此我认为这些实际上是NA单元,其差异可能是与mapview如何显示地图有关。

因此,我的主要问题是,当rasterProject项目与同样的程度?为什么即使修剪后结果也不同?

r gis raster map-projections
1个回答
0
投票

要以right的方式投射栅格数据,您必须提供另一个Raster *对象,而不仅仅是crs。

如果提供crs,则会计算一个新范围,该范围要比避免丢失数据所需的范围大一点。当然,在这种奇怪的情况下,crs实际上是相同的,有意义的是返回不变的输入。

© www.soinside.com 2019 - 2024. All rights reserved.