Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't write GDBs using OpenFileGDB driver #2134

Closed
phildias opened this issue Mar 27, 2023 · 16 comments
Closed

Can't write GDBs using OpenFileGDB driver #2134

phildias opened this issue Mar 27, 2023 · 16 comments

Comments

@phildias
Copy link

phildias commented Mar 27, 2023

Around mid 2022, the GDAL library was updated and the OpenFileGDB was enhanced to include the capacity to write GDBs (see here).

I think some other changes need to be made to sf to allow its users to access those capabilities. Right now, when I try to wright a GDB using sf, i get an error:

library(tidyverse)
library(sf)

my_df = data.frame(col1=c(1,2,3),
                   lon=c(0,1,2),
                   lat=c(0,1,2)) %>%
  st_as_sf(coords = c("lon", "lat"), 
           crs = 4326, 
           agr = "constant")

my_df %>% 
  st_write(dsn='c:/temp/my_test.gdb', 
           layer="x1", 
           driver="OpenFileGDB",
           append=FALSE)

The st_write command above yields the following error message:

Creating dataset c:/temp/my_test.gdb failed.
Error: Creation failed.
In addition: Warning message:
In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 6: GDALDriver::Create() ... no create method implemented for this format.

Is there any way I can bypass this? Thanks!

@rsbivand
Copy link
Member

Please look at sf::sf_extSoftVersion(). Is the version of GDAL later than the announcement you refer to? It is most likely that your package was built against an earlier GDAL.

@phildias
Copy link
Author

Yep, you're right. sf::sf_extSoftVersion() shows me that the version of GDAL that R "sees" is 3.5.2, and it seems that the new OpenFileGDB capabilities were made available in version 3.6.0 (see here ).

The installation of OSGeo and GDAL were done automatically when I just ran install.packaged("sf"). Is there a way to update the version of GDAL that R is "seeing"?

@rsbivand
Copy link
Member

Which platform/operating system, and how did you install sf?

@phildias
Copy link
Author

I'm currently working on a PC with Windows 10. I installed sf by typing install.packaged("sf") in the R console in RStudio.

@rsbivand
Copy link
Member

Which version of sf? If not the latest, update, the GDAL version may be newer. Or upgrade to R 4.3 devel - to be released 21 April anyway; the Rtools43 build of sf should have a newer GDAL,

@phildias
Copy link
Author

phildias commented Mar 27, 2023

The version of sf is 1.0.12 and the version of R I'm using is 4.2.3.

@rsbivand
Copy link
Member

I can check R 4.3 for Windows 10 tomorrow, Rtools42 have the GDAL version you already have.

@JoshOBrien
Copy link
Contributor

JoshOBrien commented Mar 27, 2023

I'm running the R-4.3.0 alpha build (available at https://cran.r-project.org/bin/windows/base/rtest.html), and can confirm that as long as you're running the 4.3.0 build of sf, your reproducible example runs without any problem.

Don't forget, after installing R-4.3.0, that you'll need to do this or something equivalent to get the newer build:

remove.packages("sf")
install.packages("sf")

ETA, here are the versions of the external geospatial software being used:

library(sf)
sf::sf_extSoftVersion()
##           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
##       "3.11.1"        "3.6.2"        "9.1.1"         "true"         "true" 
##           PROJ 
##        "9.1.1"

@rsbivand
Copy link
Member

On Windows, the user library is usually versioned, so that 4.2 and 4.3 can co-exist. So in 4.3, remove.package() will not see the 4.2 package.

@rsbivand
Copy link
Member

For me, Windows 10, R 4.3-devel (mid-March):

> library(sf)
Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
> st_drivers()["OpenFileGDB",]
                   name    long_name write  copy is_raster is_vector  vsi
OpenFileGDB OpenFileGDB ESRI FileGDB  TRUE FALSE     FALSE      TRUE TRUE

reporting write TRUE.

> st_write(st_read(system.file("gpkg/nc.gpkg", package="sf")), tf)
Reading layer `nc.gpkg' from data source 
  `C:\Users\RB\AppData\Local\R\win-library\4.3\sf\gpkg\nc.gpkg' 
  using driver `GPKG'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27
Writing layer `file16dc28de7042' to data source 
  `C:\Users\RB\AppData\Local\Temp\RtmpAHDeNO\file16dc28de7042.gdb' using driver `OpenFileGDB'
Writing 100 features with 14 fields and geometry type Multi Polygon.
> st_read(tf)
Reading layer `file16dc28de7042' from data source 
  `C:\Users\RB\AppData\Local\Temp\RtmpAHDeNO\file16dc28de7042.gdb' using driver `OpenFileGDB'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27

@edzer
Copy link
Member

edzer commented Mar 28, 2023

Thanks!

@edzer edzer closed this as completed Mar 28, 2023
@phildias
Copy link
Author

Awesome, thanks for all the info! =)

@JosiahParry
Copy link
Contributor

Hi all, I want to set a minimum version of {sf} to be based on when the OpenFileGDB driver was available. Is my reading here it requires a minimum version of R to be R >= v4.3.0 and sf >= v1.0-13—this is guessed based on the first release following the closing of this issue from https://cran.r-project.org/src/contrib/Archive/sf/

@rsbivand
Copy link
Member

I think it is only controlled by the GDAL version. From https://gdal.org/en/latest/drivers/vector/openfilegdb.html, GDAL 3.6 is needed for writing fgdb. For CRAN binaries, Windows is now at 3.9.3 I think, but macOS is on 3.5. A small example file to test, say in a github actions run, might make sense.

@JosiahParry
Copy link
Contributor

@rsbivand I think there is an sf version requirement due to this line here:

sf/R/read.R

Line 777 in 7dd4173

"gdb" = "OpenFileGDB",

IIUC, sf checks the extension and maps it to the driver

@rsbivand
Copy link
Member

For writing both vectors and rasters, using the driver argument controls. For reading, the detection of the needed driver should be done by GDAL. The extension map is very likely superfluous, never needed in rgdal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants