浏览代码

Muudetud: osm ja ortofotod.

Ardo Kubjas 5 年之前
父节点
当前提交
91ab246436
共有 2 个文件被更改,包括 18 次插入17 次删除
  1. 7 7
      R/maaamet_ortofotod.R
  2. 11 10
      R/osm_shp.R

+ 7 - 7
R/maaamet_ortofotod.R

@@ -10,13 +10,13 @@
 #' @keywords maa-amet, ortofoto
 #' @export
 #' @examples
-#' ## Not run:
-#' ##
-#' ## maaamet_ortofotod()
-#' ##
-#' ## End(**Not run**)
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' maaamet_ortofotod(epk10t = 54711, dir = "~/ortofotod", conf = conf)
+#' }
 maaamet_ortofotod <- function(epk10t = NULL, dir = "~/ortofotod", conf = NULL) {
-  # epk10t <- 54711
+  # epk10t <- 54711; epk10t <- 65813
   # epk10t numbri õigsuse kontroll
   epk10t_all <- utils::read.csv(file = system.file("csv", "epk10t.csv", package = "estmap"), header = T)[, "nr"]
   if (!epk10t %in% epk10t_all) {
@@ -44,7 +44,7 @@ maaamet_ortofotod <- function(epk10t = NULL, dir = "~/ortofotod", conf = NULL) {
   url_new <- urltools::param_set(url_source, key = "kaardiruut", value = epk10t)
   ## Allalaadimine
   html_file <- readLines(url_new)
-  page <- xml2::read_html(html_file)
+  page <- xml2::read_html(html_file[1])
   website <- ""
   website <- page %>%
     rvest::html_nodes("li a") %>%

+ 11 - 10
R/osm_shp.R

@@ -7,21 +7,22 @@
 #' @keywords postgis, maps, ESRI Shpfile, OSM
 #' @export
 #' @examples
-#' ## Not run:
-#' ##
-#' ## osm_shp()
-#' ##
-#' ## End(**Not run**)
+#' \dontrun{
+#'
+#' conf <- ruut::get_config()
+#' osm_shp(conf = conf)
+#' }
 osm_shp <- function(conf = NULL) {
-  ans <- utils::askYesNo("Do you want to import maps into database?")
-  if (!ans) {
+  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 <- "/tmp/osm_shp"
+    tmp_dir <- sprintf("%s/tmp/%s", system.file(package = "estmap"), "osm_shp")
     if (!dir.exists(tmp_dir)) {
       dir.create(tmp_dir)
     }
@@ -67,7 +68,7 @@ osm_shp <- function(conf = NULL) {
         ls[i], conf$schema, conf$table
       ))
     }
-    # Delete temp directory
-    # system(sprintf("rm -rf %s/*", tmp_dir))
+    # Delete unnecessary files.
+    system(sprintf("find %s -type f -not -name '%s' -print0 | xargs -0 rm --", tmp_dir, map_shapefile))
   }
 }