如何使用R中的Terra软件包重新采样重叠的横梁?

发布于 2025-01-19 03:39:35 字数 211 浏览 3 评论 0原文

我有三个部分重叠的 DEM 栅格,它们具有不同的原点、分辨率(仅略有不同)和范围。我知道由于来源不同等原因,我需要使用 terra 的重新采样函数而不是合并或聚合,但我不确定如何启动一个空栅格以用于具有适当来源、分辨率和范围的重新采样,或者如何处理重叠区域。

是否有推荐的方法来选择现有栅格的原点和分辨率(例如中值与最小/最大值)?如何最好地处理重叠数据?有没有一种有效的方法来生成这样的栅格?

I have three partially overlapping DEM rasters with different origins, resolutions (only slightly different) and extents. I know I need to use terra's resample function rather than merge or aggregate because of the different origins, etc., but I'm not sure how to initiate an empty raster to use for resampling that has an appropriate origin, resolution and extent, or what to do about overlapping areas.

Are there recommended approaches for selecting which origin and resolution to use of the existing rasters (e.g. median vs min/max values)? How are overlapping data best handled? Is there an efficient way to generate such a raster?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2025-01-26 03:39:35

这是显示 的方式。

示例数据

library(terra)
x <- rast(xmin=0, xmax=10, ymin=0, ymax=10, res=1, vals=1)
y <- rast(xmin=9, xmax=19, ymin=0, ymax=10, res=0.9, vals=2)
z <- rast(xmin=0, xmax=10, ymin=8.1, ymax=18.1, res=1, vals=3)

您可能需要将输入栅格之一用作模板。假设您喜欢y。在这种情况下:

a <- list(x, z)
b <- lapply(a, \(i) {
     x <- extend(rast(y), i)
     resample(i, crop(x, i, "out"))
   })

b <- sprc(c(b, y))
m <- merge(b)
 

或创建一个新的模板栅格。在这种情况下,首先找到合并的范围

a <- list(x, y, z)
b <- sapply(a, \(i) ext(i) |> as.vector())
e <- ext(min(b[1,]), max(b[2,]), min(b[3,]), max(b[4,]))

# use the extent to create a raster with the desired spatial resolution 
r <- rast(e, res=1)

,现在如上所述:

gg <- lapply(a, \(i) resample(i, crop(r, i, "out")))
g <- merge(sprc(gg))

或者像这样,

src <- sprc(a)
ss <- impose(src, r)
s <- max(ss, na.rm=TRUE)

我想其中一些可以包裹在Terra方法中。

另请参见Mosaic作为Merge的替代方案。

至于选择最佳分辨率等,这取决于您的需求以及您的数据可能合理地支持的内容。但是,一个重要的一般考虑是,您要避免尽可能多地重新采样 - 因为它会恶化数据质量。

Here are ways that show how you might do that.

Example data

library(terra)
x <- rast(xmin=0, xmax=10, ymin=0, ymax=10, res=1, vals=1)
y <- rast(xmin=9, xmax=19, ymin=0, ymax=10, res=0.9, vals=2)
z <- rast(xmin=0, xmax=10, ymin=8.1, ymax=18.1, res=1, vals=3)

You may want to use one of the input rasters as template. Let's say you like y. In that case:

a <- list(x, z)
b <- lapply(a, \(i) {
     x <- extend(rast(y), i)
     resample(i, crop(x, i, "out"))
   })

b <- sprc(c(b, y))
m <- merge(b)
 

Or create a new template raster. In that case, first find out the combined extent

a <- list(x, y, z)
b <- sapply(a, \(i) ext(i) |> as.vector())
e <- ext(min(b[1,]), max(b[2,]), min(b[3,]), max(b[4,]))

# use the extent to create a raster with the desired spatial resolution 
r <- rast(e, res=1)

And now as above:

gg <- lapply(a, \(i) resample(i, crop(r, i, "out")))
g <- merge(sprc(gg))

Or like this

src <- sprc(a)
ss <- impose(src, r)
s <- max(ss, na.rm=TRUE)

I suppose some of this could be wrapped into a terra method.

Also see mosaic as an alternative to merge.

As for choosing the best resolution etc., there it is up to your needs and what your data might reasonably support. But one important general consideration is that you want to avoid resampling as much as possible --- as it deteriorates the data quality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文