-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess-geochem-mineralogy.R
58 lines (37 loc) · 1.5 KB
/
process-geochem-mineralogy.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## 2020-03-12: first version, using latest LDM snapshot
## TODO: check prep codes
## TODO: split into sub-tables
## geochemical data
q.geochem <- "SELECT DISTINCT *
FROM geochemical
ORDER BY labsampnum;"
## optical / glass
q.optical <- "SELECT DISTINCT *
FROM glass
ORDER BY labsampnum;"
## XRD / thermal
q.xrd <- "SELECT DISTINCT *
FROM xray_thermal
ORDER BY labsampnum;"
# setup connection to SQLite DB from FGDB export
db <- dbConnect(RSQLite::SQLite(), "E:/NASIS-KSSL-LDM/LDM/LDM-compact.sqlite")
# reformat raw data and return as DF
geochem <- dbGetQuery(db, q.geochem)
optical <- dbGetQuery(db, q.optical)
xrd <- dbGetQuery(db, q.xrd)
dbDisconnect(db)
## save to CSV files for upload to soilweb
write.csv(geochem, file=gzfile('export/geochem.csv.gz'), row.names=FALSE)
write.csv(optical, file=gzfile('export/optical.csv.gz'), row.names=FALSE)
write.csv(xrd, file=gzfile('export/xrd.csv.gz'), row.names=FALSE)
## approximate table defs, re-run if tables have changed
## manual intervention required:
# semi-colon
# new-lines
# data types
# cat(postgresqlBuildTableDefinition(PostgreSQL(), name='kssl.geochem', obj=geochem[1, ], row.names=FALSE), file='table-defs/geochem-tables.sql')
#
# cat(postgresqlBuildTableDefinition(PostgreSQL(), name='kssl.optical', obj=optical[1, ], row.names=FALSE), file='table-defs/geochem-tables.sql', append = TRUE)
#
# cat(postgresqlBuildTableDefinition(PostgreSQL(), name='kssl.xrd_thermal', obj=xrd[1, ], row.names=FALSE), file='table-defs/geochem-tables.sql', append = TRUE)
#