ソースを参照

Väli 'geometry' asendati väljaga 'geom'.

Ardo Kubjas 5 年 前
コミット
ad8db02cb5

+ 94 - 94
.Rhistory

@@ -1,97 +1,3 @@
-paste0(getwd(), "/R/db_all_schemas.R")
-source(paste0(getwd(), "/R/db_all_schemas.R"))
-db_is_shema_exist(schema = "x_matsalu")
-db_is_shema_exist(schema = "x_matsalu")
-db_is_shema_exist(schema = "zx_matsalu")
-styler:::style_active_file()
-styler:::style_active_file()
-db_create_new_schema <- function(conf) {
-source(paste0(getwd(), "/R/db_is_shema_exist.R"))
-if(db_is_shema_exist(schema)) {
-conn <- db_connect()
-DBI::dbExecute(conn, sprintf(
-"-- DROP SCHEMA x_matsalu;
-CREATE SCHEMA %s AUTHORIZATION %s;", conf$schema, conf$user
-))
-}
-}
-conf <- ruut::get_config()
-conf$schema <- "x_valga"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf
-conf$schema <- "x_valga1"
-conf
-db_create_new_schema(conf)
-conf$schema
-db_create_new_schema <- function(conf) {
-source(paste0(getwd(), "/R/db_is_shema_exist.R"))
-if(!db_is_shema_exist(conf$schema)) {
-conn <- db_connect()
-DBI::dbExecute(conn, sprintf(
-"-- DROP SCHEMA x_matsalu;
-CREATE SCHEMA %s AUTHORIZATION %s;", conf$schema, conf$user
-))
-}
-}
-conf <- ruut::get_config()
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-library(ruut)
-conf <- ruut::get_config()
-conf
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-db_create_new_schema <- function(conf) {
-source(paste0(getwd(), "/R/db_is_shema_exist.R"))
-if(!db_is_shema_exist(conf$schema)) {
-conn <- db_connect()
-DBI::dbExecute(conn, sprintf(
-"-- DROP SCHEMA x_matsalu;
-CREATE SCHEMA %s AUTHORIZATION %s;", conf$schema, conf$user
-))
-}
-}
-db_create_new_schema(conf)
-DBI::dbDisconnect(conn)
-conf <- ruut::get_config()
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga1"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga"
-db_create_new_schema(conf)
-conf <- ruut::get_config()
-conf$schema <- "x_valga"
-db_create_new_schema(conf)
-styler:::style_active_file()
-library(ruut)
-styler:::style_active_file()
-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()
@@ -510,3 +416,97 @@ styler:::style_active_file()
 styler:::style_active_file()
 library(ruut)
 library(ruut)
