Bläddra i källkod

Olemasolevatest funktsioonidest eemaldatud argumendid: schema ja url.

Ardo Kubjas 5 år sedan
förälder
incheckning
fc730278e3

+ 1 - 0
NAMESPACE

@@ -3,3 +3,4 @@
 export(inspire_grids)
 export(maaamet_kaardiruudud)
 export(maaamet_kataster)
+export(osm_shp)

+ 27 - 23
R/inspire_grids.R

@@ -1,11 +1,10 @@
 #' 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. 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 @@
 #' ## inspire_grids()
 #' ##
 #' ## End(**Not run**)
-inspire_grids <- function(config = NULL, schema = "inspire",
-                          url = NULL) {
+inspire_grids <- function(conf = NULL) {
   ans <- utils::askYesNo("Do you want to import maps into database?")
   if (!ans) {
     cat("\n------------------------\n")
@@ -23,45 +21,51 @@ inspire_grids <- function(config = NULL, schema = "inspire",
   }
   if (ans) {
     # Temp directory
-    tmp_dir <- tempdir()
+    tmp_dir <- "/tmp/inspire"
+    if (!dir.exists(tmp_dir)) {
+      dir.create(tmp_dir)
+    }
     # Download link
-    if (is.null(url)) url <- "https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/estonia-shapefile/download"
+    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
+    url_download <- sprintf("%s/%s", url, "")
     saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
-    utils::download.file(
-      url = url,
-      destfile = saveTo, method = "curl", extra = "-L"
-    )
+    if (!file.exists(saveTo)) {
+      utils::download.file(
+        url = url_download,
+        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"))
+    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"))
     # Export to postgis
-    if (is.null(config)) config <- ruut::get_config()
-    config$schema <- schema
+    if (is.null(conf)) conf <- ruut::get_config()
+    conf$schema <- "inspire"
     # New schema
-    ruut::db_create_new_schema(conf = config)
+    ruut::db_create_new_schema(conf = conf)
     # 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: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
+        ls[i], conf$schema, conf$table
       ))
     }
     # Delete temp directory
-    system(sprintf("rm -rf %s/*", tmp_dir))
+    # system(sprintf("rm -rf %s/*", tmp_dir))
   }
 }

+ 30 - 31
R/maaamet_kaardiruudud.R

@@ -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))
     }
   }
 }

+ 29 - 23
R/maaamet_kataster.R

@@ -1,11 +1,10 @@
 #' Maa-ameti katasriüksused
 #'
 #' Source: hhttps://geoportaal.maaamet.ee/docs/katastripiirid/paev/KATASTER_EESTI_SHP.zip. 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_kataster()
 #' ##
 #' ## End(**Not run**)
