minu_teed_eesti.R 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #' Eesti kontuuri loomine teedevõrgu piiriks
  2. #'
  3. #' EHAk (Eesti haldus- ja asustusjaotus) \url{https://geoportaal.maaamet.ee/est/Andmed-ja-kaardid/Haldus-ja-asustusjaotus-p119.html} andmete põhjal
  4. #'
  5. #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
  6. #' @return No output.
  7. #' @seealso [ruut::get_config()], [ruut::copy_shp_to_db()], [estmap::minu_teed_riigiteed()], [estmap::minu_teed_muud_teed()], [estmap::minu_teed_eesti()]
  8. #' @keywords postgis
  9. #' @export
  10. #' @examples
  11. #' \dontrun{
  12. #'
  13. #' conf <- ruut::get_config()
  14. #' minu_teed_eesti(conf = conf)
  15. #' }
  16. minu_teed_eesti <- function(conf = NULL) {
  17. ## --------------------- muutujad ja teisendused -----------------------------
  18. vars <- ajutised_muutujad(conf = conf)
  19. conf <- vars$conf
  20. ## -------------------- 1.1 Eesti riigipiir (osadeta) ------------------------
  21. ## Kasutame ETAK andmestikku 'maaamet.maakond'.
  22. ## Maakondadest Eesti maismaapiir
  23. # ruut::qgis_algorithm_search_by_word("dissolve")
  24. algorithm <- "native:dissolve"
  25. # ruut::qgis_show_help(algorithm = algorithm)
  26. conf$schema <- "maaamet"
  27. conf$table <- "maakond"
  28. input <- ruut::construct_to_gpkg_output_postgres_str(
  29. conf = conf, geometry_type = "MultiPolygon", srid = 3301,
  30. checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = "geom"
  31. )
  32. output <- vars$tmp_gpkg_file_output_1
  33. str <- sprintf("{ 'FIELD' : [], 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
  34. cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
  35. system(cmd)
  36. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  37. ## ------------------ 1.2 Kustutame ebaolulised väljad -----------------------
  38. # ruut::qgis_algorithm_search_by_word("delete")
  39. algorithm <- "native:deletecolumn"
  40. # ruut::qgis_show_help(algorithm = algorithm)
  41. input <- vars$tmp_gpkg_file_input_1
  42. output <- vars$tmp_gpkg_file_output_2
  43. cmd <- sprintf("qgis_process run %s --COLUMN='mnimi' --COLUMN='mkood' --COLUMN='fid' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
  44. system(cmd)
  45. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  46. ## -------- 1.3 Jaotame multipart polügooni singlepart polügoonideks ---------
  47. # ruut::qgis_algorithm_search_by_word("multipart")
  48. algorithm <- "native:multiparttosingleparts"
  49. # ruut::qgis_show_help(algorithm = algorithm)
  50. input <- vars$tmp_gpkg_file_input_2
  51. output <- vars$tmp_gpkg_file_output_3
  52. str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
  53. cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
  54. system(cmd)
  55. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  56. ## -------------- 1.4 Lisame pindade pindalad ja perimeetri ------------------
  57. # ruut::qgis_algorithm_search_by_word("columns")
  58. algorithm <- "qgis:exportaddgeometrycolumns"
  59. # ruut::qgis_show_help(algorithm = algorithm)
  60. input <- vars$tmp_gpkg_file_input_3
  61. output <- vars$tmp_gpkg_file_output_4
  62. str <- sprintf("{ 'CALC_METHOD' : 0, 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
  63. cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
  64. system(cmd)
  65. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  66. ## -- 1.5 Eemaldame objektid mille pindala on väiksem kui 10km2 (väikesaared) --
  67. # ruut::qgis_algorithm_search_by_word("extract")
  68. algorithm <- "native:extractbyattribute"
  69. # ruut::qgis_show_help(algorithm = algorithm)
  70. input <- vars$tmp_gpkg_file_input_4
  71. output <- vars$tmp_gpkg_file_output_5
  72. str <- sprintf("{ 'FIELD' : 'area', 'OPERATOR' : 2, 'VALUE' : '10000000', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
  73. cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
  74. system(cmd)
  75. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  76. ## ------------ 1.6 Eemaldame augud, mis on suuremad kui 1ha -----------------
  77. # ruut::qgis_algorithm_search_by_word("holes")
  78. algorithm <- "native:deleteholes"
  79. # ruut::qgis_show_help(algorithm = algorithm)
  80. input <- vars$tmp_gpkg_file_input_5
  81. output <- vars$tmp_gpkg_file_output_6
  82. str <- sprintf("{ 'MIN_AREA' : '10000', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
  83. cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
  84. system(cmd)
  85. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
  86. ## ------------------ 1.2 Copy temp gpkg file to postgis ---------------------
  87. conf$schema <- "minu_teed"
  88. conf$table <- "eesti"
  89. PG <- ruut::construct_ogr2ogr_PG_connect_str(conf = conf)
  90. 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_6, "MULTIPOLYGON", conf$schema, conf$table)
  91. system(cmd)
  92. cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
  93. }