I am using the DBI
package to connect to a SQL Server database and I am able to pull data from the table into R where the geom
column is a geometry
type according to SQL Server Management Studio.
But when the table is pulled into R, the geom
column is shown as blob
. This is how I am pulling the data into R:
data <- dbGetQuery(con,'SELECT * FROM "map_db"."city"."landcover"')
I would like to convert the blobs back to geometry
(they are x,y coordinates in UTM). I don’t really need the coordinates per say but need to calculate areas for each polygon in R.
I tried the following thinking I could compute the area using SQL but it returned an error:
dbGetQuery(con,'SELECT * FROM "map_db"."city"."landcover".STArea();')
[Microsoft][ODBC SQL Server Driver][SQL Server]Remote table-valued function calls are not allowed.
I even tried st_as_sf
but that gave me the following error:
data <- st_as_sf(dbGetQuery(con,'SELECT * FROM "map_db"."city"."landcover"'))
Error in st_sf(x, …, agr = agr, sf_column_name = sf_column_name):
no simple features geometry column present
Unfortunately, I am not able to provide access to the database so I understand this may make it harder to help my exact case but any suggestions would be welcomed.
1