I am currently running RStudio Connect on Ubuntu 16.04 and am using the professional odbc drivers provided by RStudio. These have worked great for me when connecting to both PostgreSQL and MSSQL Server databases. However, these drivers seem to be causing an issue when it comes to reading in spatial data using gdal
via the sf
R package. To be clear, the issue is not with the sf
package (as discussed here), as the same errors are seen in the command line using ogrinfo
. Rather the issue appears to be with the driver. A reprex
is hard given that the data is in a MSSQL Server database, but hopefully the below will illustrate the issue.
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
# define drivers
driver_rstudio <- "SQL Server"
driver_microsoft <- "ODBC Driver 17 for SQL Server"
# define dsn values for sf
dsn_rstudio <- glue::glue("MSSQL:server=xxx;database=xxx;UID={Sys.getenv('uid')};PWD={Sys.getenv('pwd')};Driver={driver_rstudio}")
dsn_microsoft <- glue::glue("MSSQL:server=xxx;database=xxx;UID={Sys.getenv('uid')};PWD={Sys.getenv('pwd')};Driver={driver_microsoft}")
# Try reading in layer with RStudio's driver - FAILS
st_read(dsn_rstudio, "dbo.SampleSites")
#> Reading layer `dbo.SampleSites' from data source `MSSQL:server=xxx;database=xxx;UID=xxx;PWD=xxx;Driver=SQL Server' using driver `MSSQLSpatial'
#> Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
#> NULL error in sfc_from_ogr
#> In addition: Warning message:
#> 2: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
#> GDAL Error 1: [00000](0)
# Try reading in layer with Microsoft Driver - SUCCESS
st_read(dsn_microsoft, "dbo.SampleSites")
#> Reading layer `dbo.SampleSites' from data source `MSSQL:server=xxx;database=xxx;UID=xxx;PWD=xxx;Driver=ODBC Driver 17 for SQL Server' using driver `MSSQLSpatial'
#> Simple feature collection with 92 features and 67 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: 2669698 ymin: 207794.9 xmax: 2742221 ymax: 297992
#> epsg (SRID): NA
#> proj4string: NA
This problem persists to all spatial layers. The driver is able to identify that there are spatial tables but when the spatial elements are actually queried, the driver fails. The same results are seen both with sf
and the cmd line tool ogrinfo
.
I am not sure where is the best place to post issues regarding the RStudio Drivers, but if there is a github page taht is more appropriate, I can redirect this there.
Thanks