Ver código fonte

Lisatud 'minu_teed_graaf'.

Ardo Kubjas 5 anos atrás
pai
commit
fac4770c2c

+ 2 - 0
NAMESPACE

@@ -1,5 +1,6 @@
 # Generated by roxygen2: do not edit by hand
 
+export(LOEMIND)
 export(epk_grids)
 export(gtfs)
 export(inspire_grids)
@@ -12,6 +13,7 @@ export(maaamet_kataster)
 export(maaamet_mullakaart)
 export(maaamet_ortofotod)
 export(minu_teed_eesti)
+export(minu_teed_graaf)
 export(minu_teed_loomine)
 export(minu_teed_muud_teed)
 export(minu_teed_riigiteed)

+ 22 - 1
R/LOEMIND.R

@@ -12,7 +12,28 @@
 LOEMIND <- function() {
   cat("\n1. Pluginate nimekiri, mida saab käsuliinilt käivitada.\n")
   cmd <- "qgis_process plugins"
-  cat(sprintf("Command: %s\n", cmd))
+  cat(sprintf("    Command: %s\n", cmd))
   system(cmd)
+
+
+  pluginate_asukoht_1 <- '/usr/share/qgis/python/plugins/processing/algs'
+  pluginate_asukoht_2 <- '/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins'
+  cat(sprintf("\n2. Pluginate asukohad: '%s' (tuuma pluginad) ja '%s' (kasutaja poolt lisatud pluginad).\n", pluginate_asukoht_1, pluginate_asukoht_2))
+  cmd <- sprintf("ls %s; ls %s", pluginate_asukoht_2, pluginate_asukoht_1)
+  cat(sprintf("    Command: %s\n", cmd))
+  system(cmd)
+
+  cat(sprintf("\n3. Algoritmide nimekiri.\n"))
+  cmd <- "qgis_process list"
+  cat(sprintf("    Command: %s\n", cmd))
+  system(cmd)
+
+  cat(sprintf("\n4. !!!!!!!!!!!! Juhul kui plugin on instaleeritud, kuid käsk qgis_process run...' annab teate, et algoritm ei ole leitav ja samuti ei ole plugin pluginate nimekirjas ega algoritma algorimide nimekirjas, siis tuleb lisatud plugina kataloogis olevasse faili metadata.txt (https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/plugins/plugins.html#plugin-metadata-table + otsing \"qgis_process is not showing algorithm providers installed via a python plugin\") lisada järgmine rida:\n\n          hasProcessingProvider=yes\n\n!!!!!!!!!!!!\n"))
+
+  cat("\n5. Käsu 'qgis_process' help.\n")
+  cmd <- "qgis_process"
+  cat(sprintf("    Command: %s\n", cmd))
+  system(cmd)
+
 }
 # LOEMIND()

+ 1 - 1
R/ajutised_muutujad.R

@@ -6,7 +6,7 @@ ajutised_muutujad <- function(conf) {
     conf <- ruut::get_config()
   }
   ## Defineerime ajutised failid ja muutujad.
-  tmp_dir <- tempdir() # ajutine kataloog
+  l[["tmp_dir"]] <- tmp_dir <- tempdir() # ajutine kataloog
   obj <- "demo"
   l[["tmp_gpkg_file"]] <- tmp_gpkg_file <- sprintf("%s/%s.gpkg", tmp_dir, obj) # ajutine gpkg fail
   conf$gpkg_home <- tmp_dir

+ 143 - 0
R/minu_teed_graaf.R

