[R-sig-eco] terra package SpatVector format
José Hidasi Neto
h|d@@|neto @end|ng |rom gm@||@com
Mon Nov 20 04:39:58 CET 2023
Hello everyone,
I'm trying to update my package "bivariatemaps", but I'm having a problem
with SpatVector and SpatRaster formats from the new terra package.
For example:
GridFilter<-function(shape, resol = 1, prop = 0){
grid <- terra::rast(terra::ext(shape))
terra::res(grid) <- resol
*sp::proj4string(grid)*<-*sp::proj4string(shape)*
gridpolygon <- terra::rasterToPolygons(grid)
drylandproj<-sp::spTransform(shape, sp::CRS("+proj=laea"))
gridpolproj<-sp::spTransform(gridpolygon, sp::CRS("+proj=laea"))
gridpolproj$layer <- c(1:length(gridpolproj$layer))
areagrid <- terra::expanse(gridpolproj, byid=T)
dry.grid <- terra::intersect(drylandproj, gridpolproj)
areadrygrid <- terra::expanse(dry.grid, byid=T)
info <- cbind(dry.grid$layer, areagrid[dry.grid$layer], areadrygrid)
dry.grid$layer<-info[,3]/info[,2]
dry.grid <- sp::spTransform(dry.grid, sp::CRS(sp::proj4string(shape)))
dry.grid.filtered <- dry.grid[dry.grid$layer >= prop,]}
When it tries to use pro4string on the grid and the shape, it doesn't work.
sp::proj4string(grid)Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘proj4string’ for
signature ‘"SpatRaster"’
sp::proj4string(shape)Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘proj4string’ for
signature ‘"SpatVector"’
Is there any function that works with these new formats?
All the best,
José Hidasi-Neto
--
José Hidasi Neto
Ph.D. in Ecology and Evolution
Lattes:
http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K4293841A0
My blog about science and R: https://rfunctions.blogspot.com
[[alternative HTML version deleted]]
More information about the R-sig-ecology
mailing list