|
@@ -15,56 +15,91 @@
|
|
|
#' conf <- ruut::get_config()
|
|
#' conf <- ruut::get_config()
|
|
|
#' maaamet_ortofotod(epk10t = 54711, dir = "~/ortofotod", conf = conf)
|
|
#' maaamet_ortofotod(epk10t = 54711, dir = "~/ortofotod", conf = conf)
|
|
|
#' }
|
|
#' }
|
|
|
-maaamet_ortofotod <- function(epk10t = NULL, dir = "~/ortofotod", conf = NULL) {
|
|
|
|
|
- # 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) {
|
|
|
|
|
- cat(sprintf("\n---------------\n\nValitud epk10t ruudu number %s ei ole \u00F5ige.\n", epk10t))
|
|
|
|
|
- return()
|
|
|
|
|
- }
|
|
|
|
|
- # GEOTIFF fotode salvestamise kataloog.
|
|
|
|
|
- if (!dir.exists(dir)) dir.create(dir, recursive = T)
|
|
|
|
|
|
|
+maaamet_ortofotod <-
|
|
|
|
|
+ function(epk10t = NULL,
|
|
|
|
|
+ dir = "~/ortofotod",
|
|
|
|
|
+ conf = NULL) {
|
|
|
|
|
+ # 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) {
|
|
|
|
|
+ cat(
|
|
|
|
|
+ sprintf(
|
|
|
|
|
+ "\n---------------\n\nValitud epk10t ruudu number %s ei ole \u00F5ige.\n",
|
|
|
|
|
+ epk10t
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ return()
|
|
|
|
|
+ }
|
|
|
|
|
+ # GEOTIFF fotode salvestamise kataloog.
|
|
|
|
|
+ if (!dir.exists(dir))
|
|
|
|
|
+ dir.create(dir, recursive = T)
|
|
|
|
|
|
|
|
- ## Geotiff failide allalaadimine
|
|
|
|
|
- # Näidis lehelt mille kaudu saab geotiff faile alla laadida.
|
|
|
|
|
- url_demo <- paste0(
|
|
|
|
|
- "https://geoportaal.maaamet.ee/index.php?",
|
|
|
|
|
- "lang_id=1&plugin_act=otsing&page_id=610&=&",
|
|
|
|
|
- "kaardiruut=62294&andmetyyp=ortofoto_eesti_rgb&_=1612349208090"
|
|
|
|
|
- )
|
|
|
|
|
- url_source <- urltools::url_decode(url_demo)
|
|
|
|
|
- params <- urltools::param_get(urls = url_source) # get params
|
|
|
|
|
- parsed_address <- urltools::url_parse(url_source)
|
|
|
|
|
- # Kui geotiff fail on olemas, siis me seda enam ei alla ei lae.
|
|
|
|
|
- if (length(list.files(path = dir, pattern = as.character(epk10t))) > 0) {
|
|
|
|
|
- cat(sprintf("\nFail %s on juba olemas.\n", epk10t))
|
|
|
|
|
- return()
|
|
|
|
|
- }
|
|
|
|
|
- url_new <- urltools::param_set(url_source, key = "kaardiruut", value = epk10t)
|
|
|
|
|
- ## Allalaadimine
|
|
|
|
|
- html_file <- readLines(url_new)
|
|
|
|
|
- page <- xml2::read_html(html_file[1])
|
|
|
|
|
- website <- ""
|
|
|
|
|
- website <- page %>%
|
|
|
|
|
- rvest::html_nodes("li a") %>%
|
|
|
|
|
- rvest::html_attr("href")
|
|
|
|
|
- parsed_address$parameter <- stringr::str_split(website[1], "[?]")[[1]][2]
|
|
|
|
|
- geotiff_download_url <- urltools::url_compose(parsed_urls = parsed_address)
|
|
|
|
|
- save_to_file <- sprintf("%s/%s.zip", dir, epk10t)
|
|
|
|
|
- utils::download.file(url = geotiff_download_url, method = "curl", extra = "-L", destfile = save_to_file)
|
|
|
|
|
- # zip failide lahtpakkimine
|
|
|
|
|
- cmd <- sprintf("unzip %s -d %s/; mv %s /tmp", save_to_file, dir, save_to_file)
|
|
|
|
|
- system(cmd)
|
|
|
|
|
- cmd <- sprintf("mv %s/*.tab /tmp", dir)
|
|
|
|
|
- system(cmd)
|
|
|
|
|
- cmd <- sprintf("mv %s/*.tfw /tmp", dir)
|
|
|
|
|
- system(cmd)
|
|
|
|
|
- ls <- list.files(path = dir, pattern = sprintf("%s.tif", epk10t))
|
|
|
|
|
- if (length(ls) > 0) {
|
|
|
|
|
- cat(sprintf("\n---------------\n\nValitud epk10t ruudu number %s eba\u00F5nnestus.\n", epk10t))
|
|
|
|
|
- } else {
|
|
|
|
|
- cat(sprintf("\n---------------\n\nValitud epk10t ruudu number %s \u00F5nnestus.\n", epk10t))
|
|
|
|
|
|
|
+ ## Geotiff failide allalaadimine
|
|
|
|
|
+ # Näidis lehelt mille kaudu saab geotiff faile alla laadida.
|
|
|
|
|
+ url_demo <- paste0(
|
|
|
|
|
+ "https://geoportaal.maaamet.ee/index.php?",
|
|
|
|
|
+ "lang_id=1&plugin_act=otsing&page_id=610&=&",
|
|
|
|
|
+ "kaardiruut=62294&andmetyyp=ortofoto_eesti_rgb&_=1612349208090"
|
|
|
|
|
+ )
|
|
|
|
|
+ url_source <- urltools::url_decode(url_demo)
|
|
|
|
|
+ params <- urltools::param_get(urls = url_source) # get params
|
|
|
|
|
+ parsed_address <- urltools::url_parse(url_source)
|
|
|
|
|
+ # Kui geotiff fail on olemas, siis me seda enam ei alla ei lae.
|
|
|
|
|
+ if (length(list.files(path = dir, pattern = as.character(epk10t))) > 0) {
|
|
|
|
|
+ cat(sprintf("\nFail %s on juba olemas.\n", epk10t))
|
|
|
|
|
+ return(TRUE)
|
|
|
|
|
+ }
|
|
|
|
|
+ url_new <-
|
|
|
|
|
+ urltools::param_set(url_source, key = "kaardiruut", value = epk10t)
|
|
|
|
|
+ ## Allalaadimine
|
|
|
|
|
+ html_file <- readLines(url_new)
|
|
|
|
|
+ page <- xml2::read_html(html_file[1])
|
|
|
|
|
+ website <- ""
|
|
|
|
|
+ website <- page %>%
|
|
|
|
|
+ rvest::html_nodes("li a") %>%
|
|
|
|
|
+ rvest::html_attr("href")
|
|
|
|
|
+ if (length(website) == 0) {
|
|
|
|
|
+ return(NULL)
|
|
|
|
|
+ }
|
|
|
|
|
+ parsed_address$parameter <-
|
|
|
|
|
+ stringr::str_split(website[1], "[?]")[[1]][2]
|
|
|
|
|
+ geotiff_download_url <-
|
|
|
|
|
+ urltools::url_compose(parsed_urls = parsed_address)
|
|
|
|
|
+ save_to_file <- sprintf("%s/%s.zip", dir, epk10t)
|
|
|
|
|
+ utils::download.file(
|
|
|
|
|
+ url = geotiff_download_url,
|
|
|
|
|
+ method = "curl",
|
|
|
|
|
+ extra = "-L",
|
|
|
|
|
+ destfile = save_to_file
|
|
|
|
|
+ )
|
|
|
|
|
+ # zip failide lahtpakkimine
|
|
|
|
|
+ cmd <-
|
|
|
|
|
+ sprintf("unzip %s -d %s/; mv %s /tmp", save_to_file, dir, save_to_file)
|
|
|
|
|
+ system(cmd)
|
|
|
|
|
+ cmd <- sprintf("mv %s/*.tab /tmp", dir)
|
|
|
|
|
+ system(cmd)
|
|
|
|
|
+ cmd <- sprintf("mv %s/*.tfw /tmp", dir)
|
|
|
|
|
+ system(cmd)
|
|
|
|
|
+ ls <-
|
|
|
|
|
+ list.files(path = dir, pattern = sprintf("%s.tif", epk10t))
|
|
|
|
|
+ if (length(ls) > 0) {
|
|
|
|
|
+ cat(
|
|
|
|
|
+ sprintf(
|
|
|
|
|
+ "\n---------------\n\nValitud epk10t ruudu number %s eba\u00F5nnestus.\n",
|
|
|
|
|
+ epk10t
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ return (NULL)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cat(
|
|
|
|
|
+ sprintf(
|
|
|
|
|
+ "\n---------------\n\nValitud epk10t ruudu number %s \u00F5nnestus.\n",
|
|
|
|
|
+ epk10t
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ return(geotiff_download_url)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return(geotiff_download_url)
|
|
|
|
|
-}
|
|
|