|
|
@@ -1,11 +1,10 @@
|
|
|
#' 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
|
|
|
+#' @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
|
|
|
#' ## Not run:
|
|
|
@@ -13,8 +12,7 @@
|
|
|
#' ## maaamet_kaardiruudud()
|
|
|
#' ##
|
|
|
#' ## End(**Not run**)
|
|
|
-maaamet_kaardiruudud <- function(config = NULL, schema = "maaamet",
|
|
|
- url = NULL) {
|
|
|
+maaamet_kaardiruudud <- function(conf = NULL) {
|
|
|
ans <- utils::askYesNo("Do you want to import maps into database?")
|
|
|
if (!ans) {
|
|
|
cat("\n------------------------\n")
|
|
|
@@ -22,31 +20,32 @@ maaamet_kaardiruudud <- function(config = NULL, schema = "maaamet",
|
|
|
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
|
|
|
- }
|
|
|
+ # Download links
|
|
|
+ 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"
|
|
|
+ )
|
|
|
# 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
|
|
|
+ if (is.null(conf)) {
|
|
|
+ conf <- ruut::get_config()
|
|
|
+ conf$schema <- "maaamet"
|
|
|
+ }
|
|
|
# New schema
|
|
|
- ruut::db_create_new_schema(conf = config)
|
|
|
+ ruut::db_create_new_schema(conf = conf)
|
|
|
for (j in 1:length(urls)) {
|
|
|
+ # Temp directory
|
|
|
+ tmp_dir <- sprintf("/tmp/maaamet_epk/%s", j)
|
|
|
+ if (!dir.exists(tmp_dir)) {
|
|
|
+ dir.create(tmp_dir, recursive = T)
|
|
|
+ }
|
|
|
+ # Download and save
|
|
|
+ saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
|
|
|
utils::download.file(
|
|
|
url = urls[j],
|
|
|
destfile = saveTo, method = "curl", extra = "-L"
|
|
|
@@ -60,21 +59,21 @@ maaamet_kaardiruudud <- function(config = NULL, schema = "maaamet",
|
|
|
# Multi layer
|
|
|
for (i in 1:length(tbl_names)) {
|
|
|
print(tbl_names[i])
|
|
|
- config$table <- tbl_names[i]
|
|
|
+ conf$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,
|
|
|
+ dir = tmp_dir, layer = tbl_names[i], conf = conf,
|
|
|
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
|
|
|
+ ls[i], conf$schema, conf$table
|
|
|
))
|
|
|
}
|
|
|
# Delete temp directory
|
|
|
- system(sprintf("rm -rf %s/*", tmp_dir))
|
|
|
+ # system(sprintf("rm -rf %s/*", tmp_dir))
|
|
|
}
|
|
|
}
|
|
|
}
|