+styler:::style_active_file()
+library(ruut)
+library(ruut)
+library(ruut)
+styler:::style_active_file()
+library(ruut)
+library(ruut)
+library(ruut)
+library(ruut)
+styler:::style_active_file()
+construct_ogr2ogr_PG_connect_str()
+construct_ogr2ogr_PG_connect_str <- function(gpkg_home = "/tmp", gpkg_file = "test", gpkg_table = "layer_one") {
+dsn <- sprintf("%s/%s.gpkg", gpkg_home, gpkg_file)
+ogr <- sprintf("ogr:dbname='%s'", dsn)
+output <- sprintf('%s table=\"%s\" (geometry)', ogr, gpkg_table)
+output
+}
+construct_ogr2ogr_PG_connect_str()
+library(ruut)
+styler:::style_active_file()
+conf <- ruut::get_config()
+PG <- sprintf(
+'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)',
+conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
+)
+PG
+styler:::style_active_file()
+PG
+library(ruut)
+conf <- ruut::get_config()
+construct_to_gpkg_output_postgres_str <- function(conf = NULL) {
+if (is.null(conf)) conf <- ruut::get_config()
+PG <- sprintf(
+'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' password=\'%s\' sslmode=%s key=\'id\' srid=3301  checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
+conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
+)
+PG
+}
+construct_to_gpkg_output_postgres_str(conf =
+conf
+)
+conf <- ruut::get_config()
+conf
+library(ruut)
+conf <- ruut::get_config()
+conf
+conf <- ruut::get_config()
+construct_to_gpkg_output_file_str(conf = conf)
+construct_to_gpkg_output_file_str <- function(conf = conf) {
+dsn <- sprintf("%s/%s.gpkg", conf$gpkg_home, conf$gpkg_file)
+ogr <- sprintf("ogr:dbname='%s'", dsn)
+output <- sprintf('%s table=\"%s\" (geometry)', ogr, conf$gpkg_table)
+output
+}
+construct_to_gpkg_output_file_str(conf = conf)
+styler:::style_active_file()
+library(ruut)
+config <- get_config()
+llibrary(ruut)
+library(ruut)
+config <- get_config()
+config$schema <- "data"
+db_schema_tablenames(conf = config)
+conn <- ruut::db_connect()
+q <- sprintf("select t.table_name
+from information_schema.tables t
+where t.table_schema = '%s'
+and t.table_type = 'BASE TABLE'
+order by t.table_name;", conf$schema)
+res <- DBI::dbGetQuery(conn, q)
+conn <- ruut::db_connect()
+q <- sprintf("select t.table_name
+from information_schema.tables t
+where t.table_schema = '%s'
+and t.table_type = 'BASE TABLE'
+order by t.table_name;", conf$schema)
+conf$schema
+config <- get_config()
+config$schema <- "data"
+conf <- get_config()
+conf$schema <-
+"data"
+conn <- ruut::db_connect()
+q <- sprintf("select t.table_name
+from information_schema.tables t
+where t.table_schema = '%s'
+and t.table_type = 'BASE TABLE'
+order by t.table_name;", conf$schema)
+res <- DBI::dbGetQuery(conn, q)
+nrow(res)
+if(nrow(res)==0) NULL else res[, "table_name"]
+if(nrow(res)==0) NULL else res[, "table_name"]
+styler:::style_active_file()
+library(ruut)

+ 3 - 3
R/construct_qgis_output_result_to_beter_format.R

@@ -6,7 +6,7 @@
 #' Processing algorithm…
 #' Algorithm 'Export to PostgreSQL' starting…
 #' Input parameters:
-#' { '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' }
+#' { 'CREATEINDEX' : True, 'DATABASE' : 'Data', 'DROP_STRING_LENGTH' : False, 'ENCODING' : 'UTF-8', 'FORCE_SINGLEPART' : False, 'GEOMETRY_COLUMN' : 'geom', 'INPUT' : '/data/gpkg/teed/teed_l.gpkg|layername=teed_l', 'LOWERCASE_NAMES' : True, 'OVERWRITE' : True, 'PRIMARY_KEY' : 'fid', 'SCHEMA' : 'data', 'TABLENAME' : 'mikihiir' }
 #' @param str string A QGIS input parameters.
 #' @return A string.
 #' @seealso [qgisprocess::qgis_run_algorithm], [ruut::construct_ogr2ogr_PG_connect_str]
@@ -18,7 +18,7 @@
 #'
 #' # QGIS funktsiooni käivitamisel saatakse logisse argumentidest järgmine väljund
 #' str <- "{ 'CREATEINDEX' : True, 'DATABASE' : 'Data', 'DROP_STRING_LENGTH' : False,
-#' 'ENCODING' : 'UTF-8', 'FORCE_SINGLEPART' : False, 'GEOMETRY_COLUMN' : 'geometry',
+#' 'ENCODING' : 'UTF-8', 'FORCE_SINGLEPART' : False, 'GEOMETRY_COLUMN' : 'geom',
 #' 'INPUT' : '/data/gpkg/teed/teed_l.gpkg|layername=teed_l', 'LOWERCASE_NAMES' : True,
 #' 'OVERWRITE' : True, 'PRIMARY_KEY' : 'fid', 'SCHEMA' : 'data', 'TABLENAME' : 'mikihiir' }"
 #'
@@ -34,7 +34,7 @@ construct_qgis_output_result_to_beter_format <- function(str = "") {
   str <- gsub("'False'", "0", str)
   # Numbrite ümbert ülakomade eemaldamine
   str <- gsub("'([0-9]+\\.{0,1}[0-9]*)'", "\\1", str)
-  str <- gsub("[(]geom[)]", "(geometry)", str)
+  str <- gsub("[(]geom[)]", "(geom)", str)
   str_list <- str
   # Suurte tähtede ümbert ülakomade eemaldamine
   str <- gsub("'([A-Z_]*)'", "\\1", str)

+ 2 - 2
R/construct_to_gpkg_output_file_str.R

@@ -2,7 +2,7 @@
 #'
 #' See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide  kasutatava fraasi, mis on vajalik andmebaasiga ühendamisegs.
 #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
-#' @return A string "ogr:dbname='%s/%s.gpkg' table=\"%s\" (geometry)".
+#' @return A string "ogr:dbname='%s/%s.gpkg' table=\"%s\" (geom)".
 #' @seealso [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::construct_qgis_output_result_to_beter_format()]
 #' @keywords gpkg
 #' @export
@@ -16,6 +16,6 @@
 construct_to_gpkg_output_file_str <- function(conf = conf) {
   dsn <- sprintf("%s/%s.gpkg", conf$gpkg_home, conf$gpkg_file)
   ogr <- sprintf("ogr:dbname='%s'", dsn)
-  output <- sprintf('%s table=\"%s\" (geometry)', ogr, conf$gpkg_table)
+  output <- sprintf('%s table=\"%s\" (geom)', ogr, conf$gpkg_table)
   output
 }

+ 2 - 2
R/construct_to_gpkg_output_postgres_str.R

@@ -3,7 +3,7 @@
 #' See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide  kasutatava fraasi, mis on vajalik postgresql andmebaasiga ühendamisegs.
 #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
 #' @seealso [ruut::db_connect()], [ruut::get_config()], [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::construct_qgis_output_result_to_beter_format()],[ruut::construct_to_gpkg_output_file_str()]
-#' @return A string "postgres://dbname='%s' host=%s port=%s user='%s' password='%s' sslmode=%s key='id' srid=3301  checkPrimaryKeyUnicity='1' table=\"%s\".\"%s\" (geometry)".
+#' @return A string "postgres://dbname='%s' host=%s port=%s user='%s' password='%s' sslmode=%s key='id' srid=3301  checkPrimaryKeyUnicity='1' table=\"%s\".\"%s\" (geom)".
 #' @seealso [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::construct_qgis_output_result_to_beter_format()]
 #' @keywords gpkg
 #' @export
@@ -17,7 +17,7 @@
 construct_to_gpkg_output_postgres_str <- function(conf = NULL) {
   if (is.null(conf)) conf <- ruut::get_config()
   PG <- sprintf(
-    'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' password=\'%s\' sslmode=%s key=\'id\' srid=3301  checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
+    'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' password=\'%s\' sslmode=%s key=\'id\' srid=3301  checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geom)',
     conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
   )
   PG

+ 1 - 1
R/copy_qgis_object_to_db.R

@@ -29,7 +29,7 @@ copy_qgis_object_to_db <- function(x = NULL, conf = NULL, id = "fid",
         "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 ",
+        "-lco GEOMETRY_NAME=geom -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,

+ 1 - 1
R/copy_shp_to_db.R

@@ -32,7 +32,7 @@ copy_shp_to_db <- function(dir = NULL, layer = NULL, conf = NULL, id = "fid",
         "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 ",
+        "-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
         "-s_srs %s -t_srs %s -nlt %s"
       ),
       conf$dbname, conf$host, conf$port, conf$user, conf$password,

+ 1 - 1
inst/extdata/config.json

@@ -8,7 +8,7 @@
   "schema":"date_YYMMDD",
   "table":"",
   "encoding":"UTF-8",
-  "geometry_column":"geometry",
+  "geometry_column":"geom",
   "primary_key":"fid",
   "gtype":0,
   "a_srs":"EPSG:3301",