Forráskód Böngészése

Lisatud 'inspire_grids'.

Ardo Kubjas 5 éve
szülő
commit
5b292a280a
2 módosított fájl, 60 hozzáadás és 0 törlés
  1. 1 0
      DESCRIPTION
  2. 59 0
      R/inspire_grids.R

+ 1 - 0
DESCRIPTION

@@ -12,3 +12,4 @@ Encoding: UTF-8
 LazyData: true
 Roxygen: list(markdown = TRUE)
 RoxygenNote: 7.1.1.9000
+Imports: ruut, qgisprocess, DBI, pool, RPostgreSQL, sf, raster, stars, rgdal, tidyverse, inborutils, rvest, seleniumPipes, rjson, methods, utils

+ 59 - 0
R/inspire_grids.R

@@ -0,0 +1,59 @@
+#' INSPIRE kaardiruudud
+#'
+#' Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2
+#' @examples
+#' ## Not run:
+#' ##
+#' ## inspire_grids()
+#' ##
+#' ## End(**Not run**)
+inspire_grids <- function() {
+  ans <- utils::askYesNo("Do you want to use askYesNo?")
+  if (!ans) {
+    cat("\n------------------------\n")
+    cat("Kaardikihte ei lisatud.")
+    cat("\n------------------------\n")
+  }
+  if (ans) {
+    # 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"
+    # Estonia shapefile (ZIP archive)
+    map_shapefile <- "Estonia_shapefile.zip"
+    # Download and save
+    saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
+    utils::download.file(
+      url = url,
+      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 = ".shp")
+    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()
+    config$schema <- schema
+    # New schema
+    ruut::db_create_new_schema(conf = config)
+    # Multy 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:3035", 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
+      ))
+    }
+  }
+}