Kaynağa Gözat

Pärast pikka pausi.

Ardo Kubjas 4 yıl önce
ebeveyn
işleme
dd5f1440d1
2 değiştirilmiş dosya ile 61 ekleme ve 0 silme
  1. 1 0
      .Rbuildignore
  2. 60 0
      inst/ajutised_muutujad.R

+ 1 - 0
.Rbuildignore

@@ -2,3 +2,4 @@
 ^\.Rproj\.user$
 ^LICENSE\.md$
 ^ajutised_muutujad$
+^teed_loome_riigiteede_vorgu$

+ 60 - 0
inst/ajutised_muutujad.R

@@ -0,0 +1,60 @@
+cat(sprintf("\n-----------------\n%s\n", obj))
+## Objekti muutujale väärtuste omistamine, kui seda pole antud.
+if (is.null(obj)) {
+  obj <- "demo"
+}
+obj <- gsub(" ", "_", tolower(obj))
+## Konfiguratsiooni muutujale väärtuste omistamine, kui seda pole antud.
+if (is.null(conf)) {
+  conf <- ruut::get_config()
+  conf$schema <- obj
+}
+## Kontrollime kas objektil on andmebaas ja kas andmebaasis on piirjoon.
+if (ruut::db_is_shema_exist(schema = conf$schema)) {
+  piir_table_name <- "a00_piir"
+  pk <- NULL
+  if (piir_table_name %in% ruut::db_schema_tablenames(conf = conf)) {
+    conn <- ruut::db_connect(conf = conf)
+    try(pk <- sf::st_read(dsn = conn, layer = c(conf$schema, piir_table_name)))
+  }
+} else {
+  pk <- NULL
+}
+## Piirkonna muutujale väärtuste omistamine, kui seda pole antud.
+if (is.null(pk)) {
+  # geojson_txt <- paste('{"type":"MultiPoint","coordinates":[[658300,6474800],[658300,6475000],[658700,6476000],[659600,6475000],[659600,6474800],[658300,6474800]]}')
+  geojson_txt <- paste('{"type":"MultiPoint","coordinates":[[658400,6474800],[658300,6475000],[658700,6476000],[659600,6475000],[659600,6474800],[659200,6474950],[658400,6474800]]}')
+  pk <- sf::read_sf(geojson_txt)
+  pk <- sf::st_cast(pk, "POLYGON")
+  sf::st_crs(pk) <- 3301
+  attributes(pk)$names <- attributes(pk)$sf_column <- "geom"
+}
+## ------------- muutujad ja teisendused ---------------
+tmp_dir <- tempdir() # ajutine kataloog
+tmp_gpkg_file <- sprintf("%s/%s.gpkg", tmp_dir, obj) # ajutine gpkg fail
+conf$gpkg_home <- tmp_dir
+conf$gpkg_file <- obj
+## Loome lingid gpkg ajutistest tabelitest lugemiseks ja kirjutamiseks
+conf$gpkg_table <- layer_6 <- "test_layer_6"
+tmp_gpkg_file_output_6 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_6 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+conf$gpkg_table <- layer_5 <- "test_layer_5"
+tmp_gpkg_file_output_5 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_5 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+conf$gpkg_table <- layer_4 <- "test_layer_4"
+tmp_gpkg_file_output_4 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_4 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+conf$gpkg_table <- layer_3 <- "test_layer_3"
+tmp_gpkg_file_output_3 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_3 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+conf$gpkg_table <- layer_2 <- "test_layer_2"
+tmp_gpkg_file_output_2 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_2 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+conf$gpkg_table <- layer_1 <- "test_layer_1"
+tmp_gpkg_file_output_1 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+tmp_gpkg_file_input_1 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+# Loome ajutise gpkg faili koos ajutise tabeliga.
+sf::write_sf(pk, dsn = tmp_gpkg_file, layer = "test_layer_0", driver = "gpkg", fid_column_name = "id", delete_dsn = T)
+cat(sprintf("\n------------------\nAjutise gpkg faili asukoht: %s\n", tmp_gpkg_file))
+sf::st_layers(dsn = tmp_gpkg_file)
+# unlink(tmp_gpkg_file)