@@ -0,0 +1,143 @@
+#' Riigiteedevõrgu graafide loomine (nodes and links)
+#'
+#' 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_graaf()], [estmap::minu_teed_muud_teed()], [estmap::minu_teed_eesti()]
+#' @keywords postgis
+#' @export
+#' @examples
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' minu_teed_graaf(conf = conf)
+#' }
+minu_teed_graaf <- function(conf = NULL) {
+  ## --------------------- muutujad ja teisendused -----------------------------
+  # source("R/ajutised_muutujad.R")
+  vars <- ajutised_muutujad(conf = conf)
+  conf <- vars$conf
+
+  # conf$schema <- "minu_teed"
+  # conf$table <- "zzz"
+  # output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_field = "geom")
+  # conf$schema <- "eesti"
+  # conf$table <- "e_501_tee_j"
+  # cat(paste(paste0('"', ruut::db_table_colnames(conf = conf)$column_name, '"'), collapse = ","))
+
+  ## ------------------------- 1.1 Kõik teed osadena ---------------------------
+  ## Kasutame ETAK andmestikku 'e_501_tee_j'.
+  ## s.o tyyp <= 60.
+  # 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' : 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))
+
+  ## -------------------- 1.2 Teeme veergude valiku ----------------------------
+  # cat(paste(paste0('--FIELDS=\'', ruut::db_table_colnames(conf = conf)$column_name, '\''), collapse = " "))
+  # cat(paste(paste0('--COLUMN=\'', ruut::db_table_colnames(conf = conf)$column_name, '\''), collapse = " "))
+  # ruut::qgis_algorithm_search_by_word("retain")
+  # algorithm <- "native:deletecolumn"
+  algorithm <- "native:retainfields"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  input <- vars$tmp_gpkg_file_input_1
+  output <- vars$tmp_gpkg_file_output_2
+  cmd <- sprintf("qgis_process run %s --FIELDS='etak_id' --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))
+
+  ## ----------------------- 1.3 Graafi genereerimine  -----------------------------
+  # ruut::qgis_algorithm_search_by_word("graph")
+  algorithm <- "Networks:build_graph"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  input <- vars$tmp_gpkg_file_input_2
+  output <- vars$tmp_gpkg_file_output_3
+  cmd <- sprintf("qgis_process run %s  --IDENT=0 --NOEUDS='%s' --PREFIXE=\"\" --RESEAU='%s' --SENS=\"\" ", algorithm, output, input)
+  cat(cmd)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
+
+  ## ------------------ 1.4 Copy temp gpkg file to postgis ---------------------
+  conf$schema <- "minu_teed"
+  conf$table <- "links"
+  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_2, "LINESTRING", conf$schema, conf$table)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+
+  conf$schema <- "minu_teed"
+  conf$table <- "nodes"
+  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, "POINT", conf$schema, conf$table)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+
+
+  ## ------------------------- 2.1 Prepare GTFS --------------------------------
+  # Download link
+  url <- "http://www.peatus.ee/gtfs/"
+  # Estonia shapefile (ZIP archive)
+  map_shapefile <- "gtfs.zip"
+  # Gtfs directory
+  gtfs_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "gtfs")
+  # Download and save
+  url_download <- sprintf("%s%s", url, map_shapefile)
+  saveTo <- sprintf("%s/%s", gtfs_dir, map_shapefile)
+  if (!file.exists(saveTo)) {
+    utils::download.file(
+      url = url_download,
+      destfile = saveTo, method = "curl", extra = "-L"
+    )
+  }
+  # Unzip
+  utils::unzip(saveTo, overwrite = T, exdir = gtfs_dir)
+  # ruut::qgis_algorithm_search_by_word("prepare")
+  algorithm <- "Networks:prepare\\ GTFS"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  sub_dir <- "LI"
+  cmd <- sprintf("qgis_process run %s  --PREFIXE_RESEAU='%s' --REP_RESULTAT='%s' --SPLIT_FORMULA=\"[-8:]\" --REP_SOURCE='%s' --UIC=1 ", algorithm, sub_dir, gtfs_dir, gtfs_dir)
+  cat(cmd)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s/%s'.\n", gtfs_dir, sub_dir))
+
+  ## ------------------------- 2.2 GTFS import  --------------------------------
+  # ruut::qgis_algorithm_search_by_word("gtfs")
+  algorithm <- "Networks:gtfs_import"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  # str <- "{ 'DEBUT_PERIODE' : QDate(2021, 3, 20), 'ENCODAGE' : 'utf_8_sig', 'FIN_PERIODE' : QDate(2021, 3, 20), 'PREFIXE' : 'IC', 'PROJ' : QgsCoordinateReferenceSystem('EPSG:2154'), 'REP_GTFS' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/LI', 'REP_SORTIE' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa', 'T1' : QTime(0, 0, 0), 'T2' : QTime(23, 59, 59) }"
+  # cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  cmd <- sprintf("qgis_process run %s --DEBUT_PERIODE='%s' --ENCODAGE='utf_8_sig' --FIN_PERIODE='%s' --PREFIXE='gtfs' --PROJ='EPSG:3301' --REP_GTFS='%s/%s' --REP_SORTIE='%s' --T1='00:00:00' --T2='23:59:59' ", algorithm, Sys.Date(), as.Date(Sys.Date()) + 60, gtfs_dir, sub_dir, vars$tmp_dir)
+  cat(cmd)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi shp failid kataloogi '%s'.\n", vars$tmp_dir))
+
+  # Delete unnecessary files.
+  system(sprintf("find %s -type f -not -name '%s' -print0 | xargs -0 rm --", gtfs_dir, map_shapefile))
+
+  ## -------------------- 2.3 Copy shp files to postgis ------------------------
+  # List of files
+  ls <- list.files(path = vars$tmp_dir, pattern = ".shp")
+  ls_long <- list.files(path = vars$tmp_dir, pattern = ".shp", full.names = T)
+  tbl_names <- tools::file_path_sans_ext(list.files(path = vars$tmp_dir, pattern = "*.shp"))
+  conf$schema <- "minu_teed"
+  for (i in 1:length(tbl_names)) {
+    geometry <- "LINESTRING"
+    if (tbl_names[i] == "gtfs_stops") geometry <- "POINT"
+    conf$table <- tbl_names[i]
+    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 -overwrite -nlt %s -lco GEOMETRY_NAME=geom -lco FID=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, ls_long[i], geometry, conf$schema, conf$table)
+    system(cmd)
+    cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+  }
+}

