我有两个栅格和一个形状文件,均具有 100m 分辨率的网格,但范围不同。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/ 中的函数计算每个范围的上下范围之间的距离(以米为单位),认为增量为100m 表示它们之间的增量距离为 100m,但情况似乎并非如此。
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句