附加大 spatRaster 对象的范围以匹配 spatVector 的范围:计算区域统计数据并摆脱“范围不重叠错误?" [英] Append extent of big spatRaster object to match the extent of spatVector: to compute zonal stats and to get rid of 'extents do not overlap error?'

查看:56
本文介绍了附加大 spatRaster 对象的范围以匹配 spatVector 的范围:计算区域统计数据并摆脱“范围不重叠错误?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我专门研究 terra 包.

spatRaster 详细信息: 南美洲的碳通量数据(~500 GB)

spatRaster details: Carbon flux data of South America (~500 GB)

spatVector 详细信息: 南美洲保护区数据库 (~70 MB)

spatVector details: Protected Areas database of South America (~70 MB)

目标:计算区域统计数据

错误:在执行区域统计操作时,范围不重叠.

Error: While performing zonal statistics operation, the extents do not overlap.

可能的错误原因:光栅文件只有陆地范围.然而,多边形延伸到海洋区域,因此具有陆地、海洋和陆地-海洋组合范围.

Possible reason for error: Raster files have only the terrestrial extent. Polygons, however, extend up to marine regions, thus have terrestrial, marine, and terrestrial-marine combined extents.

问题: 是否可以将光栅文件扩展到多边形的范围而不会丢失如此大文件的任何值?有没有什么有效的方法可以解决这类问题?

Question: Is it possible to extend the raster file up to the extent of Polygon without losing any values for this much large file? Is there any efficient way to solve this kind of problem?

PS:我是新来的,如果有人发现已经回答了类似的问题,请帮助我.很抱歉,我无法为这个问题制作一个可重现的示例.

PS: I am new here, and if anyone finds out that the similar question is answered already, please help me out. I am sorry that I couldn’t make a reproducible example for this problem.

推荐答案

没有SpatRaster,SpatVector"区域的方法,所以你的问题没有答案.我假设您首先使用光栅化并在那里犯了错误.对于所有 R 问题,您应该包含一个最小的、独立的可重现示例,如下所示,表明无需做您认为需要做的事情

There is no "'SpatRaster,SpatVector" method for zonal, so your question has no answer. I assume you use rasterize first and make a mistake there. As for all R questions, you should have included a minimal, self-contained reproducible example, like the below that suggests that there is no need to do what you think you need to do

library(terra)
#terra version 1.1.16
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)

# remove part of raster, such that polygons have larger extent 
r <- crop(r, v[1:5])

z <- rasterize(v, r, "NAME_1")    
zonal(r, z, mean, na.rm=TRUE)

#        NAME_1 elevation
#1     Diekirch  403.4237
#2 Grevenmacher  329.4595
#3   Luxembourg  315.2139

这篇关于附加大 spatRaster 对象的范围以匹配 spatVector 的范围:计算区域统计数据并摆脱“范围不重叠错误?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