Переглянути джерело

Lisatud maaameti mullakaart ja põhikaardi kõik kihid.

Ardo Kubjas 5 роки тому
батько
коміт
59da1c6a6d
5 змінених файлів з 244 додано та 0 видалено
  1. 2 0
      NAMESPACE
  2. 89 0
      R/maaamet_eesti.R
  3. 89 0
      R/maaamet_mullakaart.R
  4. 32 0
      man/maaamet_eesti.Rd
  5. 32 0
      man/maaamet_mullakaart.Rd

+ 2 - 0
NAMESPACE

@@ -4,9 +4,11 @@ export(epk_grids)
 export(gtfs)
 export(inspire_grids)
 export(maaamet_aadressandmed)
+export(maaamet_eesti)
 export(maaamet_ehak)
 export(maaamet_kaardiruudud)
 export(maaamet_kataster)
+export(maaamet_mullakaart)
 export(maaamet_ortofotod)
 export(osm_shp)
 export(teeregister_teed)

+ 89 - 0
R/maaamet_eesti.R

@@ -0,0 +1,89 @@
+#' Maa-ameti kogu Eesti andmestik põhikaardina
+#'
+#' Source: \url{https://geoportaal.maaamet.ee/est/Ruumiandmed/Topokaardid-ja-aluskaardid/Eesti-pohikaart-1-10000/Laadi-pohikaart-alla-p612.html} . Andmed salvestatakse postgisi andmebaasi. Schema = 'eesti'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+#' @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()]
+#' @keywords postgis, maps, ESRI Shpfile, OSM
+#' @export
+#' @examples
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' maaamet_eesti(conf = conf)
+#' }
+maaamet_eesti <- function(conf = NULL) {
+  ans <- utils::askYesNo("Do you want to import maps into database?", default = F)
+  if (!ans | is.na(ans)) {
+    cat("\n------------------------\n")
+    cat("Kaardikihte ei lisatud.")
+    cat("\n------------------------\n")
+    return()
+  }
+  if (ans) {
+    # Temp directory
+    tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "maaamet_eesti")
+    if (!dir.exists(tmp_dir)) {
+      dir.create(tmp_dir)
+    }
+    # Download link
+    url <- "https://geoportaal.maaamet.ee/index.php?lang_id=1&plugin_act=otsing&andmetyyp=pohikaart&dl=1&f=ETAK_Eesti_pohikaart_SHP.zip&page_id=612"
+    # Estonia shapefile (ZIP archive)
+    map_shapefile <- "ETAK_Eesti_pohikaart_SHP.zip"
+    # Download and save
+    url_download <- sprintf("%s", url)
+    saveTo <- sprintf("%s/%s", tmp_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 = tmp_dir)
+    # List of files
+    tmp_dir_kihid <- sprintf("%s/ETAK_Eesti_pohikaart_2021_SHP/Kihid", tmp_dir)
+    ls <- list.files(path = tmp_dir_kihid, pattern = ".dbf")
+    ls_long <- list.files(path = tmp_dir_kihid, pattern = ".dbf", full.names = T)
+    tbl_names <- unlist(strsplit(x = ls, split = ".dbf"))
+    # Export to postgis
+    if (is.null(conf)) {
+      conf <- ruut::get_config()
+      conf$schema <- "eesti"
+    }
+    # New schema
+    ruut::db_create_new_schema(conf = conf)
+    # Multi layer
+    for (i in 1:length(tbl_names)) {
+      print(tbl_names[i])
+      conf$table <- tolower(tbl_names[i])
+      source <- sprintf('"%s" "%s"', tmp_dir_kihid, tbl_names[i])
+      ## Export to postgis database.
+      conf$primary_key <- "id"
+      conf$s_srs <- "EPSG:3301"
+      conf$t_srs <- "EPSG:3301"
+      geometry_type <- "PROMOTE_TO_MULTI"
+      if (tbl_names[i] %in% c("Kirik_p")) encoding <- "ISO-8859-4" else encoding <- "UTF-8"
+      cmd <- sprintf(
+        paste0(
+          "export PGCLIENTENCODING=%s; ",
+          "ogr2ogr -progress --config PG_USE_COPY YES --config PGCLIENTENCODING %s -f PostgreSQL ",
+          "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
+          "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
+          "-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
+          "-s_srs %s -t_srs %s -nlt %s -skipfailures"
+        ), encoding, encoding,
+        conf$dbname, conf$host, conf$port, conf$user, conf$password,
+        conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
+        conf$s_srs, conf$t_srs, geometry_type
+      )
+      system(cmd)
+      cat(sprintf(
+        "\nShp fail %s kopeeriti POSTGIS andmebaasi %s.%s\n\n",
+        ls[i], conf$schema, conf$table
+      ))
+    }
+    # Delete unnecessary files.
+    system(sprintf("find %s -type f -not -name '%s' -print0 | xargs -0 rm --", tmp_dir, map_shapefile))
+  }
+}

+ 89 - 0
R/maaamet_mullakaart.R

