Selaa lähdekoodia

Töötav 'gpkg_piirkonnale_ruudustike_lisamine'.

Ardo Kubjas 5 vuotta sitten
vanhempi
sitoutus
b87b37632b

+ 3 - 0
R/construct_qgis_output_result_to_beter_format.R

@@ -53,6 +53,9 @@ construct_qgis_output_result_to_beter_format <- function(str = "", algorithm = "
   str <- gsub(", ", " ", str)
   # Asendame algoritmi
   str <- gsub("algorithm", algorithm, str)
+  # Nurksulgude asendamine
+  str <- gsub("[[]", "\"", str)
+  str <- gsub("[]]", "\"", str)
   cat(str)
   str
 }

+ 16 - 17
R/gpkg_piirkonnale_ruudustike_lisamine.R

@@ -29,33 +29,32 @@ gpkg_piirkonnale_ruudustike_lisamine <- function(obj = NULL, gpkg_home = "/tmp")
   conf <- ruut::get_config()
   conf$gpkg_home <- gpkg_home
   conf$gpkg_file <- obj
-  postgres <- sprintf(
-    "postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'id\' srid=3301 type=Polygon checkPrimaryKeyUnicity=\'1\' ",
-    conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password
-  )
   ## Algorithm
   # ruut::qgis_algorithm_search_by_word(str = "extract")
   algorithm <- "native:extractbylocation"
-  # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
-
+  # cat(ruut::qgis_show_help(algorithm = algorithm))
   ## -------------------- Loop -----------------------
   intersect_layers <- c("piir", "bb")
   ruudud <- c("epk10t_grid", "epk2t_grid", "epk02t_grid", "epk10t", "epk2t")
-  ruudud <- c("epk02t_grid")
+  conf$schema <- "maaamet"
+  # ruudud <- c("epk02t_grid")
   for (intersect in intersect_layers) {
+    conf$gpkg_table <- intersect
+    intersect_layer <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
     for (ruut in ruudud) {
+      conf$table <- ruut
+      input <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_type = "MultiPolygon", checkPrimaryKeyUnicity = T, key = "id", srid = 3301)
       conf$gpkg_table <- sprintf("%s_%s", intersect, ruut)
-      output <- ruut::construct_to_gpkg_output_file_str(conf = conf)
-      result <- qgisprocess::qgis_run_algorithm(
-        algorithm = algorithm,
-        INPUT = sprintf(
-          '%s table=\"%s\".\"%s\" (geom)',
-          postgres, "maaamet", ruut
-        ),
-        INTERSECT = sprintf("%s|layername=%s", dsn, intersect),
-        OUTPUT = output,
-        PREDICATE = c(0)
+      output <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
+      input <- ruut::construct_to_gpkg_output_postgres_str(
+        conf = conf, geometry_type = "Polygon", srid = 3301,
+        checkPrimaryKeyUnicity = TRUE, key = "id"
       )
+      ## ------------------- QGIS: qgisprocess ----------------------
+      str <- paste0("{ 'INPUT' : '", input, "', 'INTERSECT' : '", intersect_layer, "', 'OUTPUT' : '", output, "', 'PREDICATE' : [0] }")
+      cmd <- ruut::construct_qgis_output_result_to_beter_format(str = str, algorithm = algorithm)
+      cat(sprintf("\n%s\n", cmd))
+      system(cmd)
     }
   }
   ## Layers list