+ 92 - 355
R/minu_teed_loomine.R

@@ -1,4 +1,4 @@
-#' Teeregistri WFS ja maaameti andmete põhjal oma teeandmete 'minu_teed' loomine
+#' Teeregistri WFS ja maaameti andmete oma teeandmete 'minu_teed' loomine
 #'
 #' 1. Põhi-, kõrval ja tugimaanteedest ning rambid moodustatakse uus andmebaas 'riigiteedevork'.
 #' 2. Ilma teenumbrita kohalike teede andmebaasi 'numbrita_kohalik_tee' loomine.
@@ -9,7 +9,7 @@
 #' @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::teeregister_wfs()]
-#' @keywords postgis, maps, WFS, OSM
+#' @keywords postgis
 #' @export
 #' @examples
 #' \dontrun{
@@ -19,304 +19,48 @@
 #' }
 minu_teed_loomine <- function(conf = NULL) {
   ## ------------- muutujad ja teisendused ---------------
-  if (is.null(conf)) {
-    conf <- ruut::get_config()
-  }
-  ## Defineerime ajutised failid ja muutujad.
-  tmp_dir <- tempdir() # ajutine kataloog
-  obj <- "demo"
-  tmp_gpkg_file <- sprintf("%s/%s.gpkg", tmp_dir, obj) # ajutine gpkg fail
-  conf$gpkg_home <- tmp_dir
-  conf$gpkg_file <- obj
-  conf$primary_key <- "id"
-  ## Loome lingid gpkg ajutistest tabelitest lugemiseks ja kirjutamiseks
-  conf$gpkg_table <- layer_6 <- "test_layer_6"
-  tmp_gpkg_file_output_6 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_6 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  conf$gpkg_table <- layer_5 <- "test_layer_5"
-  tmp_gpkg_file_output_5 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_5 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  conf$gpkg_table <- layer_4 <- "test_layer_4"
-  tmp_gpkg_file_output_4 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_4 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  conf$gpkg_table <- layer_3 <- "test_layer_3"
-  tmp_gpkg_file_output_3 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_3 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  conf$gpkg_table <- layer_2 <- "test_layer_2"
-  tmp_gpkg_file_output_2 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_2 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
-  conf$gpkg_table <- layer_1 <- "test_layer_1"
-  tmp_gpkg_file_output_1 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = F)
-  tmp_gpkg_file_input_1 <- ruut::construct_to_gpkg_output_file_str(conf = conf, is_input_str = T)
+  vars <- ajutised_muutujad(conf = conf)
+  conf <- vars$conf
 
-
-
-  ## ================= Schema 'minu_teed' ====================
   conf$schema <- "minu_teed"
-  ruut::db_create_new_schema(conf = conf)
+  conf$table <- "zzz"
+  output <- ruut::construct_to_gpkg_output_postgres_str(conf = conf, geometry_field = "geom")
+  cat(paste(paste0('"', ruut::db_table_colnames(conf = conf)$column_name, '"'), collapse = ","))
 
 
-  ## =================== 2. teedevõrkude loomine =======================
-  ## ------------------ 2.1.1 Riigiteed osadena -----------------------
-  ## s.o (ilma rampideta) <= 30, koos rampide ja muude riigiteedega <= 45.
-  # ruut::qgis_algorithm_search_by_word("extract")
-  algorithm <- "native:extractbyattribute"
+  ## --------------------- 1.2 CSV tabeli import -------------------------------
+  # ruut::qgis_algorithm_search_by_word("csvtools")
+  algorithm <- "csvtools:loadcsvfile"
   # 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 <- tmp_gpkg_file_output_1
