Ver Fonte

Muudetud 'epk_grids'.

Ardo Kubjas há 5 anos atrás
pai
commit
414d40b57f
3 ficheiros alterados com 25 adições e 69 exclusões
  1. 1 1
      DESCRIPTION
  2. 23 67
      R/epk_grids.R
  3. 1 1
      man/epk_grids.Rd

+ 1 - 1
DESCRIPTION

@@ -12,4 +12,4 @@ Encoding: UTF-8
 LazyData: true
 Roxygen: list(markdown = TRUE)
 RoxygenNote: 7.1.1.9000
-Imports: ruut, qgisprocess, DBI, pool, RPostgreSQL, sf, raster, stars, rgdal, tidyverse, inborutils, rvest, seleniumPipes, rjson, methods, utils, jsonlite, urltools, magrittr, stringr, xml2, purrr, readr, rgeos, sp, dplyr, rlang
+Imports: ruut, DBI, pool, RPostgreSQL, sf, raster, stars, rgdal, tidyverse, inborutils, rvest, seleniumPipes, rjson, methods, utils, jsonlite, urltools, magrittr, stringr, xml2, purrr, readr, rgeos, sp, dplyr, rlang

+ 23 - 67
R/epk_grids.R

@@ -16,7 +16,7 @@
 #' conf <- ruut::get_config()
 #' conf$schema <- "maaamet"
 #' conf$table <- "epk200t_bb"
-#' output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+#' output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
 #' epk_grids(conf = conf, output_format = "PostgreSQL")
 #'
 #' # GPKG output
@@ -34,85 +34,41 @@ epk_grids <- function(conf = NULL, output_format = "PostgreSQL") {
     conf$schema <- "maaamet"
     conf$gpkg_home <- "/data/gpkg"
     conf$gpkg_file <- "ruudud"
+    conf$primary_key <- "id"
   }
 
   conf$table <- conf$gpkg_table <- "epk200t_bb"
-  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
   if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
   # ruut::qgis_algorithm_search_by_word(str = "grid")
   algorithm <- "native:creategrid"
-  # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
-  result <- qgisprocess::qgis_run_algorithm(
-    algorithm = algorithm,
-    CRS = "EPSG:3301",
-    EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
-    HOVERLAY = 0,
-    HSPACING = 500000,
-    OUTPUT = output,
-    TYPE = 2,
-    VOVERLAY = 0,
-    VSPACING = 400000
-    # .quiet = TRUE
-  )
+  # ruut::qgis_show_help(algorithm = algorithm)
+  str <- sprintf("{ 'CRS' : 'epsg:3301', 'EXTENT' : '300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG:3301]', 'HOVERLAY' : 0, 'HSPACING' : 500000, 'OUTPUT' : '%s', 'TYPE' : 2, 'VOVERLAY' : 0, 'VSPACING' : 400000 }", output)
+  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  system(cmd)
   conf$table <- conf$gpkg_table <- "epk200t_grid"
-  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
   if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
-  result <- qgisprocess::qgis_run_algorithm(
-    algorithm = algorithm,
-    CRS = "EPSG:3301",
-    EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
-    HOVERLAY = 0,
-    HSPACING = 100000,
-    OUTPUT = output,
-    TYPE = 2,
-    VOVERLAY = 0,
-    VSPACING = 100000
-    # .quiet = TRUE
-  )
+  str <- sprintf("{ 'CRS' : 'epsg:3301', 'EXTENT' : '300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG:3301]', 'HOVERLAY' : 0, 'HSPACING' : 100000, 'OUTPUT' : '%s', 'TYPE' : 2, 'VOVERLAY' : 0, 'VSPACING' : 100000 }", output)
+  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  system(cmd)
   conf$table <- conf$gpkg_table <- "epk2t_grid"
-  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
   if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
-  result <- qgisprocess::qgis_run_algorithm(
-    algorithm = algorithm,
-    CRS = "EPSG:3301",
-    EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
-    HOVERLAY = 0,
-    HSPACING = 1000,
-    OUTPUT = output,
-    TYPE = 2,
-    VOVERLAY = 0,
-    VSPACING = 1000
-    # .quiet = TRUE
-  )
+  str <- sprintf("{ 'CRS' : 'epsg:3301', 'EXTENT' : '300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG:3301]', 'HOVERLAY' : 0, 'HSPACING' : 1000, 'OUTPUT' : '%s', 'TYPE' : 2, 'VOVERLAY' : 0, 'VSPACING' : 1000 }", output)
+  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  system(cmd)
   conf$table <- conf$gpkg_table <- "epk10t_grid"
-  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
   if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
-  result <- qgisprocess::qgis_run_algorithm(
-    algorithm = algorithm,
-    CRS = "EPSG:3301",
-    EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
-    HOVERLAY = 0,
-    HSPACING = 5000,
-    OUTPUT = output,
-    TYPE = 2,
-    VOVERLAY = 0,
-    VSPACING = 5000
-    # .quiet = TRUE
-  )
+  str <- sprintf("{ 'CRS' : 'epsg:3301', 'EXTENT' : '300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG:3301]', 'HOVERLAY' : 0, 'HSPACING' : 5000, 'OUTPUT' : '%s', 'TYPE' : 2, 'VOVERLAY' : 0, 'VSPACING' : 5000 }", output)
+  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  system(cmd)
   conf$table <- conf$gpkg_table <- "epk02t_grid"
-  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+  if (tolower(output_format) == "postgresql") output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
   if (tolower(output_format) == "gpkg") output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
-  result <- qgisprocess::qgis_run_algorithm(
-    algorithm = algorithm,
-    CRS = "EPSG:3301",
-    EXTENT = "300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG=3301]",
-    HOVERLAY = 0,
-    HSPACING = 100,
-    OUTPUT = output,
-    TYPE = 2,
-    VOVERLAY = 0,
-    VSPACING = 100
-    # .quiet = TRUE
-  )
+  str <- sprintf("{ 'CRS' : 'epsg:3301', 'EXTENT' : '300000.000000000,800000.000000000,6300000.000000000,6700000.000000000 [EPSG:3301]', 'HOVERLAY' : 0, 'HSPACING' : 100, 'OUTPUT' : '%s', 'TYPE' : 2, 'VOVERLAY' : 0, 'VSPACING' : 100 }", output)
+  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  system(cmd)
   cat(sprintf("\nAndmed salvestati asukohta: %s.\n\n", output))
 }

+ 1 - 1
man/epk_grids.Rd

@@ -28,7 +28,7 @@ Eesti projektsioonile vastava ning kogu Eestit katva ruutvõrgustiku genereerimi
 conf <- ruut::get_config()
 conf$schema <- "maaamet"
 conf$table <- "epk200t_bb"
-output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf)
+output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, key = "id")
 epk_grids(conf = conf, output_format = "PostgreSQL")
 
 # GPKG output