我有两个光栅和一个形状文件,都有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)
Shapefile
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
有没有办法比较像素排成一行的情况?如果可能,我希望保留原始值,而不是重新采样。
发布于 2019-03-15 23:30:22
假设除了一个(ymin)之外,所有的范围坐标都是相同的,并且分辨率是相同的,它们应该对齐。
我们可以先看一下扩展区
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)https://stackoverflow.com/questions/55182508
复制相似问题