|
|
@@ -19,52 +19,27 @@
|
|
|
#' }
|
|
|
minu_teed_loomine <- 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")
|
|
|
- cat(paste(paste0('"', ruut::db_table_colnames(conf = conf)$column_name, '"'), collapse = ","))
|
|
|
-
|
|
|
-
|
|
|
- ## --------------------- 1.2 CSV tabeli import -------------------------------
|
|
|
- # ruut::qgis_algorithm_search_by_word("csvtools")
|
|
|
- algorithm <- "csvtools:loadcsvfile"
|
|
|
- # 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 --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))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # 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' : '' }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ # 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 = ","))
|
|
|
|
|
|
- ## =================== 3. 'eesti' =======================
|
|
|
|
|
|
+ ## -------- 1.1 Kontrollime andmebaasis vajalike tabelite olemasolu ----------
|
|
|
+ conf$schema <- "minu_teed"
|
|
|
+ tbl_names <- ruut::db_schema_tablenames(conf = conf)
|
|
|
+ if (!all(c("teedevork_riigiteed_osadena", "eesti", "teedevork") %in% tbl_names)) {
|
|
|
+ cat("\n------------------\nPuuduvad vajalikud andmebaasitabelid.\n")
|
|
|
+ return(NULL)
|
|
|
+ }
|
|
|
|
|
|
- ## ------------------ Teedevõrgu polügoniseerimine ------------------
|
|
|
- ## 4.1 Teisendame eesti polügooni joonteks.
|
|
|
+ ## -------------------- 1.1 Loeme eesti kontuurjoone -------------------------
|
|
|
# ruut::qgis_algorithm_search_by_word("lines")
|
|
|
algorithm <- "native:polygonstolines"
|
|
|
# ruut::qgis_show_help(algorithm = algorithm)
|
|
|
@@ -78,20 +53,26 @@ minu_teed_loomine <- function(conf = NULL) {
|
|
|
str <- sprintf("{ 'INPUT' : '%s', '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))
|
|
|
+
|
|
|
+ ## ------------------------- 1.2 Riigi teed osadena ---------------------------
|
|
|
## 4.2 Eemaldame riigiteedest rambid.
|
|
|
algorithm <- "native:extractbyattribute"
|
|
|
# ruut::qgis_show_help(algorithm = algorithm)
|
|
|
conf$schema <- "minu_teed"
|
|
|
- conf$table <- "teedevork_riigiteed"
|
|
|
+ conf$table <- "teedevork_riigiteed_osadena"
|
|
|
input <- ruut::construct_to_gpkg_output_postgres_str(
|
|
|
conf = conf, geometry_type = "MultiLineString", srid = 3301,
|
|
|
- checkPrimaryKeyUnicity = TRUE, key = "id_0", geometry_field = "geom"
|
|
|
+ checkPrimaryKeyUnicity = TRUE, key = "id", geometry_field = "geom"
|
|
|
)
|
|
|
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)
|
|
|
cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+
|
|
|
+ ## ------------- 1.3 Riigiteede ja eesti kontuuri ühendamine -----------------
|
|
|
## 4.3 Enne polügoniseerimist ühendame eesti kontuuri ja teedevõrgu üheks.
|
|
|
# ruut::qgis_algorithm_search_by_word("merge")
|
|
|
algorithm <- "native:mergevectorlayers"
|
|
|
@@ -105,15 +86,48 @@ minu_teed_loomine <- function(conf = NULL) {
|
|
|
)
|
|
|
system(cmd)
|
|
|
cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## -------------------- 1.4 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_3
|
|
|
+ output <- vars$tmp_gpkg_file_output_4
|
|
|
+ cmd <- sprintf("qgis_process run %s --FIELDS='fid' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
|
|
|
+ system(cmd)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## ----------------------- 1.5 Polügoniseerimine -----------------------------
|
|
|
## 4.4 Polügoniseerime saadud riigiteedevõrgu. Tekib teedega piiratud polügoonid.
|
|
|
# ruut::qgis_algorithm_search_by_word("Polygonize")
|
|
|
algorithm <- "native:polygonize"
|
|
|
# ruut::qgis_show_help(algorithm = algorithm)
|
|
|
- input <- vars$tmp_gpkg_file_input_3
|
|
|
- output <- vars$tmp_gpkg_file_output_4
|
|
|
+ input <- vars$tmp_gpkg_file_input_4
|
|
|
+ output <- vars$tmp_gpkg_file_output_5
|
|
|
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)
|
|
|
+
|
|
|
+ ## ------------------ 1.4 Copy temp gpkg file to postgis ---------------------
|
|
|
+ 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=id -nln %s.%s -nlt PROMOTE_TO_MULTI", PG, vars$tmp_gpkg_file, vars$layer_5, "POLYGON", conf$schema, conf$table)
|
|
|
+ system(cmd)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ## ------------------ Teedevõrgu polügoniseerimine ------------------
|
|
|
+
|
|
|
## 4.5 Copy temp gpkg file to postgis.
|
|
|
conf$schema <- "minu_teed"
|
|
|
conf$table <- "teedevork_riigiteed_a"
|