|
|
@@ -1,300 +1,3 @@
|
|
|
-config <- ruut::get_config()
|
|
|
-config
|
|
|
-config$dbname
|
|
|
-names(config)
|
|
|
-names(config) %in% c("dbname","host","port","user","password")
|
|
|
-names(config)
|
|
|
-c("dbname","host","port","user","password") %in% names(config)
|
|
|
-all(c("dbname","host","port","user","password") %in% names(config))
|
|
|
-styler:::style_active_file()
|
|
|
-RPostgreSQL::PostgreSQL()
|
|
|
-config <- ruut::get_config()
|
|
|
-try(conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-))
|
|
|
-(
|
|
|
-conn
|
|
|
-)
|
|
|
-db_connect <- function(conf = NULL) {
|
|
|
-if (is.null(conf)) {
|
|
|
-config <- ruut::get_config()
|
|
|
-} else {
|
|
|
-config <- conf
|
|
|
-}
|
|
|
-if (all(c("dbname", "host", "port", "user", "password") %in% names(config))) {
|
|
|
-try(conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-))
|
|
|
-} else {
|
|
|
-print("Andmebaasiga \U00FChendamise parameetrid puudulikud. Palun kontrolli konfiguratsiooni faili.")
|
|
|
-return()
|
|
|
-}
|
|
|
-## Andmebaasiga ühenduse kontroll
|
|
|
-if (exists("conn") && !inherits(conn, "try-error")) {
|
|
|
-print("Connection exist")
|
|
|
-} else {
|
|
|
-print("Connection error")
|
|
|
-}
|
|
|
-}
|
|
|
-conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-)
|
|
|
-conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-)
|
|
|
-conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-)
|
|
|
-config <- ruut::get_config()
|
|
|
-config
|
|
|
-conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-)
|
|
|
-conn
|
|
|
-## Andmebaasiga ühenduse kontroll
|
|
|
-if (exists("conn") && !inherits(conn, "try-error")) {
|
|
|
-print("Connection exist")
|
|
|
-} else {
|
|
|
-print("Connection error")
|
|
|
-}
|
|
|
-styler:::style_active_file()
|
|
|
-library(ruut)
|
|
|
-ruut::dbconnect()
|
|
|
-library(ruut)
|
|
|
-ruut::pk_bbox()
|
|
|
-ruut::cat_function()
|
|
|
-ruut::get_config()
|
|
|
-source("R/db_connect.R")
|
|
|
-conn <- db_connect()
|
|
|
-conn
|
|
|
-source("./R/db_connect.R")
|
|
|
-source("./R/db_connect.R")
|
|
|
-conn <- db_connect()
|
|
|
-conn
|
|
|
-source("db_connect.R")
|
|
|
-styler:::style_active_file()
|
|
|
-ruut::cat_function()
|
|
|
-print(file.exists(system.file(c("db_connect.R"), package = "ruut")))
|
|
|
-print(file.exists(system.file(c("db_connect.R"), package = "ruut")))
|
|
|
-ruut::cat_function()
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-print(file.exists(system.file(c("db_connect.R"), package = "ruut")))
|
|
|
-print(file.exists(system.file(c("R","db_connect.R"), package = "ruut")))
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-ruut::cat_function()
|
|
|
-styler:::style_active_file()
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-paste0(getwd(),"/R/db_connect.R")
|
|
|
-file.exists(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-ruut::cat_function()
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-styler:::style_active_file()
|
|
|
-library(ruut)
|
|
|
-ruut::cat_function()
|
|
|
-db_connect <- function(conf = NULL) {
|
|
|
-if (is.null(conf)) {
|
|
|
-config <- ruut::get_config()
|
|
|
-} else {
|
|
|
-config <- conf
|
|
|
-}
|
|
|
-if (all(c("dbname", "host", "port", "user", "password") %in% names(config))) {
|
|
|
-try(conn <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
|
|
|
-dbname = config$dbname, host = config$host,
|
|
|
-user = config$user, password = config$password,
|
|
|
-port = config$port
|
|
|
-))
|
|
|
-} else {
|
|
|
-conn <- NULL
|
|
|
-print("Andmebaasiga \U00FChendamise parameetrid puudulikud. Palun kontrolli konfiguratsiooni faili.")
|
|
|
-return()
|
|
|
-}
|
|
|
-## Andmebaasiga ühenduse kontroll
|
|
|
-if (exists("conn") && !inherits(conn, "try-error")) {
|
|
|
-print("Connection exist")
|
|
|
-} else {
|
|
|
-print("Connection error")
|
|
|
-}
|
|
|
-}
|
|
|
-db_connect()
|
|
|
-db_connect(conf = conf)
|
|
|
-config <- ruut::get_config()
|
|
|
-db_connect(conf = config)
|
|
|
-db_connect(conf = c("3"))
|
|
|
-conn
|
|
|
-dbDisconnect(conn)
|
|
|
-dbDisconnect(conn)
|
|
|
-conn
|
|
|
-library(ruut)
|
|
|
-db_connect()
|
|
|
-xxx <- db_connect()
|
|
|
-xxx
|
|
|
-library(ruut)
|
|
|
-xxx <- db_connect()
|
|
|
-db_connect()
|
|
|
-library(ruut)
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-conn
|
|
|
-library(ruut)
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-styler:::style_active_file()
|
|
|
-get_config <- function(conf = NULL) {
|
|
|
-if (is.null(conf)) {
|
|
|
-config <- rjson::fromJSON(file = system.file("extdata", "config.json", package = "ruut"))
|
|
|
-}
|
|
|
-else {
|
|
|
-config <- conf
|
|
|
-}
|
|
|
-return(config)
|
|
|
-}
|
|
|
-get_config
|
|
|
-get_config()
|
|
|
-styler:::style_active_file()
|
|
|
-styler:::style_active_file()
|
|
|
-styler:::style_active_file()
|
|
|
-library(ruut)
|
|
|
-library(ruut)
|
|
|
-qgis_algorithm_search_by_word(str = "bound")
|
|
|
-algorithm <- "native:boundingboxes"
|
|
|
-## Read help!!!
|
|
|
-cat(qgis_show_help(algorithm = algorithm))
|
|
|
-# Run algorithm.
|
|
|
-library(ruut)
|
|
|
-library(ruut)
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-all_schemas
|
|
|
-db_all_schemas <- function() {
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-all_schemas$schema_name
|
|
|
-}
|
|
|
-db_all_schemas()
|
|
|
-db_is_shema_exist <- function(schema = NULL) {
|
|
|
-if(schema %in% db_all_schemas()) return(TRUE) else return(FALSE)
|
|
|
-}
|
|
|
-db_is_shema_exist("xxxx")
|
|
|
-aaa <- db_is_shema_exist("xxxx")
|
|
|
-aaa <- db_is_shema_exist("x_matsalu")
|
|
|
-aaa <- db_is_shema_exist("x_matsalu")
|
|
|
-schema = "x_matsalu"
|
|
|
-schema %in% db_all_schemas()
|
|
|
-db_all_schemas()
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-aaa
|
|
|
-aaa <- db_is_shema_exist(schema = "sx_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "sx_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "sx_matsalu")
|
|
|
-db_is_shema_exist <- function(schema = NULL) {
|
|
|
-if(schema %in% db_all_schemas())
|
|
|
-return(TRUE)
|
|
|
-else
|
|
|
-return(FALSE)
|
|
|
-}
|
|
|
-aaa <- db_is_shema_exist(schema = "sx_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "sx_matsalu")
|
|
|
-aaa
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-aaa <- db_is_shema_exist(schema = "x_matsalu")
|
|
|
-db_is_shema_exist(schema = "x_matsalu")
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-db_is_shema_exist(schema = "x_matsalu")
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-all_schemas$schema_name
|
|
|
-db_all_schemas <- function() {
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-return (all_schemas$schema_name)
|
|
|
-}
|
|
|
-db_all_schemas()
|
|
|
-db_all_schemas()
|
|
|
-db_all_schemas()
|
|
|
-db_all_schemas()
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-db_all_schemas <- function() {
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-return (all_schemas$schema_name)
|
|
|
-}
|
|
|
-# db_all_schemas()
|
|
|
-db_is_shema_exist <- function(schema = NULL) {
|
|
|
-if(schema %in% db_all_schemas())
|
|
|
-return(TRUE)
|
|
|
-else
|
|
|
-return(FALSE)
|
|
|
-}
|
|
|
-DBI::dbDisconnect(conn)
|
|
|
-conn <- db_connect()
|
|
|
-conn <- db_connect()
|
|
|
-conn <- db_connect()
|
|
|
-library(ruut)
|
|
|
-conn <- db_connect()
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-all_schemas
|
|
|
-all_schemas$schema_name
|
|
|
-library(ruut)
|
|
|
-db_all_schemas <- function() {
|
|
|
-source(paste0(getwd(),"/R/db_connect.R"))
|
|
|
-conn <- db_connect()
|
|
|
-all_schemas <- DBI::dbGetQuery(conn, "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA")
|
|
|
-return (all_schemas$schema_name)
|
|
|
-}
|
|
|
-# db_all_schemas()
|
|
|
-db_is_shema_exist <- function(schema = NULL) {
|
|
|
-if(schema %in% db_all_schemas())
|
|
|
-return(TRUE)
|
|
|
-else
|
|
|
-return(FALSE)
|
|
|
-}
|
|
|
-db_all_schemas()
|
|
|
-db_is_shema_exist <- function(schema = NULL) {
|
|
|
-if(schema %in% db_all_schemas())
|
|
|
-return(TRUE)
|
|
|
else
|
|
|
return(FALSE)
|
|
|
}
|
|
|
@@ -449,3 +152,361 @@ library(ruut)
|
|
|
styler:::style_active_file()
|
|
|
library(ruut)
|
|
|
library(ruut)
|
|
|
+library(ruut)
|
|
|
+library(ruut)
|
|
|
+library(ruut)
|
|
|
+ogr2ogr --long-usage
|
|
|
+system("ogr2ogr --long-usage")
|
|
|
+library(ruut)
|
|
|
+library(ruut)
|
|
|
+library(ruut)
|
|
|
+styler:::style_active_file()
|
|
|
+styler:::style_active_file()
|
|
|
+system("ogr2ogr --long-usage")
|
|
|
+styler:::style_active_file()
|
|
|
+styler:::style_active_file()
|
|
|
+library(ruut)
|
|
|
+#'
|
|
|
+#' INSPIRE grid map
|
|
|
+#'
|
|
|
+library(dplyr)
|
|
|
+library(ruut)
|
|
|
+# Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2
|
|
|
+# Temp directory
|
|
|
+tmp_dir <- tempdir()
|
|
|
+# Download link
|
|
|
+url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
|
|
|
+# Estonia shapefile (ZIP archive)
|
|
|
+map_shapefile <- "Estonia_shapefile.zip"
|
|
|
+# Download and sav
|
|
|
+saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
+download.file(
|
|
|
+url = download_url,
|
|
|
+destfile = saveTo, method = "curl", extra = "-L"
|
|
|
+)
|
|
|
+# Unzip
|
|
|
+unzip(saveTo, overwrite = T, exdir = tmp_dir)
|
|
|
+# List of files
|
|
|
+ls <- list.files(path = tmp_dir, pattern = ".shp")
|
|
|
+ls_long <- list.files(path = tmp_dir, pattern = ".shp", full.names = T)
|
|
|
+tbl_names <- strsplit(x = ls, split = ".shp") %>% unlist()
|
|
|
+# Export to postgis
|
|
|
+schema <- "inspire"
|
|
|
+i <- 1
|
|
|
+config <- get_config()
|
|
|
+config$schema <- schema
|
|
|
+# New schema
|
|
|
+db_create_new_schema(conf = config)
|
|
|
+library(dplyr)
|
|
|
+library(ruut)
|
|
|
+# Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2
|
|
|
+# Temp directory
|
|
|
+tmp_dir <- tempdir()
|
|
|
+# Download link
|
|
|
+url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
|
|
|
+# Estonia shapefile (ZIP archive)
|
|
|
+map_shapefile <- "Estonia_shapefile.zip"
|
|
|
+# Download and sav
|
|
|
+saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
+download.file(
|
|
|
+url = url,
|
|
|
+destfile = saveTo, method = "curl", extra = "-L"
|
|
|
+)
|
|
|
+# Unzip
|
|
|
+unzip(saveTo, overwrite = T, exdir = tmp_dir)
|
|
|
+# List of files
|
|
|
+ls <- list.files(path = tmp_dir, pattern = ".shp")
|
|
|
+ls_long <- list.files(path = tmp_dir, pattern = ".shp", full.names = T)
|
|
|
+tbl_names <- strsplit(x = ls, split = ".shp") %>% unlist()
|
|
|
+# Export to postgis
|
|
|
+schema <- "inspire"
|
|
|
+i <- 1
|
|
|
+config <- get_config()
|
|
|
+config$schema <- schema
|
|
|
+# New schema
|
|
|
+db_create_new_schema(conf = config)
|
|
|
+print(tbl_names[i])
|
|
|
+config$table <- tbl_names[i]
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
|
|
|
+crs_source <- "-s_srs EPSG:3035"
|
|
|
+crs_target <- "-t_srs EPSG:4326"
|
|
|
+fid <- "fid"
|
|
|
+ruut::copy_shp_to_db(dir = tmp_dir, layer = tbl_names[i], conf = config,
|
|
|
+id = fid, crs_source = crs_source, crs_target = crs_target,
|
|
|
+geometry_type = 'POLYGON')
|
|
|
+dir = tmp_dir; layer = tbl_names[i]; conf = config;
|
|
|
+id = fid; crs_source = crs_source; crs_target = crs_target;
|
|
|
+geometry_type = 'POLYGON'
|
|
|
+length(list.files(path = dir, pattern = sprintf("%s*", layer)))
|
|
|
+length(list.files(path = dir, pattern = sprintf("%s*", layer))) > 0
|
|
|
+source <- sprintf('"%s" "%s"', dir, layer)
|
|
|
+source
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+dir = tmp_dir; layer = tbl_names[i]; conf = config;
|
|
|
+id = fid; crs_source = crs_source; crs_target = crs_target;
|
|
|
+geometry_type = 'PROMOTE_TO_MULTI'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+ruut::db_create_new_schema(conf)
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt PROMOTE_TO_MULTI"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target
|
|
|
+)
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+geometry_type = 'POLYGON'
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+system("ogr2ogr --long-usage")
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs%s -t_srs -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+crs_target
|
|
|
+crs_source
|
|
|
+cmd
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+crs_target
|
|
|
+crs_source = "EPSG:4326"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+source('~/apps/R/packages/ruut/R/copy_shp_to_db.R', echo=TRUE)
|
|
|
+cmd
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+copy_shp_to_db <- function(dir = NULL, layer = NULL, conf = NULL, id = "fid",
|
|
|
+crs_source = "EPSG:4326",
|
|
|
+crs_target = "EPSG:4326",
|
|
|
+geometry_type = "PROMOTE_TO_MULTI") {
|
|
|
+# Command 'ogr2ogr' help
|
|
|
+# system("ogr2ogr --long-usage")
|
|
|
+# Kontrollime kas etteantud kataloogis paiknevad failid
|
|
|
+if (length(list.files(path = dir, pattern = sprintf("%s*", layer))) > 0) {
|
|
|
+source <- sprintf('"%s" "%s"', dir, layer)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+ruut::db_create_new_schema(conf)
|
|
|
+Sys.sleep(1)
|
|
|
+system(cmd)
|
|
|
+} else {
|
|
|
+cat("\nEi leitud antud kataloogist faile.")
|
|
|
+return(NULL)
|
|
|
+}
|
|
|
+}
|
|
|
+ruut::copy_shp_to_db(dir = tmp_dir, layer = tbl_names[i], conf = config,
|
|
|
+id = fid, crs_source = crs_source, crs_target = crs_target,
|
|
|
+geometry_type = 'POLYGON')
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode,
|
|
|
+conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target,
|
|
|
+geometry_type
|
|
|
+)
|
|
|
+source <- sprintf('"%s" "%s"', dir, layer)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+cmd
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"%s %s -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
|
|
|
+crs_source <- "EPSG:3035"
|
|
|
+crs_target <- "EPSG:4326"
|
|
|
+fid <- "fid"
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+config
|
|
|
+conf
|
|
|
+config
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+config$dbname, config$host, config$port, config$user, config$password,
|
|
|
+config$sslmode, config$schema, source, fid, config$schema, config$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --conf PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, id, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+cmd <- sprintf(
|
|
|
+paste0(
|
|
|
+"ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
|
|
|
+"PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
|
|
|
+"sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
|
|
|
+"-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
|
|
|
+"-s_srs %s -t_srs %s -nlt %s"
|
|
|
+),
|
|
|
+conf$dbname, conf$host, conf$port, conf$user, conf$password,
|
|
|
+conf$sslmode, conf$schema, source, fid, conf$schema, conf$table,
|
|
|
+crs_source, crs_target, geometry_type
|
|
|
+)
|
|
|
+system(cmd)
|
|
|
+styler:::style_active_file()
|
|
|
+library(ruut)
|
|
|
+styler:::style_active_file()
|
|
|
+styler:::style_active_file()
|
|
|
+library(ruut)
|
|
|
+styler:::style_active_file()
|