DOI-USGS / hyRefactor

https://code.usgs.gov/wma/nhgf/reference-fabric/hyrefactor
Creative Commons Zero v1.0 Universal
5 stars 0 forks source link

new_hope_events not loaded with new_hope_data.R #6

Closed seanhardison1 closed 4 years ago

seanhardison1 commented 4 years ago

Just wanted to let you know that the vignette example for split_flowlines does not load the new_hope_events data frame, so the example doesn't run.

thanks!

Sean

dblodgett-usgs commented 4 years ago

Should be loading here: https://github.com/dblodgett-usgs/hyRefactor/blob/master/inst/extdata/new_hope_data.R#L16 Do you maybe need to install the latest build from github?

seanhardison1 commented 4 years ago

Right, my fault! It looks like there's something going wrong on my end during the import

Overwritten PROJ_LIB was /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Error: Cannot open "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/hyRefactor/extdata/new_hope_reconcile.gpkg"; The source could be corrupt or not supported. See `st_drivers()` for a list of supported formats.
In addition: Warning message:
In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Error 1: unable to open database file: this file is a WAL-enabled database. It cannot be opened because it is presumably read-only or in a read-only directory.
dblodgett-usgs commented 4 years ago

Interesting. It looks like the way I load the test data won't work if your user can't write to the location the data is loaded?

Can you try installing the latest github build and let me know if it is better?

This should have fixed it: https://github.com/dblodgett-usgs/hyRefactor/commit/636512b06ac33a72a83f3ff8cadc27b7fda04b74

seanhardison1 commented 4 years ago

Still getting the same error 🤷‍♂️ . I also tried after a fresh install of sf with no luck

dblodgett-usgs commented 4 years ago

Can you try running what's in this file directly? https://github.com/dblodgett-usgs/hyRefactor/blob/master/inst/extdata/new_hope_data.R

If that works, then we need to make sure that what is installed and getting sourced correctly.

Then we need to make sure that the contents of this directory:

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/hyRefactor/extdata/

Contain all the required files and is getting updated when you reinstall.

seanhardison1 commented 4 years ago

Running that script successfully loads the new_hope_events data.frame. However, I'm still getting an error:

> new_hope_catchment <- sf::read_sf(nhpgpkg, "CatchmentSP")
> new_hope_catchment <- sf::st_transform(new_hope_catchment, proj)
> new_hope_flowline <- sf::read_sf(nhpgpkg, "NHDFlowline_Network")
> new_hope_flowline <- sf::st_transform(new_hope_flowline, proj)
> new_hope_fline_ref <- sf::read_sf(nhpgpkgref)
> new_hope_fline_rec <- sf::read_sf(nhpgpkgrec)
Error: Cannot open "/private/var/folders/3_/8vnl60ds0kvbhwrvf9b17ff00000gn/T/RtmpXBQCXu/fileb2a963dde817.gpkg"; The source could be corrupt or not supported. See `st_drivers()` for a list of supported formats.
In addition: Warning message:
In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Error 1: unable to open database file: this file is a WAL-enabled database. It cannot be opened because it is presumably read-only or in a read-only directory.
> new_hope_catchment_rec <- sf::read_sf(nhpgpkgreccat)
> new_hope_events <- sf::read_sf(nhpgpkgev)

I think the error loading new_hope_fline_rec causes source(system.file("extdata", "new_hope_data.R", package = "hyRefactor")) to break before it can get to new_hope_catchment_rec or new_hope_events

dblodgett-usgs commented 4 years ago

Interesting. There must be something wrong with new_hope_reconcile.gpkg

Can you grab it out of your install and see if it's corrupt?

Here's the one from my source directory. Does this work on your machine? new_hope_reconcile.gpkg.zip

seanhardison1 commented 4 years ago

No, I'm unable to read either file into R using sf or rgdal.

I'm not familiar with SQL so I don't know what the next steps would be, but I found an approach that seems to handle the file without breaking. At least it appears to show the contents of the file:

library(RSQLite)
extdata <- system.file("extdata", package = "hyRefactor")
con <- dbConnect(RSQLite::SQLite(), dbname = file.path(extdata, "new_hope_reconcile.gpkg"))
dbListTables(con)

source

dblodgett-usgs commented 4 years ago

My theory is that this is actually related to projection. I just pulled that down and checked -- it is using some really strange projection. No idea why.

new_hope_reconcile.gpkg.zip

This work any better?

seanhardison1 commented 4 years ago

That solved it! Nicely done.

dblodgett-usgs commented 4 years ago

Great. Updated files are now checked in too.