I wrote a script in R for converting MS Access .mdb files to SQLite.
It is using the Hmisc library for reading and RSqlite package for writing to a .sqlite file, which performs well in QGIS under Linux.
library(Hmisc) #for "mdb.get"
library(RSQLite) # for export to sqlite
library(tidyverse) # for "mutate_if"
# Path to .mdb:
mdb_path <-"/xxx/xxx/xxx/xxx/xxx/xxx/xyz.mdb" # <- Adjust path to file here
# create variables for path, filename etc. for export
dest_path <- dirname(mdb_path) #dirname from base; Change, if result should go to another directory than the source
dest_name <- tools::file_path_sans_ext(basename(mdb_path)) # file name without extension. Change if result name should be different
## load mdb
# create list of mdb-tables
lst.MDB <- list()
# populate list with data frames from mdb-tables
lst.MDB <- mdb.get(mdb_path,allow="_") # allow="_" preventing transformation from underscore to point
# transform factors to character with mutate_if
lst.MDB <- lapply(lst.MDB ,function(x) mutate_if(x,is.factor, as.character))
# create list of table names from the list of data frames
lst.MDB.names <- as.list(names(lst.MDB))
#create connection to new sqlite database
db = dbConnect(SQLite(), dbname= paste(dest_path,paste(dest_name, ".sqlite",sep=""),sep="/"))
# loop over table names
for(i in lst.MDB.names){
dbWriteTable( #from RSqlite : https://rdrr.io/cran/RSQLite/man/dbWriteTable.html
db, # connection
i, # table name
lst.MDB[[i]], # data frame form list of data frames
field.types = NULL,
overwrite = TRUE,
append = FALSE,
header = TRUE,
colClasses = NA,
row.names = FALSE,
nrows = 50,
sep = ",",
eol = "\n",
skip = 0,
temporary = FALSE
)
}
#UPDATE: alternatively writing to GeoPackage using library sf
#write data tables to gpkg: https://gis.stackexchange.com/a/388760/8202
library(sf)
for(i in lst.MDB.names){
st_write(lst.MDB[[i]],
paste(dest_path,paste(dest_name, ".gpkg",sep=""),sep="/"),
layer = i)
}
#Done
apt install mdbtools
). List tables withmdb-tables
, dump table(s) schema to sqlite or postgresql withmdb-schema
and usemdb-export
to export content tables to SQL statements. Add some glue and done. PS: fine for non geospatial but OGR/GDAL better way if geospatial content. See gist.github.com/mywarr/9908044 or gist.github.com/kazlauskis/1d0bdb9efb3b1bb1e76d48aa368f3a64