| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #' Muude teede teedevõ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_muud_teed(conf = conf)
- #' }
- minu_teed_muud_teed <- function(conf = NULL) {
- ## --------------------- muutujad ja teisendused -----------------------------
- vars <- ajutised_muutujad(conf = conf)
- conf <- vars$conf
- ## ------------------------- 1.1 Muud teed osadena ---------------------------
- ## Kasutame ETAK andmestikku 'e_501_tee_j'.
- ## s.o tyyp IN (50,60,).
- ## Esmalt sorteerime >= 50
- # 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' : 3, 'OUTPUT' : '%s', 'VALUE' : '50' }", 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))
- ## Seejärel sorteerime <= 60
- algorithm <- "native:extractbyattribute"
- input <- vars$tmp_gpkg_file_input_1
- output <- vars$tmp_gpkg_file_output_2
- str <- sprintf("{ 'FIELD' : 'tyyp', 'INPUT' : '%s', 'OPERATOR' : 5, 'OUTPUT' : '%s', 'VALUE' : '60' }", 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))
- ## Eemaldame need muud teed kus 'tee'=NULL (ilma teenumbrita ehk kvartalissisesed).
- algorithm <- "native:extractbyattribute"
- input <- vars$tmp_gpkg_file_input_2
- output <- vars$tmp_gpkg_file_output_3
- str <- sprintf("{ 'FIELD' : 'tee', 'INPUT' : '%s', 'OPERATOR' : 9, '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))
- ## ------------------ 1.2 Copy temp gpkg file to postgis ---------------------
- conf$schema <- "minu_teed"
- conf$table <- "teedevork_kt_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_3, "LINESTRING", conf$schema, conf$table)
- system(cmd)
- cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
- ## ----------------------- 2.1 Muud teed tervikuna ---------------------------
- ## Ühendame sama teenumbriga muud teed
- # ruut::qgis_algorithm_search_by_word("dissolve")
- algorithm <- "native:dissolve"
- # ruut::qgis_show_help(algorithm = algorithm)
- input <- vars$tmp_gpkg_file_input_3
- output <- vars$tmp_gpkg_file_output_4
- 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_4
- output <- vars$tmp_gpkg_file_output_5
- 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_kt"
- 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_5, "MULTILINESTRING", conf$schema, conf$table)
- system(cmd)
- cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
- ## ----------------- 3.1 Muude teede 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_5
- output <- vars$tmp_gpkg_file_output_6
- 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 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_6
- output <- vars$tmp_gpkg_file_output_7
- 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))
- ## ------------------ 3.3 Copy temp gpkg file to postgis ---------------------
- conf$schema <- "minu_teed"
- conf$table <- "teedevork_kt_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=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_7, "POINT", conf$schema, conf$table)
- system(cmd)
- cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
- ## ------------------- 4.1 Ilma tee numbrita muud teed -----------------------
- ## Leiame need muud teed kus 'tee'=NULL (ilma teenumbrita ehk kvartalissisesed).
- algorithm <- "native:extractbyattribute"
- input <- vars$tmp_gpkg_file_input_2
- output <- vars$tmp_gpkg_file_output_3
- str <- sprintf("{ 'FIELD' : 'tee', 'INPUT' : '%s', 'OPERATOR' : 8, '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))
- ## ................... 4.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_3
- output <- vars$tmp_gpkg_file_output_4
- cmd <- sprintf("qgis_process run %s --FIELDS='tyyp' --FIELDS='tyyp_t' --FIELDS='tee' --FIELDS='nimetus' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
- system(cmd)
- ## ------------------ 4.3 Copy temp gpkg file to postgis ---------------------
- conf$schema <- "minu_teed"
- conf$table <- "teedevork_kt_numbrita"
- 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_4, "LINESTRING", conf$schema, conf$table)
- system(cmd)
- cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
- ## ----------------- 4.4 Nimeta teede 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_4
- output <- vars$tmp_gpkg_file_output_5
- 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))
- ## ------------------- 4.5 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_5
- output <- vars$tmp_gpkg_file_output_6
- 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))
- ## ------------------ 4.6 Copy temp gpkg file to postgis ---------------------
- conf$schema <- "minu_teed"
- conf$table <- "teedevork_kt_numbrita_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=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_6, "POINT", conf$schema, conf$table)
- system(cmd)
- cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
- }
|