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

When the raster package was still active, I would usually have to do the following to crop the rasterla

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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745587690a4634642.html

相关推荐

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

    When the raster package was still active, I would usually have to do the following to crop the rasterla

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信