@@ -0,0 +1,89 @@
+#' Maa-ameti mullakaart
+#'
+#' Source: \url{https://geoportaal.maaamet.ee/est/Andmed-ja-kaardid/Mullastiku-kaart-p33.html} . Andmed salvestatakse postgisi andmebaasi. Schema = 'eesti'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+#' @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()]
+#' @keywords postgis, maps, ESRI Shpfile, OSM
+#' @export
+#' @examples
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' maaamet_mullakaart(conf = conf)
+#' }
+maaamet_mullakaart <- function(conf = NULL) {
+  ans <- utils::askYesNo("Do you want to import maps into database?", default = F)
+  if (!ans | is.na(ans)) {
+    cat("\n------------------------\n")
+    cat("Kaardikihte ei lisatud.")
+    cat("\n------------------------\n")
+    return()
+  }
+  if (ans) {
+    # Temp directory
+    tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "maaamet_mullakaart")
+    if (!dir.exists(tmp_dir)) {
+      dir.create(tmp_dir)
+    }
+    # Download link
+    url <- "https://geoportaal.maaamet.ee/docs/muld/Mullakaart_SHP.zip"
+    # Estonia shapefile (ZIP archive)
+    map_shapefile <- "Mullakaart_SHP.zip"
+    # Download and save
+    url_download <- sprintf("%s", url)
+    saveTo <- sprintf("%s/%s", tmp_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 = tmp_dir)
+    # List of files
+    ls <- list.files(path = tmp_dir, pattern = ".dbf")
+    ls_long <- list.files(path = tmp_dir, pattern = ".dbf", full.names = T)
+    tbl_names <- unlist(strsplit(x = ls, split = ".dbf"))
+    # Export to postgis
+    if (is.null(conf)) {
+      conf <- ruut::get_config()
+      conf$schema <- "eesti"
+    }
+    # New schema
+    ruut::db_create_new_schema(conf = conf)
+    # Multi layer
+    for (i in 1:length(tbl_names)) {
+      print(tbl_names[i])
+      conf$table <- tolower(tbl_names[i])
+      source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
+      ## Export to postgis database.
+      conf$primary_key <- "id"
+      conf$s_srs <- "EPSG:3301"
+      conf$t_srs <- "EPSG:3301"
+      geometry_type <- "PROMOTE_TO_MULTI"
+      cmd <- sprintf(
+        paste0(
+          "export PGCLIENTENCODING=UTF-8; ",
+          "ogr2ogr -progress --config PG_USE_COPY YES --config  PGCLIENTENCODING UTF-8 -f PostgreSQL ",
+          "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
+          "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
+          "-lco GEOMETRY_NAME=geom -lco FID=%s -nln %s.%s ",
+          "-s_srs %s -t_srs %s -nlt %s"
+        ),
+        conf$dbname, conf$host, conf$port, conf$user, conf$password,
+        conf$sslmode, conf$schema, source, conf$primary_key, conf$schema, conf$table,
+        conf$s_srs, conf$t_srs, geometry_type
+      )
+      system(cmd)
+
+
+      cat(sprintf(
+        "\nShp fail %s kopeeriti POSTGIS andmebaasi %s.%s\n\n",
+        ls[i], conf$schema, conf$table
+      ))
+    }
+    # Delete unnecessary files.
+    system(sprintf("find %s -type f -not -name '%s' -print0 | xargs -0 rm --", tmp_dir, map_shapefile))
+  }
+}

+ 32 - 0
man/maaamet_eesti.Rd

@@ -0,0 +1,32 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/maaamet_eesti.R
+\name{maaamet_eesti}
+\alias{maaamet_eesti}
+\title{Maa-ameti kogu Eesti andmestik põhikaardina}
+\usage{
+maaamet_eesti(conf = NULL)
+}
+\arguments{
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
+}
+\description{
+Source: \url{https://geoportaal.maaamet.ee/est/Ruumiandmed/Topokaardid-ja-aluskaardid/Eesti-pohikaart-1-10000/Laadi-pohikaart-alla-p612.html} . Andmed salvestatakse postgisi andmebaasi. Schema = 'eesti'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+}
+\examples{
+\dontrun{
+
+conf <- ruut::get_config()
+maaamet_eesti(conf = conf)
+}
+}
+\seealso{
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}
+}
+\keyword{ESRI}
+\keyword{OSM}
+\keyword{Shpfile,}
+\keyword{maps,}
+\keyword{postgis,}

+ 32 - 0
man/maaamet_mullakaart.Rd

@@ -0,0 +1,32 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/maaamet_mullakaart.R
+\name{maaamet_mullakaart}
+\alias{maaamet_mullakaart}
+\title{Maa-ameti mullakaart}
+\usage{
+maaamet_mullakaart(conf = NULL)
+}
+\arguments{
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
+}
+\description{
+Source: \url{https://geoportaal.maaamet.ee/est/Andmed-ja-kaardid/Mullastiku-kaart-p33.html} . Andmed salvestatakse postgisi andmebaasi. Schema = 'eesti'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+}
+\examples{
+\dontrun{
+
+conf <- ruut::get_config()
+maaamet_mullakaart(conf = conf)
+}
+}
+\seealso{
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}
+}
+\keyword{ESRI}
+\keyword{OSM}
+\keyword{Shpfile,}
+\keyword{maps,}
+\keyword{postgis,}