Kaynağa Gözat

Lisatud 'maaamet_kaardiruudud'.

Ardo Kubjas 5 yıl önce
ebeveyn
işleme
afc4bc4532
5 değiştirilmiş dosya ile 145 ekleme ve 10 silme
  1. 1 0
      NAMESPACE
  2. 15 7
      R/inspire_grids.R
  3. 80 0
      R/maaamet_kaardiruudud.R
  4. 17 3
      man/inspire_grids.Rd
  5. 32 0
      man/maaamet_kaardiruudud.Rd

+ 1 - 0
NAMESPACE

@@ -1,3 +1,4 @@
 # Generated by roxygen2: do not edit by hand
 
 export(inspire_grids)
+export(maaamet_kaardiruudud)

+ 15 - 7
R/inspire_grids.R

@@ -1,11 +1,20 @@
 #' INSPIRE kaardiruudud
 #'
-#' Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni.
+#' Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+#' @param config list configuration file ruut::get_config()
+#' @param schema str database schema name. Deafult is 'inspire'
+#' @param url link ESRI Shapefile download url.
+#' @seealso [ruut::get_config()]
 #' @keywords postgis, maps, ESRI Shpfile
 #' @export
 #' @examples
-#' inspire_grids()
-inspire_grids <- function() {
+#' ## Not run:
+#' ##
+#' ## inspire_grids()
+#' ##
+#' ## End(**Not run**)
+inspire_grids <- function(config = NULL, schema = "inspire",
+                          url = NULL) {
   ans <- utils::askYesNo("Do you want to import maps into database?")
   if (!ans) {
     cat("\n------------------------\n")
@@ -16,7 +25,7 @@ inspire_grids <- function() {
     # Temp directory
     tmp_dir <- tempdir()
     # Download link
-    url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
+    if (is.null(url)) url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
     # Estonia shapefile (ZIP archive)
     map_shapefile <- "Estonia_shapefile.zip"
     # Download and save
@@ -32,12 +41,11 @@ inspire_grids <- function() {
     ls_long <- list.files(path = tmp_dir, pattern = ".shp", full.names = T)
     tbl_names <- unlist(strsplit(x = ls, split = ".shp"))
     # Export to postgis
-    schema <- "inspire"
-    config <- ruut::get_config()
+    if (is.null(config)) config <- ruut::get_config()
     config$schema <- schema
     # New schema
     ruut::db_create_new_schema(conf = config)
-    # Multy layer
+    # Multi layer
     for (i in 1:length(tbl_names)) {
       print(tbl_names[i])
       config$table <- tbl_names[i]

+ 80 - 0
R/maaamet_kaardiruudud.R

@@ -0,0 +1,80 @@
+#' Maa-ameti kaardiruudukesed
+#'
+#' Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+#' @param config list configuration file ruut::get_config()
+#' @param schema str database schema name. Deafult is 'inspire'
+#' @param url link ESRI Shapefile download url.
+#' @seealso [ruut::get_config()]
+#' @keywords postgis, maps, ESRI Shpfile
+#' @export
+#' @examples
+#' ## Not run:
+#' ##
+#' ## maaamet_kaardiruudud()
+#' ##
+#' ## End(**Not run**)
+maaamet_kaardiruudud <- function(config = NULL, schema = "maaamet",
+                                 url = NULL) {
+  ans <- utils::askYesNo("Do you want to import maps into database?")
+  if (!ans) {
+    cat("\n------------------------\n")
+    cat("Kaardikihte ei lisatud.")
+    cat("\n------------------------\n")
+  }
+  if (ans) {
+    # Temp directory
+    tmp_dir <- tempdir(check = T)
+    # Download link
+    if (is.null(url)) {
+      urls <- c(
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk2T_SHP.zip",
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk10T_SHP.zip",
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk20T_shp.zip",
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk50T_shp.zip",
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk100T_shp.zip",
+        "https://geoportaal.maaamet.ee/docs/pohikaart/epk200T_shp.zip"
+      )
+    } else {
+      urls <- url
+    }
+    # Estonia shapefile (ZIP archive)
+    map_shapefile <- "maaamet_shapefile.zip"
+    # Download and save
+    saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
+    # Export to postgis
+    if (is.null(config)) config <- ruut::get_config()
+    config$schema <- schema
+    # New schema
+    ruut::db_create_new_schema(conf = config)
+    for (j in 1:length(urls)) {
+      utils::download.file(
+        url = urls[j],
+        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"))
+      # Multi layer
+      for (i in 1:length(tbl_names)) {
+        print(tbl_names[i])
+        config$table <- tbl_names[i]
+        source <- sprintf('"%s" "%s"', tmp_dir, tbl_names[i])
+        ## Export to postgis database.
+        ruut::copy_shp_to_db(
+          dir = tmp_dir, layer = tbl_names[i], conf = config,
+          id = "fid", crs_source = "EPSG:3301", crs_target = "EPSG:4326",
+          geometry_type = "POLYGON"
+        )
+        cat(sprintf(
+          "\nShp fail %s kopeeriti POSTGIS andmebaasi %s.%s\n\n",
+          ls[i], config$schema, config$table
+        ))
+      }
+      # Delete temp directory
+      system(sprintf("rm -rf %s/*", tmp_dir))
+    }
+  }
+}

+ 17 - 3
man/inspire_grids.Rd

@@ -4,13 +4,27 @@
 \alias{inspire_grids}
 \title{INSPIRE kaardiruudud}
 \usage{
-inspire_grids()
+inspire_grids(config = NULL, schema = "inspire", url = NULL)
+}
+\arguments{
+\item{config}{list configuration file ruut::get_config()}
+
+\item{schema}{str database schema name. Deafult is 'inspire'}
+
+\item{url}{link ESRI Shapefile download url.}
 }
 \description{
-Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni.
+Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
 }
 \examples{
-inspire_grids()
+## Not run:
+##
+## inspire_grids()
+##
+## End(**Not run**)
+}
+\seealso{
+\code{\link[ruut:get_config]{ruut::get_config()}}
 }
 \keyword{ESRI}
 \keyword{Shpfile}

+ 32 - 0
man/maaamet_kaardiruudud.Rd

@@ -0,0 +1,32 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/maaamet_kaardiruudud.R
+\name{maaamet_kaardiruudud}
+\alias{maaamet_kaardiruudud}
+\title{Maa-ameti kaardiruudukesed}
+\usage{
+maaamet_kaardiruudud(config = NULL, schema = "maaamet", url = NULL)
+}
+\arguments{
+\item{config}{list configuration file ruut::get_config()}
+
+\item{schema}{str database schema name. Deafult is 'inspire'}
+
+\item{url}{link ESRI Shapefile download url.}
+}
+\description{
+Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
+}
+\examples{
+## Not run:
+##
+## maaamet_kaardiruudud()
+##
+## End(**Not run**)
+}
+\seealso{
+\code{\link[ruut:get_config]{ruut::get_config()}}
+}
+\keyword{ESRI}
+\keyword{Shpfile}
+\keyword{maps,}
+\keyword{postgis,}