|
@@ -0,0 +1,52 @@
|
|
|
|
|
+#' Teeregistri WFS kihid
|
|
|
|
|
+#'
|
|
|
|
|
+#' Eesti avaandmete \url{https://avaandmed.eesti.ee/datasets?emsId=35} teabevärava kaudu teederegistri WFS (Web Feature Service) andmete eksportimine postgisandmebaasi. WFS andmestiku kirjeldus: \url{https://teeregister-api.mnt.ee/teenus/wfs?request=GetCapabilities&service=WFS}
|
|
|
|
|
+#'
|
|
|
|
|
+#' @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, WFS, OSM
|
|
|
|
|
+#' @export
|
|
|
|
|
+#' @examples
|
|
|
|
|
+#' \dontrun{
|
|
|
|
|
+#'
|
|
|
|
|
+#' conf <- ruut::get_config()
|
|
|
|
|
+#' teeregister_wfs(conf = conf)
|
|
|
|
|
+#' }
|
|
|
|
|
+teeregister_wfs <- function(conf = NULL) {
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ # Export to postgis
|
|
|
|
|
+ if (is.null(conf)) {
|
|
|
|
|
+ conf <- ruut::get_config()
|
|
|
|
|
+ conf$schema <- "teeregister_wfs"
|
|
|
|
|
+ }
|
|
|
|
|
+ # New schema
|
|
|
|
|
+ ruut::db_create_new_schema(conf = conf)
|
|
|
|
|
+ ## Teeregistri avaandmete kihtide lugemine
|
|
|
|
|
+ wfs_list <- loe_teeregistri_wfs_kihid()
|
|
|
|
|
+ layer_list <- wfs_list[, "layer"]
|
|
|
|
|
+ pg <- ruut::construct_ogr2ogr_PG_connect_str(conf = conf)
|
|
|
|
|
+ ## WFS andmekogu
|
|
|
|
|
+ wfs <- "\"WFS:https://teeregister-api.mnt.ee/teenus/wfs\""
|
|
|
|
|
+ # Andmete kopeerimine andmebaasi
|
|
|
|
|
+ for (i in 1:length(layer_list)) {
|
|
|
|
|
+ wfs_layer <- layer_list[i]
|
|
|
|
|
+ conf$table <- gsub("ms:", "", wfs_layer)
|
|
|
|
|
+ cat(sprintf("\n-----------------\nKihi \"%s\" kopeerimine andmebaasi.\n", wfs_layer))
|
|
|
|
|
+ q <- sprintf(
|
|
|
|
|
+ "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL %s -lco DIM=2 %s %s -overwrite -nlt GEOMETRY -lco GEOMETRY_NAME=geometry -lco FID=id -nln %s.%s -s_srs EPSG:3301 -t_srs EPSG:4326 -a_srs EPSG:4326 -nlt PROMOTE_TO_MULTI ",
|
|
|
|
|
+ pg, wfs, wfs_layer, conf$schema, conf$table
|
|
|
|
|
+ )
|
|
|
|
|
+ cat(sprintf("\n%s\n", q))
|
|
|
|
|
+ system(q)
|
|
|
|
|
+ cat(sprintf("\n%s\n-------------\n", "Kopeerimine l\U00F5petati"))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|