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 Answer
Reset to default 2It 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
mask = TRUE
incrop()
- stackoverflow/questions/77998525/… – margusl Commented Nov 19, 2024 at 8:02