[R-sig-Geo] rgdal and MSSQL Server geometries

Shannon E. Albeke salbeke at uwyo.edu
Wed Apr 3 04:21:09 CEST 2013


Dear r-geo list, 
I am potentially struggling with some syntax and thought that maybe someone has solved a similar issue. I am trying to use 'rgdal' package and the readOGR function to read in a data table from a MS SQL Server 2012 instance. In the table I have a column of type 'geometry'. In this example the data are simply polygons describing Local Hulls for individual animals. I would like read in the these polygons using readOGR just like I would if I were to read in an ESRI Shapefile. However, when I run the following line of code I get the error for ogrInfo function:

#/////////////////////
poly<- readOGR(dsn='MSSQL:server=CPU\\CPU_SQL2012EXP;database=Deer;uid=myUser;trusted_connection=true', layer='CollarPoly')

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : 
  Cannot open file
#////////////////////

I have looked and it appears that I have the correct ogrDrivers
ogrDrivers()
25   MSSQLSpatial  TRUE

I feel that what I am trying to accomplish is possible, and after searching through quite a few gdal resources, I'm just at a loss and am hoping that someone can let me know of a good/simple solution. I do know that I can connect to the same database using RODBC and obtain the data table, but the returned object is not a SpatialPolygonsDataFrame nor has the spatial information readily available (i.e. the shape and coordinate system). I greatly appreciate your time and assistance.

Cheers,
Shannon

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] PBSmapping_2.65.40 maptools_0.8-21    lattice_0.20-10   
 [4] foreign_0.8-51     gpclib_1.5-1       adehabitatHR_0.4.4
 [7] adehabitatLT_0.3.7 CircStats_0.2-4    boot_1.3-7        
[10] MASS_7.3-22        adehabitatMA_0.3.4 ade4_1.5-1        
[13] deldir_0.0-21      rgeos_0.2-11       RODBC_1.3-6       
[16] rgdal_0.8-01       raster_2.0-41      sp_1.0-5          

loaded via a namespace (and not attached):
[1] tools_2.15.2



More information about the R-sig-Geo mailing list