确定两个网格在 R 中是否完全匹配

Determine if two grids match exactly in R

我有两个栅格文件和一个形状文件,都具有 100 米分辨率的网格,但范围不同。 shapefile 的范围略小。我想确保它们完全对齐,以便在未来的分析中我的计算对于每个网格单元都是正确的。

光栅 1

day class : RasterLayer dimensions : 2367, 2909, 6885603 (nrow, ncol, ncell) resolution : 0.0008333333, 0.0008333333 (x, y) extent : -123.6325, -121.2083, 36.8925, 38.865 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 names : DAY_BA values : 0, 14917 (min, max)

光栅 2

night class : RasterLayer dimensions : 2365, 2909, 6879785 (nrow, ncol, ncell) resolution : 0.0008333333, 0.0008333333 (x, y) extent : -123.6325, -121.2083, 36.89417, 38.865 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 names : NIGHT_BA values : 0, 1744 (min, max)

形状文件

mgrs class : SpatialPolygonsDataFrame features : 1186800 extent : -122.6511, -121.594, 37.10124, 38.27151 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 variables : 12

文件很大,加载它们并绘制它们以进行视觉比较没有产生任何有趣的结果。

我尝试使用 https://eurekastatistics.com/calculating-a-distance-matrix-for-geographic-points-using-r/ 中的函数计算每个上下范围之间的距离(以米为单位),认为 100 米的增量表示它们彼此之间的增量距离为 100 米,但是这似乎并非如此。

distance.100m <- GeoDistanceInMetresMatrix(df.lims)/100 distance.100m DayMin DayMax NightMin NightMax MSMin MSMax DayMin 0.000000 3056.1968 1.906129 3056.1968 903.7839357 2363.0676716 DayMax 3056.196849 0.0000 3054.546060 0.0000 2332.1390496 739.6121652 NightMin 1.906129 3054.5461 0.000000 3054.5461 902.8710503 2361.5160232 NightMax 3056.196849 0.0000 3054.546060 0.0000 2332.1390496 739.6121652 MSMin 903.783936 2332.1390 902.871050 2332.1390 0.0000000 1598.8812655 MSMax 2363.067672 739.6122 2361.516023 739.6122 1598.8812655 0.0000000

关于如何比较像素排列的任何想法?我想尽可能保留原始值而不是重新采样。

鉴于除一个(ymin)外所有范围坐标都相同,并且分辨率相同,它们应该排成一行。

我们可以先看extents

d <- raster(nrow=2367, ncol=2909, ext=extent(c(-123.6325, -121.2083, 36.8925, 38.865)))
n <- raster(nrow=2365, ncol=2909, ext=extent(c(-123.6325, -121.2083, 36.89417, 38.865)))  
e <- extent(c(-122.6511, -121.594, 37.10124, 38.27151))

plot(extent(d), col='green', lwd=2)
plot(extent(n), add=TRUE, col="red")
plot(e, add=TRUE, col="blue")

很明显,栅格是相似的,多边形在栅格范围内。

我们可以检查光栅的原点,看看它们是否对齐:

origin(n)
#[1] 3.331042e-05 6.573362e-05
origin(d)
#[1]  3.331042e-05 -7.105427e-14

不完全是,但这可能是因为四舍五入。如果我们这样做

res(n) <- 1/1200
res(d) <- 1/1200

为了(可能)得到你真正(应该)拥有的东西:

origin(n)
[1] -9.947598e-14  4.263256e-14
origin(d)
[1] -9.947598e-14 -7.105427e-14

由于d的范围较大,您可以将其裁剪为n,以便排列

d <- crop(d, n)