rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
543 stars 90 forks source link

crs argument to rast #1550

Closed sou-github2024 closed 4 months ago

sou-github2024 commented 4 months ago

argument crs= does not operate!

t2 <- rast("test.tif",crs="epsg:4326") 
#Error in .local(x, ...) : unused argument (crs = "epsg:4326") 
crs(t2) 
#Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'crs': object 't2' not found
rhijmans commented 4 months ago

This is expected. The manual shows that the rast method for signature 'character' (filename) does not have an argument "crs"

rast(x, subds=0, lyrs=NULL, drivers=NULL, opts=NULL, 
          win=NULL, snap="near", vsi=FALSE, raw=FALSE)

If it is necessary to change the crs of a SpatRaster you could do

t2 <- rast("test.tif")
crs(t2) <- "epsg:4326"