I am trying to write geodata to a Microsoft SQLServer 2017 using rgdal.
dsn = 'MSSQL:server=XXX;database=XXX;trusted_connection=yes' data=data.frame(lat=c(52.52437), lon=c(13.41053), value=c("v")) colnames(data) <- c("lat", "lon", "value") data_coords = data coordinates(data_coords) <- ~ lat + lon data_sp = SpatialPointsDataFrame(data_coords, data) writeOGR(data_sp, dsn=dsn, driver="MSSQLSpatial", layer="NewMSSQLSpatialTableName", layer_options=c("SRID=28355"), verbose=TRUE)
However, this code fails with:
> writeOGR(data_sp, dsn=dsn, driver="MSSQLSpatial", layer="NewMSSQLSpatialTableName", layer_options=c("SRID=28355"), verbose=TRUE) Object initially classed as: wkbPoint Error in writeOGR(data_sp, dsn = dsn, driver = "MSSQLSpatial", layer = "NewMSSQLSpatialTableName", : Layer creation failed
I have permissions to create tables in the database. Am I missing additional permissions or did I do something else wrong?
> library(rgdal) rgdal: version: 1.2-16, (SVN revision 701) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.2.0, released 2017/04/28 Path to GDAL shared files: C:/Users/User/Software/R/R-3.4.3/library/rgdal/gdal GDAL binary built with GEOS: TRUE Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493] Path to PROJ.4 shared files: C:/Users/User/Software/R/R-3.4.3/library/rgdal/proj Linking to sp version: 1.2-7