|
|
@@ -25,7 +25,9 @@ pk_lisame_jooned <- function(obj = NULL, conf = NULL) {
|
|
|
conf <- vars$conf
|
|
|
## Konfiguratsiooni muutujale väärtuste omistamine, kui seda pole antud.
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
@@ -36,66 +38,129 @@ pk_lisame_jooned <- function(obj = NULL, conf = NULL) {
|
|
|
|
|
|
## -------------------- Loop -----------------------
|
|
|
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"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "korvalmaantee"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "tugimaantee"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "muutee"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "ramp"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "teeosa"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "n_kergliiklustee"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "n_liiklussagedus"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "teeregister_wfs", "table" = "n_omand"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "gtfs", "table" = "shapes"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_203_vooluveekogu_j"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_305_puittaimestik_j"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_405_piire_j"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_501_tee_j"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_502_roobastee_j"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_505_liikluskorralduslik_rajatis_j"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "e_601_elektriliin_j"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "korgus_j"))
|
|
|
- andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "sild_j"))
|
|
|
- # andmed <- rbind(andmed, data.frame("schema" = "eesti", "table" = "sygavus_j"))
|
|
|
+ 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"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "korvalmaantee"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "tugimaantee"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "muutee"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "ramp"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "teeosa"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "n_kergliiklustee"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "n_liiklussagedus"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "teeregister_wfs", "table" = "n_omand"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed, data.frame("schema" = "gtfs", "table" = "shapes"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_203_vooluveekogu_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_305_puittaimestik_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_405_piire_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_501_tee_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_502_roobastee_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(
|
|
|
+ andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_505_liikluskorralduslik_rajatis_j")
|
|
|
+ )
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed,
|
|
|
+ data.frame("schema" = "eesti", "table" = "e_601_elektriliin_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed, data.frame("schema" = "eesti", "table" = "korgus_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed, data.frame("schema" = "eesti", "table" = "sild_j"))
|
|
|
+ andmed <-
|
|
|
+ rbind(andmed, data.frame("schema" = "eesti", "table" = "sygavus_j"))
|
|
|
for (intersect in intersect_layers) {
|
|
|
conf$table <- intersect
|
|
|
conf$schema <- obj
|
|
|
- intersect_layer <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_type = "Polygon", srid = 3301, checkPrimaryKeyUnicity = TRUE, key = "id")
|
|
|
+ intersect_layer <-
|
|
|
+ ruut::construct_to_gpkg_output_postgres_str(
|
|
|
+ conf = conf,
|
|
|
+ geometry_type = "Polygon",
|
|
|
+ srid = 3301,
|
|
|
+ checkPrimaryKeyUnicity = TRUE,
|
|
|
+ key = "id"
|
|
|
+ )
|
|
|
for (i in 1:nrow(andmed)) {
|
|
|
+ cat("\n\n\n==========================================\n\n")
|
|
|
+ cat(sprintf("Tabel: %s.%s", andmed[i, "schema"], andmed[i, "table"]))
|
|
|
+ cat("\n==========================================\n\n")
|
|
|
## teeregister_wfs andmebaasis on importimisel geomeetria välja tähistus 'geometry'.
|
|
|
- # if (andmed$schema[i] %in% c("teeregister_wfs")) geom <- "geometry" else geom <- "geom"
|
|
|
- if (andmed$schema[i] %in% c("gtfs")) geom <- "geometry" else geom <- "geom"
|
|
|
+ geom <- "geom"
|
|
|
+ # if (andmed$schema[i] %in% c("gtfs")) geom <- "geometry"
|
|
|
conf$table <- andmed$table[i]
|
|
|
conf$schema <- andmed$schema[i]
|
|
|
input <- ruut::construct_to_gpkg_output_postgres_str(
|
|
|
- conf = conf, geometry_type = "Linestring", srid = 3301,
|
|
|
- checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = geom
|
|
|
+ conf = conf,
|
|
|
+ geometry_type = "Linestring",
|
|
|
+ srid = 3301,
|
|
|
+ checkPrimaryKeyUnicity = TRUE,
|
|
|
+ key = "id",
|
|
|
+ geometry_field = geom
|
|
|
)
|
|
|
## 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("data_l_%s_%s", strtrim(as.character(andmed$schema[i]), 2), andmed$table[i])
|
|
|
+ conf$table <-
|
|
|
+ sprintf("data_l_%s_%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' : '' }")
|
|
|
+ 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' : '' }"
|
|
|
+ )
|
|
|
algorithm <- "native:intersection"
|
|
|
- cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ cmd <-
|
|
|
+ ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
cat(sprintf("\n%s\n\n", cmd))
|
|
|
system(cmd)
|
|
|
- ## Filtreerime mõned andmetabelid eraldi alamkihtideks
|
|
|
- if (andmed$table[i] == "n_liiklussagedus") {
|
|
|
- parent_table <-
|
|
|
- sprintf("data_a_%s_%s",
|
|
|
- strtrim(as.character(andmed$schema[i]), 2),
|
|
|
- andmed$table[i])
|
|
|
- conn <- ruut::db_connect(conf = conf)
|
|
|
- data <-
|
|
|
- unique(as.data.frame(sf::st_read(
|
|
|
- dsn = conn,
|
|
|
- layer = c(conf$schema, parent_table),
|
|
|
- as_tibble = T
|
|
|
- ))[, c("code", "fclass")])
|
|
|
- DBI::dbDisconnect(conn)
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
## Layers list
|