| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #' Piirkonna joonte lisamine
- #'
- #' Etteantud piirkonna geomeetrilise piirjoone ('piir') järele leitakse selles piirkonnas ja piirkonna piiriga piirnevad joonobjektid ().
- #'
- #' @param obj str Objekti nimi.
- #' @param pk Piirkonna geomeetriline joon.
- #' @param gpkg_home path Salvestatavate GPKG faili asukoht.
- #'
- #' @examples
- #' \dontrun{
- #'
- #' }
- piirkonnale_joonte_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tmp") {
- if (is.null(pk) || !sf::st_is_valid(pk)) {
- cat("\nPalun kontrolli geomeetrilise kujundi õigsust.\n")
- return()
- }
- if (is.null(obj)) {
- cat("\nPuudu on objekti nimi.\n")
- return()
- }
- cat(sprintf("\nAlgparameetrid: objekti nimi %s ja GPKG faili kataloog %s\n", obj, gpkg_home))
- postgres <- sprintf(
- "postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=%s checkPrimaryKeyUnicity=\'1\'",
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password, "Polygon"
- )
- postgres_point <- sprintf(
- "postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=%s checkPrimaryKeyUnicity=\'1\'",
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password, "Point"
- )
- postgres_line <- sprintf(
- "postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=%s checkPrimaryKeyUnicity=\'1\'",
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password, "Linestring"
- )
- dsn <- sprintf("%s/%s.gpkg", gpkg_home, obj) # Polygon
- dsn_p <- sprintf("%s/%s_p.gpkg", gpkg_home, obj) # Point
- dsn_l <- sprintf("%s/%s_l.gpkg", gpkg_home, obj) # Linestring
- ogr <- sprintf(
- "ogr:dbname='%s'",
- dsn_l
- )
- tmp_gpkg_file <- tempfile(fileext = ".gpkg")
- ## ----------------- punktfaili loomine -------------------
- ## -------------- epk2t_grids tsentroidid -----------------
- # ruut::qgis_algorithm_search_by_word(str = "polygons")
- algorithm <- "native:polygonstolines"
- # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
- result <- qgisprocess::qgis_run_algorithm(
- algorithm = algorithm,
- INPUT = sprintf("%s|layername=%s", dsn, "piir"),
- OUTPUT = sprintf('%s table=\"%s\" (geometry)', ogr, "piir_l")
- # .quiet = TRUE
- )
- ## ----------------- piiri sisse jäävad punktid -------------------
- ## --------------------------- algandmed --------------------------
- andmed.df <- data.frame("schema" = character(0), "table" = character(0))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_alusdokumendid_ja_lepingud"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "korvalmaantee"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "muutee"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_kergliiklustee"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_liiklussagedus"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_omand"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "pohimaantee"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "ramp"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "teeosa"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "tugimaantee"))
- andmed.df <- rbind(andmed.df, data.frame("schema" = "gtfs", "table" = "shapes"))
- j <- 1
- for (j in 1:nrow(andmed.df)) {
- output_layer_name <- as.character(andmed.df$table[j])
- # ruut::qgis_algorithm_search_by_word(str = "intersect")
- algorithm <- "native:intersection"
- # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
- result <- qgisprocess::qgis_run_algorithm(
- algorithm = algorithm,
- INPUT = sprintf('%s table="%s"."%s" (geometry)', postgres_line, andmed.df$schema[j], andmed.df$table[j]),
- INPUT_FIELDS = "",
- # OUTPUT = sprintf('%s table=\"%s\" (geometry)', ogr, andmed.df$table[j]),
- OUTPUT = tmp_gpkg_file,
- OVERLAY = sprintf("%s|layername=%s", dsn, "piir"),
- OVERLAY_FIELDS = "",
- OVERLAY_FIELDS_PREFIX = ""
- # # .quiet = TRUE
- )
- result
- # assign(as.character(andmed.df$table[j]), sf::read_sf(qgisprocess::qgis_output(result, "OUTPUT")))
- system(sprintf("ogr2ogr -f GPKG -overwrite %s %s -nln %s -t_srs \"EPSG:3301\"", dsn_l, tmp_gpkg_file, output_layer_name))
- ## AINULT ELAMUD aadressandmetest!!
- # if (output_layer_name == "aadressandmed") {
- # system(sprintf("ogr2ogr -f GPKG -overwrite %s %s -nln %s_ee -t_srs \"EPSG:3301\" -where \"adob_liik = 'EE'\" ", dsn_p, tmp_gpkg_file, output_layer_name))
- # }
- }
- ## ---------------------- vaata layer'id ----------------------
- # Vaata layer'eid
- sf::st_layers(dsn = dsn)
- sf::st_layers(dsn = dsn_p)
- sf::st_layers(dsn = dsn_l)
- }
- # piirkonnale_joonte_lisamine(obj = NULL, pk = NULL, gpkg_home = "/tmp")
|