|
|
@@ -0,0 +1,100 @@
|
|
|
+#' Eesti kontuuri loomine teedevõrgu piiriks
|
|
|
+#'
|
|
|
+#' EHAk (Eesti haldus- ja asustusjaotus) \url{https://geoportaal.maaamet.ee/est/Andmed-ja-kaardid/Haldus-ja-asustusjaotus-p119.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_riigiteed()], [estmap::minu_teed_muud_teed()], [estmap::minu_teed_eesti()]
|
|
|
+#' @keywords postgis
|
|
|
+#' @export
|
|
|
+#' @examples
|
|
|
+#' \dontrun{
|
|
|
+#'
|
|
|
+#' conf <- ruut::get_config()
|
|
|
+#' minu_teed_eesti(conf = conf)
|
|
|
+#' }
|
|
|
+minu_teed_eesti <- function(conf = NULL) {
|
|
|
+ ## --------------------- muutujad ja teisendused -----------------------------
|
|
|
+ vars <- ajutised_muutujad(conf = conf)
|
|
|
+ conf <- vars$conf
|
|
|
+
|
|
|
+ ## -------------------- 1.1 Eesti riigipiir (osadeta) ------------------------
|
|
|
+ ## Kasutame ETAK andmestikku 'maaamet.maakond'.
|
|
|
+ ## 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 <- vars$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)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## ------------------ 1.2 Kustutame ebaolulised väljad -----------------------
|
|
|
+ # ruut::qgis_algorithm_search_by_word("delete")
|
|
|
+ algorithm <- "native:deletecolumn"
|
|
|
+ # 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 --COLUMN='mnimi' --COLUMN='mkood' --COLUMN='fid' --INPUT='%s' --OUTPUT='%s' ", algorithm, input, output)
|
|
|
+ system(cmd)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## -------- 1.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 <- vars$tmp_gpkg_file_input_2
|
|
|
+ output <- vars$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)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## -------------- 1.4 Lisame pindade pindalad ja perimeetri ------------------
|
|
|
+ # ruut::qgis_algorithm_search_by_word("columns")
|
|
|
+ algorithm <- "qgis:exportaddgeometrycolumns"
|
|
|
+ # ruut::qgis_show_help(algorithm = algorithm)
|
|
|
+ input <- vars$tmp_gpkg_file_input_3
|
|
|
+ output <- vars$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)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## -- 1.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 <- vars$tmp_gpkg_file_input_4
|
|
|
+ output <- vars$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)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## ------------ 1.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 <- vars$tmp_gpkg_file_input_5
|
|
|
+ output <- vars$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)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
|
|
|
+
|
|
|
+ ## ------------------ 1.2 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, vars$tmp_gpkg_file, vars$layer_6, "MULTIPOLYGON", conf$schema, conf$table)
|
|
|
+ system(cmd)
|
|
|
+ cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
|
|
|
+}
|