Эх сурвалжийг харах

Muudetud 'pk_lisame_jooned'.

Ardo Kubjas 5 жил өмнө
parent
commit
88f6aeec0a
1 өөрчлөгдсөн 10 нэмэгдсэн , 24 устгасан
  1. 10 24
      R/pk_lisame_jooned.R

+ 10 - 24
R/pk_lisame_jooned.R

@@ -18,39 +18,24 @@
 #' ruut::db_schema_tablenames(conf = conf)
 #' }
 pk_lisame_jooned <- function(obj = NULL, conf = NULL) {
-  obj <- gsub(" ", "_", tolower(obj))
+  ## ------------- muutujad ja teisendused ---------------
+  vars <- ajutised_muutujad(pk = NULL, obj, conf)
+  obj <- vars$obj
+  piir <- vars$pk
+  conf <- vars$conf
   ## Konfiguratsiooni muutujale väärtuste omistamine, kui seda pole antud.
-  if (is.null(conf)) {
-    conf <- ruut::get_config()
-    conf$schema <- obj
-  }
-  if (!any("piir" %in% ruut::db_schema_tablenames(conf = conf))) {
+  if (!any("a00_piir" %in% ruut::db_schema_tablenames(conf = conf))) {
     cat("\nAndmebaas loomata. Palun funktsiooniga ruut::pk_sellest_alustame_db_loomist() andmebaasi loomist.\n")
     return(NULL)
   }
 
-  ## ------------- muutujad ja teisendused ---------------
-  conn <- ruut::db_connect(conf = conf)
-  try(piir <- sf::st_read(dsn = conn, layer = c(conf$schema, "piir")))
-  tmp_dir <- tempdir()
-  tmp_gpkg_file <- sprintf("%s/%s.gpkg", tmp_dir, obj)
-  # system(sprintf("touch %s", tmp_gpkg_file))
-  conf$gpkg_home <- tmp_dir
-  conf$gpkg_file <- obj
-  conf$gpkg_table <- "test_layer"
-  tmp_gpkg_file_output <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  # write to gpkg
-  sf::write_sf(piir, dsn = tmp_gpkg_file, layer = "piir", driver = "gpkg", fid_column_name = "id", delete_dsn = T)
-  # unlink(tmp_gpkg_file)
-
   ## Algorithm
   # ruut::qgis_algorithm_search_by_word(str = "extract")
   # algorithm <- "native:extractbylocation"
   # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
 
   ## -------------------- Loop -----------------------
-  intersect_layers <- c("bb2") # c("piir", "bb", "bb2")
+  intersect_layers <- c("a00_bb2") # c("piir", "bb", "bb2")
   andmed <- data.frame("schema" = character(0), "table" = character(0))
   andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "n_alusdokumendid_ja_lepingud"))
   andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "pohimaantee"))
@@ -86,7 +71,8 @@ pk_lisame_jooned <- function(obj = NULL, conf = NULL) {
         conf = conf, geometry_type = "Linestring", srid = 3301,
         checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = geom
       )
-      conf$table <- sprintf("%s", andmed$table[i])
+      ## Andmebaasi tabeli nimi: 2 esimest tähte tuleb schema nimest millest on andmed võetud, siis '_l_' s.o 'line' mis tähistab jooni.
+      conf$table <- sprintf("%s_l_%s", strtrim(as.character(andmed$schema[i]), 2), andmed$table[i])
       conf$schema <- obj
       output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_field = "geom", geometry_type = NULL, srid = 3301, checkPrimaryKeyUnicity = FALSE, key = "id")
       str <- paste0("{ 'INPUT' : '", input, "', 'INPUT_FIELDS' : [], 'OUTPUT' : '", output, "', 'OVERLAY' : '", intersect_layer, "', 'OVERLAY_FIELDS' : [], 'OVERLAY_FIELDS_PREFIX' : '' }")
@@ -99,5 +85,5 @@ pk_lisame_jooned <- function(obj = NULL, conf = NULL) {
   ## Layers list
   conf$schema <- obj
   ruut::db_schema_tablenames(conf = conf)
-  sf::st_layers(dsn = tmp_gpkg_file)
+  sf::st_layers(dsn = vars$tmp_gpkg_file)
 }