epk_grids.R 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #' Kõikide kaardiruudukeste genereerimine
  2. #'
  3. #' Eesti projektsioonile vastava ning kogu Eestit katva ruutvõrgustiku genereerimine ja salvestamine andmebaasi. Valikud on 'postgis' ja 'gpkg'. Ruutvõrgustike ruutude suuruse on 100x100 km, 5x5 km, 1x1 km ja 100x100 mmeetrid, lisaks ruudukastide piirjoon.. Võrgustik salvestatakse vaikimisi andmebaasi nime postgisi andmebaasi 'data' schema 'maaamet' alla või gpkg andmebaasid kataloogi '/data/gpkg'. Loe: \url{https://geoportaal.maaamet.ee/est/Ruumiandmed/Kaardilehtede-susteemid-p224.html}. Koniguratsiooni muutmiseks muuda konfiguratsiooni faili.
  4. #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
  5. #' @param output_format format_name: output file format name, possible values are:
  6. #' - "GPKG"
  7. #' - "PostgreSQL" (Default)
  8. #' @return String.
  9. #' @seealso [ruut::get_config()], [ruut::construct_to_gpkg_output_file_str()], [ruut::construct_to_gpkg_output_postgres_str()]
  10. #' @keywords postgis, gpkg
  11. #' @export
  12. #' @examples
  13. #' \dontrun{
  14. #'
  15. #' # Postgresql output
  16. #' conf <- ruut::get_config()
  17. #' conf$schema <- "maaamet"
  18. #' conf$table <- "epk200t_bb"
  19. #' output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  20. #' epk_grids(conf = conf, output_format = "PostgreSQL")
  21. #'
  22. #' # GPKG output
  23. #' conf <- ruut::get_config()
  24. #' conf$gpkg_home <- "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa"
  25. #' conf$gpkg_file <- "ruudud"
  26. #' conf$gpkg_table <- "epk200t_bb"
  27. #' output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  28. #' epk_grids(conf = conf, output_format = "GPKG")
  29. #' }
  30. epk_grids <- function(conf = NULL, output_format = "PostgreSQL") {
  31. # Export to postgis
  32. if (is.null(conf)) {
  33. conf <- ruut::get_config()
  34. conf$schema <- "maaamet"
  35. conf$gpkg_home <- "/data/gpkg"
  36. conf$gpkg_file <- "ruudud"
  37. }
  38. conf$table <- conf$gpkg_table <- "epk200t_bb"
  39. if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  40. if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  41. # ruut::qgis_algorithm_search_by_word(str = "grid")
  42. algorithm <- "native:creategrid"
  43. # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
  44. result <- qgisprocess::qgis_run_algorithm(
  45. algorithm = algorithm,
  46. CRS = "EPSG:3301",
  47. EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
  48. HOVERLAY = 0,
  49. HSPACING = 500000,
  50. OUTPUT = output,
  51. TYPE = 2,
  52. VOVERLAY = 0,
  53. VSPACING = 400000
  54. # .quiet = TRUE
  55. )
  56. conf$table <- conf$gpkg_table <- "epk200t_grid"
  57. if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  58. if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  59. result <- qgisprocess::qgis_run_algorithm(
  60. algorithm = algorithm,
  61. CRS = "EPSG:3301",
  62. EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
  63. HOVERLAY = 0,
  64. HSPACING = 100000,
  65. OUTPUT = output,
  66. TYPE = 2,
  67. VOVERLAY = 0,
  68. VSPACING = 100000
  69. # .quiet = TRUE
  70. )
  71. conf$table <- conf$gpkg_table <- "epk2t_grid"
  72. if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  73. if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  74. result <- qgisprocess::qgis_run_algorithm(
  75. algorithm = algorithm,
  76. CRS = "EPSG:3301",
  77. EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
  78. HOVERLAY = 0,
  79. HSPACING = 1000,
  80. OUTPUT = output,
  81. TYPE = 2,
  82. VOVERLAY = 0,
  83. VSPACING = 1000
  84. # .quiet = TRUE
  85. )
  86. conf$table <- conf$gpkg_table <- "epk10t_grid"
  87. if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  88. if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  89. result <- qgisprocess::qgis_run_algorithm(
  90. algorithm = algorithm,
  91. CRS = "EPSG:3301",
  92. EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
  93. HOVERLAY = 0,
  94. HSPACING = 5000,
  95. OUTPUT = output,
  96. TYPE = 2,
  97. VOVERLAY = 0,
  98. VSPACING = 5000
  99. # .quiet = TRUE
  100. )
  101. conf$table <- conf$gpkg_table <- "epk02t_grid"
  102. if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
  103. if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
  104. result <- qgisprocess::qgis_run_algorithm(
  105. algorithm = algorithm,
  106. CRS = "EPSG:3301",
  107. EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
  108. HOVERLAY = 0,
  109. HSPACING = 100,
  110. OUTPUT = output,
  111. TYPE = 2,
  112. VOVERLAY = 0,
  113. VSPACING = 100
  114. # .quiet = TRUE
  115. )
  116. cat(sprintf("\nAndmed salvestati asukohta: %s.\n\n", output))
  117. }