-maaamet_kataster <- function(config = NULL, schema = "maaamet",
-                             url = NULL) {
+maaamet_kataster <- function(conf = NULL) {
   ans <- utils::askYesNo("Do you want to import maps into database?")
   if (!ans) {
     cat("\n------------------------\n")
@@ -23,45 +21,53 @@ maaamet_kataster <- function(config = NULL, schema = "maaamet",
   }
   if (ans) {
     # Temp directory
-    tmp_dir <- tempdir()
+    tmp_dir <- "/tmp/maaamet_kataster"
+    if (!dir.exists(tmp_dir)) {
+      dir.create(tmp_dir)
+    }
     # Download link
-    if (is.null(url)) url <- "https://geoportaal.maaamet.ee/docs/katastripiirid/paev"
+    url <- "https://geoportaal.maaamet.ee/docs/katastripiirid/paev"
     # Estonia shapefile (ZIP archive)
     map_shapefile <- "KATASTER_EESTI_SHP.zip"
     # Download and save
+    url_download <- sprintf("%s/%s", url, map_shapefile)
     saveTo <- sprintf("%s/%s", tmp_dir, map_shapefile)
-    utils::download.file(
-      url = sprintf("%s/%s", url, map_shapefile),
-      destfile = saveTo, method = "curl", extra = "-L"
-    )
+    if (!file.exists(saveTo)) {
+      utils::download.file(
+        url = url_download,
+        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"))
+    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"))
     # 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)
     # 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))
   }
 }

+ 9 - 0
inst/abifailid/valikud_examples.R

@@ -0,0 +1,9 @@
+## Examples
+
+
+#' @examples
+#' ## Not run:
+#' ##
+#' ## xxxxxxxxxxxxxxxxx()
+#' ##
+#' ## End(**Not run**)

+ 3 - 0
inst/abifailid/valikud_keywords.R

@@ -0,0 +1,3 @@
+## Keywords
+
+system(sprintf("cat %s",file.path(R.home("doc"), "KEYWORDS")))

+ 35 - 0
inst/abifailid/valikud_params.R

@@ -0,0 +1,35 @@
+## Arguments
+
+# \code{\link{brocolors}}
+
+## Mina:
+
+#' @param dir	The directory where the shapefiles are located.
+#' @param layer str Layer to use.
+#' @param schema	str A database schema name.
+#' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
+#' @param x	object of class 'sf', 'sfc' or 'sfg'.
+#' @param type num select value: 1-3. 0: Envelope (Bounding Box), 1: Minimum Oriented Rectangle, 2: Minimum Enclosing Circle, 3: Convex Hull.
+#' @param x	object of 'qgis_result' spatial object.
+#' @param id A specified feature id will be processed. Unique field database. Default value 'fid'.
+#' @param crs_source CRS source CRS for example 'EPSG:3301' (Estonia). Default is 'EPSG:4326'.
+#' @param crs_target CRS target CRS for example 'EPSG:4326'. Default is 'EPSG:4326'.
+#' @param geometry_type str Force a geometry type for new layer.  One of: NONE, GEOMETRY, POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTIPOINT, MULTIPOLYGON, or MULTILINESTRING, or PROMOTE_TO_MULTI or CONVERT_TO_LINEAR.  Add "25D" for 3D layers.
+
+
+
+
+#' @param ... Passed to processx::run().
+#' @param sort	If TRUE, will show the largest groups at the top.
+#' @param env A list() of environment variables. Defaults to qgis_env().
+#' @param path A path to the 'qgis_process' executable. Defaults to qgis_path().
+#' @param action An action to take if the 'qgis_process' executable could not be found.
+#' @param quiet Use FALSE to display more information about the command, possibly useful for debugging.
+#' @param query Use TRUE to refresh the cached value.
+#' @param x	An object passed to a QGIS processing algorithm
+#' @param spec	A list() with values for algorithm, name, description, and qgis_type. See qgis_argument_spec() to create a blank spec for testing.
+#' @param value	The result of as_qgis_argument() after the QGIS processing algorithm has been run.
+#' @param algorithm	A qualified algorithm name (e.g., "native:filedownloader") or a path to a QGIS model file.
+#' @param name, description, qgis_type, available_values, acceptable_values	Column values of arguments denoting the argument name, description, and acceptable values.
+#' @param arguments	The result of qgis_arguments().
+#' @param src	A data source

+ 14 - 0
inst/abifailid/valikud_return.R

@@ -0,0 +1,14 @@
+## Return
+
+## Mina:
+#' @return The object with class 'qgis_object'.
+#' @return No output.
+#' @return A array of all database schemas.
+#' @return Connection to the database.
+#' @return New schema created.
+#' @return TRUE/FALSE.
+
+
+#' @param x A number.
+#' @param y A number.
+#' @return The sum of \code{x} and \code{y}.

+ 14 - 0
inst/abifailid/valikud_seealso.R

@@ -0,0 +1,14 @@
+## Arguments
+
+#' @seealso \code{\link{prod}} for products, \code{\link{cumsum}} for cumulative
+#'   sums, and \code{\link{colSums}}/\code{\link{rowSums}} marginal sums over
+#'   high-dimensional arrays.
+
+
+#' @seealso [ruut::db_connect()], [ruut::get_config()]
+
+
+#' @seealso [ruut::cat_function()], [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::convert_sf2qgis()], [ruut::copy_qgis_object_to_db()], [ruut::copy_shp_to_db()], [ruut::db_all_schemas()], [ruut::db_connect()], [ruut::db_create_new_schema()], [ruut::db_is_shema_exist()], [ruut::db_table_colnames()], [ruut::get_config()], [ruut::pk_boundary_box()], [ruut::qgis_algorithm_search_by_word()]
+#'
+#'
+#' \url{https://gdal.org/programs/ogr2ogr.html}, \url{https://github.com/paleolimbot/qgisprocess}, \url{https://r-spatial.github.io/sf/}

+ 8 - 8
man/inspire_grids.Rd

@@ -4,14 +4,13 @@
 \alias{inspire_grids}
 \title{INSPIRE kaardiruudud}
 \usage{
-inspire_grids(config = NULL, schema = "inspire", url = NULL)
+inspire_grids(conf = 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.}
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
 }
 \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.
@@ -24,9 +23,10 @@ Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andm
 ## End(**Not run**)
 }
 \seealso{
-\code{\link[ruut:get_config]{ruut::get_config()}}
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}
 }
 \keyword{ESRI}
-\keyword{Shpfile}
+\keyword{OSM}
+\keyword{Shpfile,}
 \keyword{maps,}
 \keyword{postgis,}

+ 8 - 8
man/maaamet_kaardiruudud.Rd

@@ -4,14 +4,13 @@
 \alias{maaamet_kaardiruudud}
 \title{Maa-ameti kaardiruudukesed}
 \usage{
-maaamet_kaardiruudud(config = NULL, schema = "maaamet", url = NULL)
+maaamet_kaardiruudud(conf = 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.}
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
 }
 \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.
@@ -24,9 +23,10 @@ Source: https://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2. Andm
 ## End(**Not run**)
 }
 \seealso{
-\code{\link[ruut:get_config]{ruut::get_config()}}
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}
 }
 \keyword{ESRI}
-\keyword{Shpfile}
+\keyword{OSM}
+\keyword{Shpfile,}
 \keyword{maps,}
 \keyword{postgis,}

+ 8 - 8
man/maaamet_kataster.Rd

@@ -4,14 +4,13 @@
 \alias{maaamet_kataster}
 \title{Maa-ameti katasriüksused}
 \usage{
-maaamet_kataster(config = NULL, schema = "maaamet", url = NULL)
+maaamet_kataster(conf = 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.}
+\item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+}
+\value{
+No output.
 }
 \description{
 Source: hhttps://geoportaal.maaamet.ee/docs/katastripiirid/paev/KATASTER_EESTI_SHP.zip. Andmed salvestatakse postgisi andmebaasi. Schema = 'inspire'. Koniguratsiooni muutmiseks muuda konfiguratsiooni. Muutujate vaikeväärtused on sellised, et ei ole vaja midagi muuta.
@@ -24,9 +23,10 @@ Source: hhttps://geoportaal.maaamet.ee/docs/katastripiirid/paev/KATASTER_EESTI_S
 ## End(**Not run**)
 }
 \seealso{
-\code{\link[ruut:get_config]{ruut::get_config()}}
+\code{\link[ruut:get_config]{ruut::get_config()}}, \code{\link[ruut:copy_shp_to_db]{ruut::copy_shp_to_db()}}
 }
 \keyword{ESRI}
-\keyword{Shpfile}
+\keyword{OSM}
+\keyword{Shpfile,}
 \keyword{maps,}
 \keyword{postgis,}