#' Piirkonnale andmebaasides olevate joonte lisamine #' #' Etteantud piirkonna geomeetrilise piirjoone ('piir') ja selle joone piirikasti ('bb') järele leitakse nende aladega kaetud polügoonid. Andmed salvestatakse GPKG faili kihtidena. #' #' @param obj str Objekti nimi. Edaspidi on oluline ainult see nimi. Piirkonna geomeetrilist joont ei ole vaja lisada. #' @param gpkg_home path Salvestatavate GPKG faili asukoht. #' @return Uute GPKG andmebaasi kihtide 'piir_...' ja 'bb_...' loomine. #' @seealso [sf::st_read()], [sf::write_sf()],[sf::st_transform()],[ruut::gpkg_piirkonnale_ruudustike_lisamine()] ,[ruut::gpkg_piirkonnale_polygoonide_lisamine()],[ruut::gpkg_sellest_alustame_gpkg_loomist()],[ruut::gpkg_piirkonnale_joonte_lisamine()],[ruut::gpkg_piirkonnale_punktide_lisamine()] #' @keywords GPKG, boundary box, EPSG:3301 #' @export #' @examples #' \dontrun{ #' #' gpkg_home <- "/tmp" #' obj <- "marja" #' gpkg_piirkonnale_joonte_lisamine(obj = obj, gpkg_home = gpkg_home) #' #' # Layers list. #' dsn <- sprintf("%s/%s.gpkg", gpkg_home, obj) #' sf::st_layers(dsn = dsn) #' } gpkg_piirkonnale_joonte_lisamine <- function(obj = NULL, gpkg_home = "/tmp") { dsn <- sprintf("%s/%s.gpkg", gpkg_home, obj) if (!file.exists(dsn)) { cat(sprintf("\nSellist faili \"%s\" ei leitud.\n", dsn)) return(NULL) } ## Konfiguratsiooni muutujale väärtuste omistamine conf <- ruut::get_config() tmp_gpkg_file <- tempfile(fileext = ".gpkg") conf$gpkg_home <- dirname(tmp_gpkg_file) conf$gpkg_file <- gsub(paste0(conf$gpkg_home, "/"), "", tmp_gpkg_file) conf$gpkg_file <- gsub(".gpkg", "", conf$gpkg_file) conf$gpkg_home <- gpkg_home conf$gpkg_file <- obj 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) ## Algorithm # ruut::qgis_algorithm_search_by_word(str = "extract") # algorithm <- "native:extractbylocation" # cat(qgisprocess::qgis_show_help(algorithm = algorithm)) ## -------------------- Loop ----------------------- intersect_layers <- c("piir", "bb") intersect_layers <- c("bb") 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$gpkg_table <- intersect intersect_layer <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T) for (i in 1:nrow(andmed)) { ## teeregister_wfs andmebaasis on importimisel geomeetria välja tähistus 'geometry'. if (andmed$schema[i] %in% c("teeregister_wfs")) geom <- "geometry" else geom <- "geom" conf$gpkg_table <- sprintf("%s_%s", intersect, andmed$table[i]) conf$table <- andmed$table[i] conf$schema <- andmed$schema[i] output <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F) input <- ruut::construct_to_gpkg_output_postgres_str( conf = conf, geometry_type = "Linestring", srid = 3301, checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = geom ) ## !!! Trikk: alguses leiame ühisosaga piirkonnad ## !!! Trikk: alguses leiame ühisosaga piirkonnad ## ------------------- QGIS: qgisprocess ---------------------- str <- paste0("{ 'INPUT' : '", input, "', 'INTERSECT' : '", intersect_layer, "', 'OUTPUT' : '", tmp_gpkg_file_output, "', 'PREDICATE' : [0] }") algorithm <- "native:extractbylocation" cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm) cat(sprintf("\n%s\n\n", cmd)) system(cmd) ## !!! Trikk jätkub: edasi leiame alles ühisosa str <- paste0("{ 'INPUT' : '", tmp_gpkg_file_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) cat(sprintf("\n%s\n\n", cmd)) system(cmd) } } ## Layers list sf::st_layers(dsn = dsn) }