Skip to content

cannot write sf dataframe geometry column to MariaDB table #297

@frabau1

Description

@frabau1

I am trying to use MariaDB to store GIS data queried from Open Street Map using R, however the MariaDB driver is failing to write the geometry column from R to MariaDB. I get this error: "Error: Cannot get geometry object from data you send to the GEOMETRY field [1416]".

Geodatabase support in MariaDB .

I have tried other sf data frames obtained from other sources (imported shapefiles, files from the tigris package, etc.) and get the same error.

library(osmdata)
library(sf)
library(dplyr)
library(RMariaDB)

#OSM overpass query
q1 <- opq(bbox = c(-78.895569,38.236023,-75.050354,39.584524)) %>% 
  add_osm_feature(key = 'highway', value = c('path','footway')) %>%
  add_osm_feature(key = 'surface', value = c('dirt','unpaved','ground','rock', 'compacted')) %>%
  add_osm_feature(key = 'bicycle', value = c('designated','yes','permissive')) 

#fetch sf results
q1 <- q1 %>% 
  osmdata_sf()

#pull out lines
q1_lines <- q1$osm_lines

#pull out polygons - closed loop trails erroniously show as polygons
q1_poly <- q1$osm_polygons

#convert polygons to linestrings
q1_converted <- st_cast(q1_poly,"LINESTRING")

#recombine
q1 <- bind_rows(q1_lines, q1_converted)

#drop redundant column 
q1 <- q1 %>% 
  select(-fixme)

con <- dbConnect(
  drv = RMariaDB::MariaDB(), 
  dbname='dbname',
  username = 'user',
  password = 'pass', 
  host = 'ipaddress', 
  port = portnum
)

q2 <- st_as_sf(q1)

dbWriteTable(con, name="mtb_trails", q1_lines)


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions