Search code examples
rspatialterra

Cannot use project function to reproject SpatVector to EPSG:3035


I have a SpatVector containing occurrence records coordinates and a SpatRaster Corine land cover layer and would like to count the number of records in each land cover layer cell. However, before I can do this, I need to reproject the SpatVector to match the projection and extent of the SpatRaster, which is EPSG: 3035.

I've tried using the below code but encounter the error Error: [project] input crs is not valid

#The below SpatVector is just a reproducible snipped of what I am working with
 #in my script I am working with occurrence records downloaded from GBIF
occurrence <- terra::vect(cbind(c(5.73582, 5.673900, 5.770425),
                                c(58.79926, 58.73660, 58.70576))

proj_occ <- terra::project(occurrence, "epsg:3035")

This same line of code worked as intended when I re-projected the country shapefile (downloaded in R using the geodata::gadm() function).

How can I fix this? Thank you!


Solution

  • You need to specify the crs of the input data. For example like this

    library(terra)
    occurrence <- terra::vect(cbind(c(5.73582, 5.673900, 5.770425),
                                    c(58.79926, 58.73660, 58.70576)), 
                                    crs="+proj=longlat")
    
    proj_occ <- terra::project(occurrence, "epsg:3035")