最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

geospatial - Mask and Crop functions in Terra R - Stack Overflow

programmeradmin1浏览0评论

When the raster package was still active, I would usually have to do the following to crop the rasterlayer to an irregular polygon (with some functions updated for terra). I am wondering there is a faster/more efficient way to do this same thing?:

kml <- vect("pathtokml.kml")
r <- rast("pathtoraster.tif")

crp <- mask(r, project(kml, r)) #fix for different CRS's
crp2 <- crop(crp, ext(kml))
plot(crp2)

When the raster package was still active, I would usually have to do the following to crop the rasterlayer to an irregular polygon (with some functions updated for terra). I am wondering there is a faster/more efficient way to do this same thing?:

kml <- vect("pathtokml.kml")
r <- rast("pathtoraster.tif")

crp <- mask(r, project(kml, r)) #fix for different CRS's
crp2 <- crop(crp, ext(kml))
plot(crp2)
Share Improve this question asked Nov 19, 2024 at 4:07 AndrewAndrew 1712 silver badges6 bronze badges 1
  • 1 For some performance gain try cropping first and and then mask. Or jus set mask = TRUE in crop() - stackoverflow/questions/77998525/… – margusl Commented Nov 19, 2024 at 8:02
Add a comment  | 

1 Answer 1

Reset to default 2

It is more efficient to first crop and then mask, and with terra you can do this in one step.

x <- crop(r, project(kml, r), mask=TRUE)
发布评论

评论列表(0)

  1. 暂无评论