|
@@ -18,39 +18,24 @@
|
|
|
#' ruut::db_schema_tablenames(conf = conf)
|
|
#' ruut::db_schema_tablenames(conf = conf)
|
|
|
#' }
|
|
#' }
|
|
|
pk_lisame_punktid <- function(obj = NULL, conf = NULL) {
|
|
pk_lisame_punktid <- 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.
|
|
## 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")
|
|
cat("\nAndmebaas loomata. Palun funktsiooniga ruut::pk_sellest_alustame_db_loomist() andmebaasi loomist.\n")
|
|
|
return(NULL)
|
|
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
|
|
## Algorithm
|
|
|
# ruut::qgis_algorithm_search_by_word(str = "extract")
|
|
# ruut::qgis_algorithm_search_by_word(str = "extract")
|
|
|
# algorithm <- "native:extractbylocation"
|
|
# algorithm <- "native:extractbylocation"
|
|
|
# cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
# cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
|
|
|
|
|
|
## -------------------- Loop -----------------------
|
|
## -------------------- 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 <- data.frame("schema" = character(0), "table" = character(0))
|
|
|
andmed <- rbind(andmed, data.frame("schema" = "maaamet", "table" = "aadressandmed")) # POINT
|
|
andmed <- rbind(andmed, data.frame("schema" = "maaamet", "table" = "aadressandmed")) # POINT
|
|
|
andmed <- rbind(andmed, data.frame("schema" = "osm_shp", "table" = "pofw"))
|
|
andmed <- rbind(andmed, data.frame("schema" = "osm_shp", "table" = "pofw"))
|
|
@@ -88,7 +73,7 @@ pk_lisame_punktid <- function(obj = NULL, conf = NULL) {
|
|
|
conf = conf, geometry_type = "Point", srid = 3301,
|
|
conf = conf, geometry_type = "Point", srid = 3301,
|
|
|
checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = geom
|
|
checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = geom
|
|
|
)
|
|
)
|
|
|
- conf$table <- sprintf("%s", andmed$table[i])
|
|
|
|
|
|
|
+ conf$table <- sprintf("%s_p_%s", strtrim(as.character(andmed$schema[i]), 2), andmed$table[i])
|
|
|
conf$schema <- obj
|
|
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")
|
|
output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_field = "geom", geometry_type = NULL, srid = 3301, checkPrimaryKeyUnicity = FALSE, key = "id")
|
|
|
## ------------------- QGIS: qgisprocess ----------------------
|
|
## ------------------- QGIS: qgisprocess ----------------------
|
|
@@ -99,8 +84,9 @@ pk_lisame_punktid <- function(obj = NULL, conf = NULL) {
|
|
|
system(cmd)
|
|
system(cmd)
|
|
|
## Filtreerime aadressandmete kihi eraldi alamkihtideks
|
|
## Filtreerime aadressandmete kihi eraldi alamkihtideks
|
|
|
if (andmed$table[i] == "aadressandmed") {
|
|
if (andmed$table[i] == "aadressandmed") {
|
|
|
- aadressandmed <- unique(as.data.frame(sf::st_read(dsn = conn, layer = c(conf$schema, as.character(andmed$table[i])), as_tibble = T))[, c("adob_liik"), drop = FALSE])
|
|
|
|
|
- parent_table <- as.character(andmed$table[i])
|
|
|
|
|
|
|
+ parent_table <- sprintf("%s_p_%s", strtrim(as.character(andmed$schema[i]), 2), andmed$table[i])
|
|
|
|
|
+ conn <- ruut::db_connect(conf = conf)
|
|
|
|
|
+ aadressandmed <- unique(as.data.frame(sf::st_read(dsn = conn, layer = c(conf$schema, parent_table), as_tibble = T))[, c("adob_liik"), drop = FALSE])
|
|
|
for (k in 1:nrow(aadressandmed)) {
|
|
for (k in 1:nrow(aadressandmed)) {
|
|
|
table_suffix <- aadressandmed$adob_liik[k]
|
|
table_suffix <- aadressandmed$adob_liik[k]
|
|
|
conf$table <- parent_table
|
|
conf$table <- parent_table
|
|
@@ -121,5 +107,5 @@ pk_lisame_punktid <- function(obj = NULL, conf = NULL) {
|
|
|
## Layers list
|
|
## Layers list
|
|
|
conf$schema <- obj
|
|
conf$schema <- obj
|
|
|
ruut::db_schema_tablenames(conf = conf)
|
|
ruut::db_schema_tablenames(conf = conf)
|
|
|
- sf::st_layers(dsn = tmp_gpkg_file)
|
|
|
|
|
|
|
+ sf::st_layers(dsn = vars$tmp_gpkg_file)
|
|
|
}
|
|
}
|