James-Thorson-NOAA / FishStatsUtils

Shared resources for spatio-temporal models
GNU General Public License v3.0
10 stars 16 forks source link

Error in convert_shapefile function - no applicable method for `@` applied to an object of class "sf" #92

Closed AndyUEA closed 4 months ago

AndyUEA commented 10 months ago

Hi,

I've been helping a researcher get a script running but getting an error when trying to run the make_extrapolation_info function in v2.13.0

Error in shapefile_input@proj4string : no applicable method for@applied to an object of class "sf"

This seems to be bubbling up from the call to convert_shapefile

> traceback()
12: print(shapefile_input@proj4string)
11: lapply(list(...), as.character)
10: .makeMessage(..., domain = domain, appendLF = appendLF)
9: message("Reading shapefile with projargs: ", print(shapefile_input@proj4string))
8: convert_shapefile(file_path = Region[rI], projargs = projargs,
       grid_dim_km = grid_dim_km, area_tolerance = area_tolerance,
       ...)
7: make_extrapolation_info(Region = "spurdog_celtic_sea_area.shp",
       projargs = NULL, zone = NA, create_strata_per_region = TRUE,
       max_cells = Inf) at spatial_setup.R#6
6: spatial_setup(spurdog_data$lonlat_gz) at run_ATM_spurdog.R#10
5: run_ATM_spurdog(2021, 2021, 2, 7) at run_ATM_spurdog.R#39
4: eval(ei, envir)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("run_ATM_spurdog.R")

It looks similar to the issue reported on the make_mesh function that was updated to to use "sf" https://github.com/James-Thorson-NOAA/VAST/issues/380

This works with the old rgdal method

> shapefile_input = rgdal::readOGR( file_path, verbose=FALSE, p4s=NULL )
> shapefile_input@proj4string
Coordinate Reference System:
Deprecated Proj.4 representation:
 +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1
<...snip...>

But not the sf method

> shapefile_input = sf::st_read( file_path )
<...snip...>
> shapefile_input@proj4string
Error in shapefile_input@proj4string :
  no applicable method for `@` applied to an object of class "sf"

Happy to provide any further details you need.

NicWalker88 commented 4 months ago

I get the same error when using DATRAS products, i.e., "NS-IBTS"

James-Thorson-NOAA commented 4 months ago

can you try this using the dev branch?

remotes::install_devtools( "James-Thorson-NOAA\FishStatsUtils@dev", force=TRUE, dep=FALSE )

library(FishStatsUtils)
region = make_extrapolation_info( Region = "NS_IBTS" )
NicWalker88 commented 4 months ago

Thanks, this seems to be working now.

James-Thorson-NOAA commented 4 months ago

OK, I just merged the dev branches and made new release-numbers for FishStatsUtils and VAST, so this should be all sorted. Please tell me if you find any further issues :)