-  str <- sprintf("{ 'FIELD' : 'tyyp', 'INPUT' : '%s', 'OPERATOR' : 5, 'OUTPUT' : '%s', 'VALUE' : '45' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  input <- vars$tmp_gpkg_file_input_1
+  output <- vars$tmp_gpkg_file_output_2
+  cmd <- sprintf("qgis_process run %s --FIELD_NAME='rahvaarv' --FIELD_TYPE=1 --FIELD_LENGTH=0 --FIELD_PRECISION=0 --GLOBAL=\"\" --FORMULA='if ( \"VAARTUS\" >= 1000000, 3, \"VAARTUS\")' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output) # Ma ei tea miks nii töötab, aga muud moodi ei saanud ühe teisendusega tööle. Veider.
   system(cmd)
   cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
-  ## 2.1.2 Copy temp gpkg file to postgis.
-  conf$schema <- "minu_teed"
-  conf$table <- "teedevork_riigiteed_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, tmp_gpkg_file, layer_1, "LINESTRING", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
 
-  ## ---------------- 2.2.1 Riigiteed tervikuna ------------------
-  # ruut::qgis_algorithm_search_by_word("dissolve")
-  algorithm <- "native:dissolve"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_1
-  output <- tmp_gpkg_file_output_2
-  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)
-  ## 2.2.2 Eemaldame ebavajalikud veerud
-  # ruut::qgis_algorithm_search_by_word("retain")
-  algorithm <- "native:retainfields"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_2
-  output <- tmp_gpkg_file_output_3
-  cmd <- sprintf("qgis_process run %s  --FIELDS='tyyp' --FIELDS='tyyp_t' --FIELDS='tee' --FIELDS='nimetus' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
-  system(cmd)
-  ## 2.2.2 Copy temp gpkg file to postgis.
-  conf$schema <- "minu_teed"
-  conf$table <- "teedevork_riigiteed"
-  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, tmp_gpkg_file, layer_3, "MULTILINESTRING", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
-  ##  2.2.3 Riigiteede alg- ja lõpppunkt ---------------
-  # ruut::qgis_algorithm_search_by_word("vertices")
-  algorithm <- "native:extractspecificvertices"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_3
-  output <- tmp_gpkg_file_output_4
-  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))
-  ## 2.2.4 Copy temp gpkg file to postgis.
-  conf$schema <- "minu_teed"
-  conf$table <- "teedevork_riigiteed_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=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, tmp_gpkg_file, layer_4, "POINT", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
 
 
-  ## ------------------- 2.4 Muud teed osadena ----------------------
-  ## s.o tyyp IN (50,60,).
-  ## 2.4.1 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 <- 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))
-  ## 2.4.2 Seejärel sorteerime <= 60
-  algorithm <- "native:extractbyattribute"
-  input <- tmp_gpkg_file_input_1
-  output <- 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))
+  # Processing algorithm…
+  # Algorithm 'Create vector layer from CSV file' starting…
+  # Input parameters:
+  #   { 'CRS' : None, 'DECIMAL_POINT' : 0, 'DELIMITER' : 1, 'GEOMETRY_DATA' : 2, 'INPUT' : '/data/rahvaarv_ruutudes/GRID1000_MK12/Tabel_1_rahvaarv_GRD_1000_REL_2011.csv', 'OUTPUT' : 'TEMPORARY_OUTPUT', 'QUOTE_CHAR' : '\"', 'USE_HEADER' : True, 'WKT_FIELD' : '', 'X_FIELD' : '', 'Y_FIELD' : '' }
+
+
+
+
+
+
 
