#' Riigiteedevõrgu loomine #' #' ETAK (Eesti topograafia andmekogu) \url{https://geoportaal.maaamet.ee/est/Ruumiandmed/Eesti-topograafia-andmekogu/Laadi-ETAK-andmed-alla-p609.html} andmete põhjal #' #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}. #' @return No output. #' @seealso [ruut::get_config()], [ruut::copy_shp_to_db()], [estmap::minu_teed_riigiteed()], [estmap::minu_teed_muud_teed()], [estmap::minu_teed_eesti()] #' @keywords postgis #' @export #' @examples #' \dontrun{ #' #' conf <- ruut::get_config() #' minu_teed_riigiteed(conf = conf) #' } minu_teed_riigiteed <- function(conf = NULL) { ## --------------------- muutujad ja teisendused ----------------------------- vars <- ajutised_muutujad(conf = conf) conf <- vars$conf ## ------------------------- 1.1 Riigiteed osadena --------------------------- ## Kasutame ETAK andmestikku 'e_501_tee_j'. ## s.o (ilma rampideta) <= 30, koos rampide ja muude riigiteedega <= 45. # ruut::qgis_algorithm_search_by_word("extract") algorithm <- "native:extractbyattribute" # ruut::qgis_show_help(algorithm = algorithm) conf$schema <- "eesti" conf$table <- "e_501_tee_j" input <- ruut::construct_to_gpkg_output_postgres_str( conf = conf, geometry_type = "MultiLineString", srid = 3301, checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = "geom" ) output <- vars$tmp_gpkg_file_output_1 str <- sprintf("{ 'FIELD' : 'tyyp', 'INPUT' : '%s', 'OPERATOR' : 5, 'OUTPUT' : '%s', 'VALUE' : '45' }", input, output) cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output)) ## ------------------ 1.2 Copy temp gpkg file to postgis --------------------- conf$schema <- "minu_teed" conf$table <- "teedevork_riigiteed_osadena" PG <- ruut::construct_ogr2ogr_PG_connect_str(conf = conf) cmd <- sprintf("ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL %s -lco DIM=2 %s %s -overwrite -nlt %s -lco GEOMETRY_NAME=geom -lco FID=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_1, "LINESTRING", conf$schema, conf$table) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table)) ## ----------------------- 2.1 Riigiteed tervikuna --------------------------- # ruut::qgis_algorithm_search_by_word("dissolve") algorithm <- "native:dissolve" # ruut::qgis_show_help(algorithm = algorithm) input <- vars$tmp_gpkg_file_input_1 output <- vars$tmp_gpkg_file_output_2 str <- sprintf("{ 'FIELD' : 'tee', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output) cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output)) ## ------------------- 2.2 Eemaldame ebavajalikud veerud --------------------- # ruut::qgis_algorithm_search_by_word("retain") algorithm <- "native:retainfields" # ruut::qgis_show_help(algorithm = algorithm) input <- vars$tmp_gpkg_file_input_2 output <- vars$tmp_gpkg_file_output_3 cmd <- sprintf("qgis_process run %s --FIELDS='tyyp' --FIELDS='tyyp_t' --FIELDS='tee' --FIELDS='nimetus' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output)) ## ------------------ 2.3 Copy temp gpkg file to postgis --------------------- conf$schema <- "minu_teed" conf$table <- "teedevork_riigiteed" PG <- ruut::construct_ogr2ogr_PG_connect_str(conf = conf) cmd <- sprintf("ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL %s -lco DIM=2 %s %s -overwrite -nlt %s -lco GEOMETRY_NAME=geom -lco FID=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_3, "MULTILINESTRING", conf$schema, conf$table) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table)) ## ----------------- 3.1 Riigiteede alg- ja lõpppunkt ----------------------- # ruut::qgis_algorithm_search_by_word("vertices") algorithm <- "native:extractspecificvertices" # ruut::qgis_show_help(algorithm = algorithm) input <- vars$tmp_gpkg_file_input_3 output <- vars$tmp_gpkg_file_output_4 str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s', , 'VERTICES' : \"0,-1\" }", input, output) cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output)) ## ------------------ 3.2 Copy temp gpkg file to postgis --------------------- conf$schema <- "minu_teed" conf$table <- "teedevork_riigiteed_p" PG <- ruut::construct_ogr2ogr_PG_connect_str(conf = conf) cmd <- sprintf("ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL %s -lco DIM=2 %s %s -overwrite -nlt %s -lco GEOMETRY_NAME=geom -lco FID=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_4, "POINT", conf$schema, conf$table) system(cmd) cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table)) }