英文:
How to efficiently read part of raster data intersecting with vector data in R?
问题
给定一个大型栅格数据集(ras)(最好是云优化的GeoTIFF)在投影A中,以及一个在投影B中覆盖ras的一小部分的矢量数据集(vec)。在R中,获得与vec相交的栅格数据的高效方式是什么?
一种方法是读取数据,重新投影数据,裁剪数据,然后进行遮罩处理。
ras <- terra::rast(rasterpath)
vec <- sf::st_read(vectorpath)
ras_reproject <- terra::project(ras, terra::crs(vec))
ras_crop <- terra::crop(ras_reproject, vec)
但是重新投影需要很长时间,而且我不想将整个栅格数据集加载到内存中。
是否有包含类似于read_raster(rasterpath, extent=vec)功能的软件包?
英文:
Given a large raster dataset (ras) (ideally Cloud optimized GeoTIFF) in projection A and a vector dataset (vec) in projection B covering a small part of ras. What is an efficient way to get the raster data intersecting with vec in R?
One way would be to read the data, reproject it, crop it, mask it.
ras <- terra::rast(rasterpath)
vec <- sf::st_read(vectorpath)
ras_reproject <- terra::project(ras, terra::crs(vec))
ras_crop <- terra::crop(ras_reproject , vec)
But reprojection takes forever and I do not want to load the entire raster dataset in Memory.
Is there package with a function like read_raster(rasterpath, extent=vec)?
答案1
得分: 1
我不确定这是否在所有情况下都有效,但{{ezwarp}}库和基于gdal构建的{{vapour}}库似乎已经做到了我想要的。
library(ezwarp)
ras_crop <- ezwarp(
x = rasterpath, y = rasterpath, res = 10, cutline = vec,
crop_to_cutline = TRUE, engine = "vapour"
)
英文:
I am not sure if this works out in all situations yet,
but the {{ezwarp}} library and the underlying {{vapour}} library which builds on gdal kind of did what I wanted
library(ezwarp)
ras_crop <- ezwarp(
x = rasterpath, y = rasterpath, res = 10, cutline = vec,
crop_to_cutline = TRUE, engine = "vapour"
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论