-  ## 2.4.3 Eemaldame need muud teed kus 'tee'=NULL (ilma teenumbrita ehk kvartalissisesed).
-  algorithm <- "native:extractbyattribute"
-  input <- tmp_gpkg_file_input_2
-  output <- 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))
-  ## 2.4.4 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, tmp_gpkg_file, layer_3, "LINESTRING", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
-  ## 2.4.5 Ühendame sama teenumbriga muud teed
-  # ruut::qgis_algorithm_search_by_word("dissolve")
-  algorithm <- "native:dissolve"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_3
-  output <- 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)
-  ## 2.4.6 Eemaldame ebavajalikud veerud
-  # ruut::qgis_algorithm_search_by_word("retain")
-  algorithm <- "native:retainfields"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_4
-  output <- 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)
-  ## 2.4.7 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, tmp_gpkg_file, layer_5, "MULTILINESTRING", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
-  ## 2.4.8 Muude teede alg- ja lõpppunkt
-  # ruut::qgis_algorithm_search_by_word("vertices")
-  algorithm <- "native:extractspecificvertices"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_5
-  output <- 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))
-  ## 2.4.9 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=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, tmp_gpkg_file, layer_6, "POINT", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
 
 
-  ## 2.5.1 Leiame need muud teed kus 'tee'=NULL (ilma teenumbrita ehk kvartalissisesed).
-  algorithm <- "native:extractbyattribute"
-  input <- tmp_gpkg_file_input_2
-  output <- 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))
-  ## 2.5.2 Eemaldame ebavajalikud veerud
-  # ruut::qgis_algorithm_search_by_word("retain")
-  algorithm <- "native:retainfields"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_3
-  output <- 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)
-  ## 2.5.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, tmp_gpkg_file, layer_4, "LINESTRING", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
-  ## 2.5.3 Nimeta teede alg- ja lõpppunkt
-  # ruut::qgis_algorithm_search_by_word("vertices")
-  algorithm <- "native:extractspecificvertices"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_4
-  output <- 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))
-  ## 2.4.9 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=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, tmp_gpkg_file, layer_5, "POINT", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
 
 
-  ## =================== 3. 'eesti' =======================
-  ## 3.1 Maakondadest Eesti maismaapiir
-  # ruut::qgis_algorithm_search_by_word("dissolve")
-  algorithm <- "native:dissolve"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  conf$schema <- "maaamet"
-  conf$table <- "maakond"
-  input <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_type = "MultiPolygon", srid = 3301,
-    checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = "geom"
-  )
-  output <- tmp_gpkg_file_output_1
-  str <- sprintf("{ 'FIELD' : [], 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
-  ## 3.2 Kustutame ebaolulised väljad
-  # ruut::qgis_algorithm_search_by_word("delete")
-  algorithm <- "native:deletecolumn"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_1
-  output <- tmp_gpkg_file_output_2
-  cmd <- sprintf("qgis_process run %s  --COLUMN='mnimi' --COLUMN='mkood' --COLUMN='fid' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
-  system(cmd)
-  ## 3.3 Jaotame multipart polügooni singlepart polügoonideks.
-  # ruut::qgis_algorithm_search_by_word("multipart")
-  algorithm <- "native:multiparttosingleparts"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_2
-  output <- tmp_gpkg_file_output_3
-  str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
-  ## 3.4 Lisame pindade pindalad ja perimeetri
-  # ruut::qgis_algorithm_search_by_word("columns")
-  algorithm <- "qgis:exportaddgeometrycolumns"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_3
-  output <- tmp_gpkg_file_output_4
-  str <- sprintf("{ 'CALC_METHOD' : 0, 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
 
-  ## 3.5 Eemaldame objektid mille pindala on väiksem kui 10km2 (väikesaared)
-  # ruut::qgis_algorithm_search_by_word("extract")
-  algorithm <- "native:extractbyattribute"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_4
-  output <- tmp_gpkg_file_output_5
-  str <- sprintf("{ 'FIELD' : 'area', 'OPERATOR' : 2, 'VALUE' : '10000000', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
-  ## 3.6 Eemaldame augud, mis on suuremad kui 1ha.
-  # ruut::qgis_algorithm_search_by_word("holes")
-  algorithm <- "native:deleteholes"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_5
-  output <- tmp_gpkg_file_output_6
-  str <- sprintf("{ 'MIN_AREA' : '10000', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
-  ## 3.7 Copy temp gpkg file to postgis.
-  conf$schema <- "minu_teed"
-  conf$table <- "eesti"
-  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=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, tmp_gpkg_file, layer_6, "MULTIPOLYGON", conf$schema, conf$table)
-  system(cmd)
-  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+
+
+
+
+  ## =================== 3. 'eesti' =======================
 
 
   ## ------------------ Teedevõrgu polügoniseerimine ------------------
@@ -330,7 +74,7 @@ minu_teed_loomine <- function(conf = NULL) {
     conf = conf, geometry_type = "Polygon", srid = 3301,
     checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
   )
-  output <- tmp_gpkg_file_output_1
+  output <- vars$tmp_gpkg_file_output_1
   str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
   cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
   system(cmd)
@@ -343,7 +87,7 @@ minu_teed_loomine <- function(conf = NULL) {
     conf = conf, geometry_type = "MultiLineString", srid = 3301,
     checkPrimaryKeyUnicity = TRUE, key = "id_0", geometry_field = "geom"
   )
-  output <- tmp_gpkg_file_output_2
+  output <- vars$tmp_gpkg_file_output_2
   str <- sprintf("{ 'FIELD' : 'tyyp', 'INPUT' : '%s', 'OPERATOR' : 5, 'OUTPUT' : '%s', 'VALUE' : '30' }", input, output)
   cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
   system(cmd)
@@ -352,12 +96,12 @@ minu_teed_loomine <- function(conf = NULL) {
   # ruut::qgis_algorithm_search_by_word("merge")
   algorithm <- "native:mergevectorlayers"
   # ruut::qgis_show_help(algorithm = algorithm)
-  layer_1 <- tmp_gpkg_file_input_1
-  layer_2 <- tmp_gpkg_file_input_2
-  output <- tmp_gpkg_file_output_3
+  vars$layer_1 <- vars$tmp_gpkg_file_input_1
+  vars$layer_2 <- vars$tmp_gpkg_file_input_2
+  output <- vars$tmp_gpkg_file_output_3
   cmd <- sprintf(
     "qgis_process run native:mergevectorlayers --CRS='epsg:3301' --LAYERS='%s' --LAYERS='%s' --OUTPUT='%s' ",
-    layer_1, layer_2, output
+    vars$layer_1, vars$layer_2, output
   )
   system(cmd)
   cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
@@ -365,8 +109,8 @@ minu_teed_loomine <- function(conf = NULL) {
   # ruut::qgis_algorithm_search_by_word("Polygonize")
   algorithm <- "native:polygonize"
   # ruut::qgis_show_help(algorithm = algorithm)
-  input <- tmp_gpkg_file_input_3
-  output <- tmp_gpkg_file_output_4
+  input <- vars$tmp_gpkg_file_input_3
+  output <- vars$tmp_gpkg_file_output_4
   str <- sprintf("{ 'INPUT' : '%s', 'KEEP_FIELDS' : False, 'OUTPUT' : '%s' }", input, output)
   cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
   system(cmd)
@@ -374,70 +118,63 @@ minu_teed_loomine <- function(conf = NULL) {
   conf$schema <- "minu_teed"
   conf$table <- "teedevork_riigiteed_a"
   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=fid -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, tmp_gpkg_file, layer_4, "MULTIPOLYGON", conf$schema, conf$table)
+  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_4, "MULTIPOLYGON", conf$schema, conf$table)
   system(cmd)
   cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
 
-
-
-
-  ## =================== !!!!!!!!!!!!!! POOLELI !!!!!!!!!!!! =======================
-
-  ## 4.2 Lõikame Eesti kaardist polügoniseerime riigiteedevõrgu välja.
-  ## Tekib ümber Eesti raam, mis tuleb jagada kuidagi transporditsoonideks.
-  # ruut::qgis_algorithm_search_by_word("Difference")
-  algorithm <- "native:difference"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  conf$schema <- "minu_teed"
-  conf$table <- "eesti"
-  input <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_type = "Polygon", srid = 3301,
-    checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
-  )
-  conf$schema <- "minu_teed"
-  conf$table <- "riigiteedevork_a"
-  overlay <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_type = "Polygon", srid = 3301,
-    checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
-  )
-  conf$schema <- "minu_teed"
-  conf$table <- "riigiteedevork_xxx"
-  output <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_field = "geom", key = "fid"
-  )
-  str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s', 'OVERLAY' : '%s' }", input, output, overlay)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
-
-  "Processing algorithm…
-Algorithm 'Intersection' starting…
-Input parameters:
-{ 'INPUT' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'fid\' srid=3301 type=MultiLineString checkPrimaryKeyUnicity=\'1\' table=\"minu_teed\".\"riigiteedevork\" (geom)', 'INPUT_FIELDS' : [], 'OUTPUT' : 'TEMPORARY_OUTPUT', 'OVERLAY' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'id_0\' srid=3301 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table=\"minu_teed\".\"riigiteedevork_xxx\" (geom)', 'OVERLAY_FIELDS' : [], 'OVERLAY_FIELDS_PREFIX' : '' }"
-
-  ## 4.3 Kuna polügoniseeritud pinnad ei olnud täiuslikud, siis teostame
-  ## polügoniseeriist veelkorra. Selleks lõikame esmalt teedevõrgust
-  ## tekkinud raamiga need teed mis jäävad raamis sisse.
-  # ruut::qgis_algorithm_search_by_word("Intersection")
-  algorithm <- "native:intersection"
-  # ruut::qgis_show_help(algorithm = algorithm)
-  conf$schema <- "minu_teed"
-  conf$table <- "riigiteedevork"
-  input <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_type = "MultiLineString", srid = 3301,
-    checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
-  )
-  conf$schema <- "minu_teed"
-  conf$table <- "riigiteedevork_xxx"
-  overlay <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_type = "MultiPolygon", srid = 3301,
-    checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
-  )
-  conf$schema <- "minu_teed"
-  conf$table <- "riigiteedevork_xxx1"
-  output <- ruut::construct_to_gpkg_output_postgres_str(
-    conf = conf, geometry_field = "geom"
-  )
-  str <- sprintf("{ 'INPUT' : '%s', 'INPUT_FIELDS' : [], 'OUTPUT' : '%s', 'OVERLAY' : '%s', 'OVERLAY_FIELDS' : [], 'OVERLAY_FIELDS_PREFIX' : '' }", input, output, overlay)
-  cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
-  system(cmd)
+  # ## =================== !!!!!!!!!!!!!! POOLELI !!!!!!!!!!!! =======================
+  #
+  # ## 4.2 Lõikame Eesti kaardist polügoniseerime riigiteedevõrgu välja.
+  # ## Tekib ümber Eesti raam, mis tuleb jagada kuidagi transporditsoonideks.
+  # # ruut::qgis_algorithm_search_by_word("Difference")
+  # algorithm <- "native:difference"
+  # # ruut::qgis_show_help(algorithm = algorithm)
+  # conf$schema <- "minu_teed"
+  # conf$table <- "eesti"
+  # input <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_type = "Polygon", srid = 3301,
+  #   checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
+  # )
+  # conf$schema <- "minu_teed"
+  # conf$table <- "riigiteedevork_a"
+  # overlay <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_type = "Polygon", srid = 3301,
+  #   checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
+  # )
+  # conf$schema <- "minu_teed"
+  # conf$table <- "riigiteedevork_xxx"
+  # output <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_field = "geom", key = "fid"
+  # )
+  # str <- sprintf("{ 'INPUT' : '%s', 'OUTPUT' : '%s', 'OVERLAY' : '%s' }", input, output, overlay)
+  # cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  # system(cmd)
+  #
+  #
+  # ## 4.3 Kuna polügoniseeritud pinnad ei olnud täiuslikud, siis teostame
+  # ## polügoniseeriist veelkorra. Selleks lõikame esmalt teedevõrgust
+  # ## tekkinud raamiga need teed mis jäävad raamis sisse.
+  # # ruut::qgis_algorithm_search_by_word("Intersection")
+  # algorithm <- "native:intersection"
+  # # ruut::qgis_show_help(algorithm = algorithm)
+  # conf$schema <- "minu_teed"
+  # conf$table <- "riigiteedevork"
+  # input <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_type = "MultiLineString", srid = 3301,
+  #   checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
+  # )
+  # conf$schema <- "minu_teed"
+  # conf$table <- "riigiteedevork_xxx"
+  # overlay <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_type = "MultiPolygon", srid = 3301,
+  #   checkPrimaryKeyUnicity = TRUE, key = "fid", geometry_field = "geom"
+  # )
+  # conf$schema <- "minu_teed"
+  # conf$table <- "riigiteedevork_xxx1"
+  # output <- ruut::construct_to_gpkg_output_postgres_str(
+  #   conf = conf, geometry_field = "geom"
+  # )
+  # str <- sprintf("{ 'INPUT' : '%s', 'INPUT_FIELDS' : [], 'OUTPUT' : '%s', 'OVERLAY' : '%s', 'OVERLAY_FIELDS' : [], 'OVERLAY_FIELDS_PREFIX' : '' }", input, output, overlay)
+  # cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+  # system(cmd)
 }

