.Rhistory 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. styler:::style_active_file()
  2. styler:::style_active_file()
  3. library(ruut)
  4. #'
  5. #' INSPIRE grid map
  6. #'
  7. library(dplyr)
  8. library(ruut)
  9. # Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2
  10. # Temp directory
  11. tmp_dir <- tempdir()
  12. # Download link
  13. url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
  14. # Estonia shapefile (ZIP archive)
  15. map_shapefile <- "Estonia_shapefile.zip"
  16. # Download and sav
  17. saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
  18. download.file(
  19. url = download_url,
  20. destfile = saveTo, method = "curl", extra = "-L"
  21. )
  22. # Unzip
  23. unzip(saveTo, overwrite = T, exdir = tmp_dir)
  24. # List of files
  25. ls <- list.files(path = tmp_dir, pattern = ".shp")
  26. ls_long <- list.files(path = tmp_dir, pattern = ".shp", full.names = T)
  27. tbl_names <- strsplit(x = ls, split = ".shp") %>% unlist()
  28. # Export to postgis
  29. schema <- "inspire"
  30. i <- 1
  31. config <- get_config()
  32. config$schema <- schema
  33. # New schema
  34. db_create_new_schema(conf = config)
  35. library(dplyr)
  36. library(ruut)
  37. # Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2
  38. # Temp directory
  39. tmp_dir <- tempdir()
  40. # Download link
  41. url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
  42. # Estonia shapefile (ZIP archive)
  43. map_shapefile <- "Estonia_shapefile.zip"
  44. # Download and sav
  45. saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
  46. download.file(
  47. url = url,
  48. destfile = saveTo, method = "curl", extra = "-L"
  49. )
  50. # Unzip
  51. unzip(saveTo, overwrite = T, exdir = tmp_dir)
  52. # List of files
  53. ls <- list.files(path = tmp_dir, pattern = ".shp")
  54. ls_long <- list.files(path = tmp_dir, pattern = ".shp", full.names = T)
  55. tbl_names <- strsplit(x = ls, split = ".shp") %>% unlist()
  56. # Export to postgis
  57. schema <- "inspire"
  58. i <- 1
  59. config <- get_config()
  60. config$schema <- schema
  61. # New schema
  62. db_create_new_schema(conf = config)
  63. print(tbl_names[i])
  64. config$table <- tbl_names[i]
  65. source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
  66. crs_source <- "-s_srs EPSG:3035"
  67. crs_target <- "-t_srs EPSG:4326"
  68. fid <- "fid"
  69. ruut::copy_shp_to_db(dir = tmp_dir, layer = tbl_names[i], conf = config,
  70. id = fid, crs_source = crs_source, crs_target = crs_target,
  71. geometry_type = 'POLYGON')
  72. dir = tmp_dir; layer = tbl_names[i]; conf = config;
  73. id = fid; crs_source = crs_source; crs_target = crs_target;
  74. geometry_type = 'POLYGON'
  75. length(list.files(path = dir, pattern = sprintf("%s*", layer)))
  76. length(list.files(path = dir, pattern = sprintf("%s*", layer))) > 0
  77. source <- sprintf('"%s" "%s"', dir, layer)
  78. source
  79. cmd <- sprintf(
  80. paste0(
  81. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  82. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  83. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  84. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  85. "%s %s -nlt %s"
  86. ),
  87. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  88. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  89. crs_source, crs_target, geometry_type
  90. )
  91. cmd
  92. system(cmd)
  93. dir = tmp_dir; layer = tbl_names[i]; conf = config;
  94. id = fid; crs_source = crs_source; crs_target = crs_target;
  95. geometry_type = 'PROMOTE_TO_MULTI'
  96. cmd <- sprintf(
  97. paste0(
  98. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  99. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  100. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  101. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  102. "%s %s -nlt %s"
  103. ),
  104. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  105. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  106. crs_source, crs_target, geometry_type
  107. )
  108. cmd
  109. ruut::db_create_new_schema(conf)
  110. system(cmd)
  111. cmd <- sprintf(
  112. paste0(
  113. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  114. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  115. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  116. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  117. "%s %s -nlt PROMOTE_TO_MULTI"
  118. ),
  119. config$dbname, config$host, config$port, config$user, config$password,
  120. config$sslmode, config$schema, source, fid, config$schema, config$table,
  121. crs_source, crs_target
  122. )
  123. cmd
  124. system(cmd)
  125. geometry_type = 'POLYGON'
  126. cmd <- sprintf(
  127. paste0(
  128. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  129. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  130. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  131. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  132. "%s %s -nlt %s"
  133. ),
  134. config$dbname, config$host, config$port, config$user, config$password,
  135. config$sslmode, config$schema, source, fid, config$schema, config$table,
  136. crs_source, crs_target, geometry_type
  137. )
  138. cmd
  139. system(cmd)
  140. system("ogr2ogr --long-usage")
  141. cmd <- sprintf(
  142. paste0(
  143. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  144. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  145. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  146. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  147. "-s_srs%s -t_srs -nlt %s"
  148. ),
  149. config$dbname, config$host, config$port, config$user, config$password,
  150. config$sslmode, config$schema, source, fid, config$schema, config$table,
  151. crs_source, crs_target, geometry_type
  152. )
  153. system(cmd)
  154. cmd <- sprintf(
  155. paste0(
  156. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  157. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  158. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  159. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  160. "%s %s -nlt %s"
  161. ),
  162. config$dbname, config$host, config$port, config$user, config$password,
  163. config$sslmode, config$schema, source, fid, config$schema, config$table,
  164. crs_source, crs_target, geometry_type
  165. )
  166. system(cmd)
  167. crs_target
  168. crs_source
  169. cmd
  170. cmd <- sprintf(
  171. paste0(
  172. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  173. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  174. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  175. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  176. "%s %s -nlt %s"
  177. ),
  178. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  179. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  180. crs_source, crs_target, geometry_type
  181. )
  182. cmd
  183. crs_target
  184. crs_source = "EPSG:4326"
  185. cmd <- sprintf(
  186. paste0(
  187. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  188. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  189. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  190. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  191. "%s %s -nlt %s"
  192. ),
  193. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  194. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  195. crs_source, crs_target, geometry_type
  196. )
  197. source('~/apps/R/packages/ruut/R/copy_shp_to_db.R', echo=TRUE)
  198. cmd
  199. cmd <- sprintf(
  200. paste0(
  201. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  202. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  203. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  204. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  205. "-s_srs %s -t_srs %s -nlt %s"
  206. ),
  207. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  208. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  209. crs_source, crs_target, geometry_type
  210. )
  211. copy_shp_to_db <- function(dir = NULL, layer = NULL, conf = NULL, id = "fid",
  212. crs_source = "EPSG:4326",
  213. crs_target = "EPSG:4326",
  214. geometry_type = "PROMOTE_TO_MULTI") {
  215. # Command 'ogr2ogr' help
  216. # system("ogr2ogr --long-usage")
  217. # Kontrollime kas etteantud kataloogis paiknevad failid
  218. if (length(list.files(path = dir, pattern = sprintf("%s*", layer))) > 0) {
  219. source <- sprintf('"%s" "%s"', dir, layer)
  220. cmd <- sprintf(
  221. paste0(
  222. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  223. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  224. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  225. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  226. "-s_srs %s -t_srs %s -nlt %s"
  227. ),
  228. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  229. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  230. crs_source, crs_target, geometry_type
  231. )
  232. ruut::db_create_new_schema(conf)
  233. Sys.sleep(1)
  234. system(cmd)
  235. } else {
  236. cat("\nEi leitud antud kataloogist faile.")
  237. return(NULL)
  238. }
  239. }
  240. ruut::copy_shp_to_db(dir = tmp_dir, layer = tbl_names[i], conf = config,
  241. id = fid, crs_source = crs_source, crs_target = crs_target,
  242. geometry_type = 'POLYGON')
  243. cmd <- sprintf(
  244. paste0(
  245. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  246. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  247. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  248. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  249. "-s_srs %s -t_srs %s -nlt %s"
  250. ),
  251. conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode,
  252. conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target,
  253. geometry_type
  254. )
  255. source <- sprintf('"%s" "%s"', dir, layer)
  256. cmd <- sprintf(
  257. paste0(
  258. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  259. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  260. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  261. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  262. "-s_srs %s -t_srs %s -nlt %s"
  263. ),
  264. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  265. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  266. crs_source, crs_target, geometry_type
  267. )
  268. cmd
  269. system(cmd)
  270. cmd <- sprintf(
  271. paste0(
  272. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  273. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  274. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  275. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  276. "%s %s -nlt %s"
  277. ),
  278. config$dbname, config$host, config$port, config$user, config$password,
  279. config$sslmode, config$schema, source, fid, config$schema, config$table,
  280. crs_source, crs_target, geometry_type
  281. )
  282. system(cmd)
  283. source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
  284. crs_source <- "EPSG:3035"
  285. crs_target <- "EPSG:4326"
  286. fid <- "fid"
  287. cmd <- sprintf(
  288. paste0(
  289. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  290. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  291. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  292. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  293. "-s_srs %s -t_srs %s -nlt %s"
  294. ),
  295. config$dbname, config$host, config$port, config$user, config$password,
  296. config$sslmode, config$schema, source, fid, config$schema, config$table,
  297. crs_source, crs_target, geometry_type
  298. )
  299. system(cmd)
  300. config
  301. conf
  302. config
  303. cmd <- sprintf(
  304. paste0(
  305. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  306. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  307. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  308. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  309. "-s_srs %s -t_srs %s -nlt %s"
  310. ),
  311. config$dbname, config$host, config$port, config$user, config$password,
  312. config$sslmode, config$schema, source, fid, config$schema, config$table,
  313. crs_source, crs_target, geometry_type
  314. )
  315. system(cmd)
  316. cmd <- sprintf(
  317. paste0(
  318. "ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
  319. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  320. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  321. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  322. "-s_srs %s -t_srs %s -nlt %s"
  323. ),
  324. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  325. conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
  326. crs_source, crs_target, geometry_type
  327. )
  328. system(cmd)
  329. cmd <- sprintf(
  330. paste0(
  331. "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
  332. "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
  333. "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
  334. "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
  335. "-s_srs %s -t_srs %s -nlt %s"
  336. ),
  337. conf$dbname, conf$host, conf$port, conf$user, conf$password,
  338. conf$sslmode, conf$schema, source, fid, conf$schema, conf$table,
  339. crs_source, crs_target, geometry_type
  340. )
  341. system(cmd)
  342. styler:::style_active_file()
  343. library(ruut)
  344. styler:::style_active_file()
  345. styler:::style_active_file()
  346. library(ruut)
  347. styler:::style_active_file()
  348. styler:::style_active_file()
  349. library(ruut)
  350. styler:::style_active_file()
  351. library(ruut)
  352. styler:::style_active_file()
  353. styler:::style_active_file()
  354. library(ruut)
  355. styler:::style_active_file()
  356. styler:::style_active_file()
  357. styler:::style_active_file()
  358. styler:::style_active_file()
  359. library(ruut)
  360. conf <- ruut::get_config()
  361. conf
  362. styler:::style_active_file()
  363. library(ruut)
  364. library(ruut)
  365. conn <- ruut::db_connect()
  366. config <- get_config()
  367. config$schema <- "public"
  368. conf = config
  369. q <- sprintf("select t.table_name
  370. from information_schema.tables t
  371. where t.table_schema = '%s'
  372. and t.table_type = 'BASE TABLE'
  373. order by t.table_name;", conf$schema)
  374. conf$schema
  375. res <- DBI::dbGetQuery(conn, q)
  376. res
  377. res <- as.array(DBI::dbGetQuery(conn, q))
  378. res <- DBI::dbGetQuery(conn, q)
  379. res[,'table_name']
  380. styler:::style_active_file()
  381. library(ruut)
  382. config
  383. config$schema <- 'maaamet'
  384. db_schema_tablenames(conf = config)
  385. library(ruut)
  386. styler:::style_active_file()
  387. library(ruut)
  388. library(ruut)
  389. styler:::style_active_file()
  390. construct_qgis_output_result_to_beter_format <- function(str = "") {
  391. #' str - Processing algorithm… Algorithm '......' starting…
  392. #' Input parameters: -> kopeerin need loogilistes sulgudes
  393. #' olevad väärtused argumendi "str" väärtuseks.
  394. str <- "{ 'CREATEINDEX' : True, 'DATABASE' : 'Data', 'DROP_STRING_LENGTH' : False, 'ENCODING' : 'UTF-8', 'FORCE_SINGLEPART' : False, 'GEOMETRY_COLUMN' : 'geometry', 'INPUT' : '/data/gpkg/teed/teed_l.gpkg|layername=teed_l', 'LOWERCASE_NAMES' : True, 'OVERWRITE' : True, 'PRIMARY_KEY' : 'fid', 'SCHEMA' : 'data', 'TABLENAME' : 'mikihiir' }"
  395. str <- gsub("'", "", str)
  396. str <- gsub(":", "=", str)
  397. str <- gsub(" ", "", str)
  398. str <- gsub(",", "',", str)
  399. str <- gsub("=", "='", str)
  400. str <- gsub("'True'", "1", str)
  401. str <- gsub("'False'", "0", str)
  402. str <- gsub(",", ",\n", str)
  403. str <- gsub("[{]", "\nalgorithm=algorithm,\n", str)
  404. str <- gsub("[}]", "'\n", str)
  405. str <- gsub("layername='", "layername=", str)
  406. cat(str)
  407. str
  408. }
  409. str <- "{ 'CREATEINDEX' : True, 'DATABASE' : 'Data', 'DROP_STRING_LENGTH' : False, 'ENCODING' : 'UTF-8', 'FORCE_SINGLEPART' : False, 'GEOMETRY_COLUMN' : 'geometry', 'INPUT' : '/data/gpkg/teed/teed_l.gpkg|layername=teed_l', 'LOWERCASE_NAMES' : True, 'OVERWRITE' : True, 'PRIMARY_KEY' : 'fid', 'SCHEMA' : 'data', 'TABLENAME' : 'mikihiir' }"
  410. params <- construct_qgis_output_result_to_beter_format(str = str)
  411. styler:::style_active_file()
  412. styler:::style_active_file()
  413. library(ruut)
  414. library(ruut)
  415. styler:::style_active_file()
  416. library(ruut)
  417. library(ruut)
  418. library(ruut)
  419. styler:::style_active_file()
  420. library(ruut)
  421. library(ruut)
  422. library(ruut)
  423. library(ruut)
  424. styler:::style_active_file()
  425. construct_ogr2ogr_PG_connect_str()
  426. construct_ogr2ogr_PG_connect_str <- function(gpkg_home = "/tmp", gpkg_file = "test", gpkg_table = "layer_one") {
  427. dsn <- sprintf("%s/%s.gpkg", gpkg_home, gpkg_file)
  428. ogr <- sprintf("ogr:dbname='%s'", dsn)
  429. output <- sprintf('%s table=\"%s\" (geometry)', ogr, gpkg_table)
  430. output
  431. }
  432. construct_ogr2ogr_PG_connect_str()
  433. library(ruut)
  434. styler:::style_active_file()
  435. conf <- ruut::get_config()
  436. PG <- sprintf(
  437. 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' password=\'%s\' sslmode=%s key=\'id\' srid=3301 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
  438. conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
  439. )
  440. PG
  441. styler:::style_active_file()
  442. PG
  443. library(ruut)
  444. conf <- ruut::get_config()
  445. construct_to_gpkg_output_postgres_str <- function(conf = NULL) {
  446. if (is.null(conf)) conf <- ruut::get_config()
  447. PG <- sprintf(
  448. 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' password=\'%s\' sslmode=%s key=\'id\' srid=3301 checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
  449. conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
  450. )
  451. PG
  452. }
  453. construct_to_gpkg_output_postgres_str(conf =
  454. conf
  455. )
  456. conf <- ruut::get_config()
  457. conf
  458. library(ruut)
  459. conf <- ruut::get_config()
  460. conf
  461. conf <- ruut::get_config()
  462. construct_to_gpkg_output_file_str(conf = conf)
  463. construct_to_gpkg_output_file_str <- function(conf = conf) {
  464. dsn <- sprintf("%s/%s.gpkg", conf$gpkg_home, conf$gpkg_file)
  465. ogr <- sprintf("ogr:dbname='%s'", dsn)
  466. output <- sprintf('%s table=\"%s\" (geometry)', ogr, conf$gpkg_table)
  467. output
  468. }
  469. construct_to_gpkg_output_file_str(conf = conf)
  470. styler:::style_active_file()
  471. library(ruut)
  472. config <- get_config()
  473. llibrary(ruut)
  474. library(ruut)
  475. config <- get_config()
  476. config$schema <- "data"
  477. db_schema_tablenames(conf = config)
  478. conn <- ruut::db_connect()
  479. q <- sprintf("select t.table_name
  480. from information_schema.tables t
  481. where t.table_schema = '%s'
  482. and t.table_type = 'BASE TABLE'
  483. order by t.table_name;", conf$schema)
  484. res <- DBI::dbGetQuery(conn, q)
  485. conn <- ruut::db_connect()
  486. q <- sprintf("select t.table_name
  487. from information_schema.tables t
  488. where t.table_schema = '%s'
  489. and t.table_type = 'BASE TABLE'
  490. order by t.table_name;", conf$schema)
  491. conf$schema
  492. config <- get_config()
  493. config$schema <- "data"
  494. conf <- get_config()
  495. conf$schema <-
  496. "data"
  497. conn <- ruut::db_connect()
  498. q <- sprintf("select t.table_name
  499. from information_schema.tables t
  500. where t.table_schema = '%s'
  501. and t.table_type = 'BASE TABLE'
  502. order by t.table_name;", conf$schema)
  503. res <- DBI::dbGetQuery(conn, q)
  504. nrow(res)
  505. if(nrow(res)==0) NULL else res[, "table_name"]
  506. if(nrow(res)==0) NULL else res[, "table_name"]
  507. styler:::style_active_file()
  508. library(ruut)
  509. library(ruut)
  510. styler:::style_active_file()
  511. library(ruut)
  512. library(ruut)