瀏覽代碼

Lisatud 'minu_teed_riigiteed'.

Ardo Kubjas 5 年之前
父節點
當前提交
43dacf9d51
共有 2 個文件被更改,包括 122 次插入0 次删除
  1. 94 0
      R/minu_teed_riigiteed.R
  2. 28 0
      man/minu_teed_riigiteed.Rd

+ 94 - 0
R/minu_teed_riigiteed.R

@@ -0,0 +1,94 @@
+#' Riigiteedevõrgu loomine
+#'
+#' 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::teeregister_wfs()]
+#' @keywords postgis
+#' @export
+#' @examples
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' minu_teed_riigiteed(conf = conf)
+#' }
+minu_teed_riigiteed <- function(conf = NULL) {
+  ## --------------------- muutujad ja teisendused -----------------------------
+  vars <- ajutised_muutujad(conf = conf)
+  conf <- vars$conf
+
+  ## ------------------------- 1.1 Riigiteed osadena ---------------------------
+  ## Kasutame ETAK andmestikku 'e_501_tee_j'.
+  ## s.o (ilma rampideta) <= 30, koos rampide ja muude riigiteedega <= 45.
+  # 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' : '45' }", 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 <- "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, vars$tmp_gpkg_file, vars$layer_1, "LINESTRING", conf$schema, conf$table)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+
+  ## ----------------------- 2.1 Riigiteed tervikuna ---------------------------
+  # ruut::qgis_algorithm_search_by_word("dissolve")
+  algorithm <- "native:dissolve"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  input <- vars$tmp_gpkg_file_input_1
+  output <- vars$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)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", output))
+
+  ## ------------------- 2.2 Eemaldame ebavajalikud veerud ---------------------
+  # ruut::qgis_algorithm_search_by_word("retain")
+  algorithm <- "native:retainfields"
+  # 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  --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))
+
+  ## ------------------ 2.3 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, vars$tmp_gpkg_file, vars$layer_3, "MULTILINESTRING", conf$schema, conf$table)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+
+  ##  ----------------- 3.1 Riigiteede alg- ja lõpppunkt -----------------------
+  # ruut::qgis_algorithm_search_by_word("vertices")
+  algorithm <- "native:extractspecificvertices"
+  # ruut::qgis_show_help(algorithm = algorithm)
+  input <- vars$tmp_gpkg_file_input_3
+  output <- vars$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))
+
+  ## ------------------ 3.2 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, vars$tmp_gpkg_file, vars$layer_4, "POINT", conf$schema, conf$table)
+  system(cmd)
+  cat(sprintf("\n-------------\nLoodi andmebaas '%s'.\n", conf$table))
+}

+ 28 - 0
man/minu_teed_riigiteed.Rd

@@ -0,0 +1,28 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/minu_teed_riigiteed.R
+\name{minu_teed_riigiteed}
+\alias{minu_teed_riigiteed}
+\title{Riigiteedevõrgu loomine}
+\usage{
+minu_teed_riigiteed(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_riigiteed(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[=teeregister_wfs]{teeregister_wfs()}}
+}
+\keyword{postgis}