+ 149 - 0
inst/python/qgis_processing_algorithm.py

@@ -0,0 +1,149 @@
+#!/usr/bin/python3
+# https://docs.qgis.org/3.18/en/docs/pyqgis_developer_cookbook/intro.html
+# export LD_LIBRARY_PATH=/usr/lib/qgis
+# export PYTHONPATH=/usr/share/qgis/python
+# export LD_LIBRARY_PATH=/usr/share/qgis/python
+# export PYTHONPATH=$PYTHONPATH:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ForestRoadsNetworksUPLOAD:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/AequilibraE/aequilibrae:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/csv_tools:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/networks:/usr/share/qgis/python:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins:/usr/share/qgis/python/plugins:/usr/lib/python38.zip:/usr/lib/python3.8:/usr/lib/python3.8/lib-dynload:/home/ardo/.local/lib/python3.8/site-packages:/usr/local/lib/python3.8/dist-packages:/usr/lib/python3/dist-packages:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python:/usr/lib/python3/dist-packages/IPython/extensions:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgis2web:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/postgisQueryBuilder:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/postgisQueryBuilder/extlibs
+# print(os.environ['PATH'])
+# print(os.environ)
+# Lisa plugina metadata.txt faili: # ardo !!!!!!!!!!!
+# hasProcessingProvider=yes
+
+
+
+import qgis
+from qgis.core import *
+import sys
+import os
+
+
+# Supply path to qgis install location
+QgsApplication.setPrefixPath("/usr", True)
+
+# Create a reference to the QgsApplication.
+# Setting the second argument to True enables the GUI.  We need
+# this since this is a custom application.
+# qgs = QgsApplication([], True)
+qgs = QgsApplication([], False)
+
+# load providers
+qgs.initQgis()
+
+
+# Append the path where processing plugin can be found
+sys.path.append('/usr/share/qgis/python/plugins')
+sys.path.append('/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins')
+
+
+import processing
+## QGIS core algoritmid
+from processing.core.Processing import Processing
+Processing.initialize()
+# qgis.core.QgsApplication.processingRegistry().addProvider(qgis.analysis.QgsNativeAlgorithms())
+
+# Otsi sõna järele mooduleid.
+otsi = "graph"
+print("\nLeitud moodulid:")
+print([x.id() for x in QgsApplication.processingRegistry().algorithms() if otsi in x.id()])
+print("\n\n")
+
+from processing.tools import *
+
+
+# from qgis.analysis import QgsNativeAlgorithms
+# QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
+
+
+import PyQt5
+from networks.creer_graphe import CreerGraphe
+
+print(CreerGraphe().name())
+# print(CreerGraphe().shortHelpString())
+
+# context = QgsProcessingContext()
+# feedback = QgsProcessingFeedback()
+
+
+## !!!!!!!!! Niimoodi saab layer'eid lisada QGIS pythoni käsurealt !!!!!!!!!!
+## !!!!!!!!!! Väga mugav kasutada kui palju layer'eid vaja lisada !!!!!!!!!!!
+## Load postgis layer
+uri = QgsDataSourceUri()
+# set host name, port, database name, username and password
+uri.setConnection("localhost", "6432", "data", "osm", "osm")
+# set database schema, table name, geometry column and optionally
+# subset (WHERE clause)
+uri.setDataSource("minu_teed", "eesti", "geom", "id = 1", "id")
+vlayer = QgsVectorLayer(uri.uri(False), "my_layer", "postgres")
+if not vlayer.isValid():
+    print("Layer failed to load!")
+else:
+    QgsProject.instance().addMapLayer(vlayer)
+
+## Load gpkg layer
+path_to_gpkg = os.path.join("/data","gpkg","artiklid","artikkel_210127_valga_matsalu_lahemaa", "links.gpkg")
+# append the layername part
+gpkg_countries_layer = path_to_gpkg + "|layername=teedevork_riigiteed"
+# e.g. gpkg_places_layer = "/usr/share/qgis/resources/data/world_map.gpkg|layername=countries"
+vlayer2 = QgsVectorLayer(gpkg_countries_layer, "Countries layer", "ogr")
+if not vlayer2.isValid():
+    print("Layer failed to load!")
+else:
+    QgsProject.instance().addMapLayer(vlayer2)
+
+
+# params = { 'IDENT' : 1, 'NOEUDS' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table=\"minu_teed\".\"aaa1\" (geom)', 'PREFIXE' : '', 'RESEAU' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/links.gpkg', 'SENS' : '' }
+params = { 'IDENT' : 1,
+'NOEUDS' : vlayer,
+'PREFIXE' : '', 'RESEAU' : vlayer2, 'SENS' : '' }
+# alg = "Networks:build_graph"
+# processing.run(alg,params)
+
+
+# print(CreerGraphe().createInstance())
+print(params['RESEAU'])
+print("---------------------")
+print(params['NOEUDS'])
+print("---------------------")
+
+
+CreerGraphe().initAlgorithm(config={})
+# CreerGraphe().processAlgorithm(parameters = params, context=context, feedback=feedback)
+# CreerGraphe().initAlgorithm(config=None)
+
+
+# for alg in qgs.processingRegistry().algorithms():
+#   print(alg.id(), "->", alg.displayName())
+
+# processing.run("native:centroids", { 'ALL_PARTS' : False, \
+# 'INPUT' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'id\' srid=3301 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table="minu_teed"."eesti" (geom)', \
+# 'OUTPUT' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table="minu_teed"."x325" (geom)' })
+# processing.run("Networks:build_graph", { 'IDENT' : 1, 'NOEUDS' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table=\"minu_teed\".\"aaa1\" (geom)', 'PREFIXE' : '', 'RESEAU' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/links.gpkg', 'SENS' : '' })
+# processing.run("qneat3:shortestpathpointtopoint", {'INPUT':'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'link_id\' srid=3301 type=LineString checkPrimaryKeyUnicity=\'1\' table=\"minu_teed\".\"links\" (geom)','START_POINT':'640381.958323,6519317.618656 [EPSG:3301]','END_POINT':'669499.921921,6528373.950681 [EPSG:3301]','STRATEGY':0,'ENTRY_COST_CALCULATION_METHOD':0,'DIRECTION_FIELD':'','VALUE_FORWARD':'','VALUE_BACKWARD':'','VALUE_BOTH':'','DEFAULT_DIRECTION':2,'SPEED_FIELD':'','DEFAULT_SPEED':5,'TOLERANCE':0,'OUTPUT':'TEMPORARY_OUTPUT'})
+
+
+# processing.algorithmHelp("qgis:creategrid")
+processing.algorithmHelp("Networks:build_graph")
+
+
+## Load postgis layer
+# uri = QgsDataSourceUri()
+# # set host name, port, database name, username and password
+# uri.setConnection("localhost", "6432", "data", "osm", "osm")
+# # set database schema, table name, geometry column and optionally
+# # subset (WHERE clause)
+# uri.setDataSource("minu_teed", "eesti", "geom", "id = 1", "id")
+# vlayer = QgsVectorLayer(uri.uri(False), "my_layer", "postgres")
+# print (vlayer)
+# processing.run("native:buffer", {'INPUT': vlayer, \
+# 'OUTPUT': 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table="minu_teed"."z225" (geom)'})
+
+
+print('How many algorithms are there? '+ str(len(QgsApplication.processingRegistry().algorithms())))
+
+
+# print(sys.path)
+
+
+# Finally, exitQgis() is called to remove the
+# provider and layer registries from memory
+qgs.exitQgis()

+ 28 - 0
man/minu_teed_graaf.Rd

@@ -0,0 +1,28 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/minu_teed_graaf.R
+\name{minu_teed_graaf}
+\alias{minu_teed_graaf}
+\title{Riigiteedevõrgu graafide loomine (nodes and links)}
+\usage{
+minu_teed_graaf(conf = NULL)
+}
+\arguments{
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
+}
+\description{
+ETAK (Eesti topograafia andmekogu) \url{https://geoportaal.maaamet.ee/est/Ruumiandmed/Eesti-topograafia-andmekogu/Laadi-ETAK-andmed-alla-p609.html} andmete põhjal
+}
+\examples{
+\dontrun{
+
+conf <- ruut::get_config()
+minu_teed_graaf(conf = conf)
+}
+}
+\seealso{
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}, \code{\link[=minu_teed_graaf]{minu_teed_graaf()}}, \code{\link[=minu_teed_muud_teed]{minu_teed_muud_teed()}}, \code{\link[=minu_teed_eesti]{minu_teed_eesti()}}
+}
+\keyword{postgis}