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)