terra package SpatVector format
Hi, I think terra::crs() does what you are looking for. More broadly, I think your workflow would be more efficient and simpler if you take the time now to switch over to terra functions like terra::project(), rather than retain so many sp functions. There's excellent documentation available here: https://rspatial.org/ Sarah
On Sun, Nov 19, 2023 at 11:39?PM Jos? Hidasi Neto <hidasineto at gmail.com> wrote:
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]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Sarah Goslee (she/her) http://www.numberwright.com