jmsigner / amt

37 stars 13 forks source link

RSF Workflow #10

Open benscarlson opened 4 years ago

benscarlson commented 4 years ago

Hello,

I'm attempting to use amt in the typical create random points/extract covariates workflow, but I'm running into some problems. I'm not sure if this is the right place to post questions but here goes.

dat <- read_csv('my_data.csv',col_types=cols()) #x,y data for rsf, in lon/lat
rast <- raster('my_layer.tif') #also lon/lat, epsg:4326

The most straightforward approach is to do the following

 dat %>% 
  make_track(lon,lat,crs = CRS('+init=epsg:4326')) %>%
  random_points %>%
  extract_covariates(rast)

This works but this gives me warning messages (below). I assume because random_points uses sf internally, which doesn't work as well with spherical coordinates.

although coordinates are longitude/latitude, st_intersects assumes that they are planar

Converting to a flat projection then seems to require a fairly convoluted workflow to extract covariates. In addition, the random points object needs to be a spatial object in order to transform coordinates, but using maketrack drops the case column.

dat %>% 
  make_track(lon,lat,crs = CRS('+init=epsg:4326')) %>%
  transform_coords(CRS('+init=epsg:3035')) %>%
  random_points %>%
  make_track(x_,y_,crs = CRS('+init=epsg:3035')) %>%
  transform_coords('+init=epsg:4326') %>%
  extract_covariates(rast)

Thank you for the help!

Ben