#' Piirkonna punktide lisamine #' #' Etteantud piirkonna geomeetrilise piirjoone ('piir') järele leitakse selles piirkonnas ja piirkonna piiriga piirnevad punktobjektid (). #' #' @param obj str Objekti nimi. #' @param pk Piirkonna geomeetriline joon. #' @param gpkg_home path Salvestatavate GPKG faili asukoht. #' @param obj_only TRUE/FALSE Kas geomeetriad leitakse ainult objekti või kogu piirikastiga määratud ala jaoks. #' #' @examples #' \dontrun{ #' #' } piirkonnale_punktide_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tmp", obj_only = TRUE) { 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" ) dsn <- sprintf("%s/%s.gpkg", gpkg_home, obj) # Polygon ogr <- sprintf( "ogr:dbname='%s'", dsn ) tmp_gpkg_file <- tempfile(fileext = ".gpkg") ## ----------------- punktfaili loomine ------------------- ## -------------- epk2t_grids tsentroidid ----------------- # ruut::qgis_algorithm_search_by_word(str = "centroid") algorithm <- "native:centroids" # cat(qgisprocess::qgis_show_help(algorithm = algorithm)) result <- qgisprocess::qgis_run_algorithm( algorithm = algorithm, ALL_PARTS = 1, INPUT = sprintf("%s|layername=%s", dsn, "epk02t_grid"), OUTPUT = sprintf('%s table=\"%s\" (geometry)', ogr, "epk2t_centroid") # .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" = "maaamet", "table" = "aadressandmed")) # POINT andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "pofw")) andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "pois")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_bussipeatus")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "kilomeetripostid")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_jaotus")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_kandur")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_mahasoit")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_onnetus")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_rdtyl")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_ristmik")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_ristumispunkt")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_sild")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_teeosa_points")) andmed.df <- rbind(andmed.df, data.frame("schema" = "teeregister_wfs", "table" = "n_ylek")) 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_point, 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, 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, tmp_gpkg_file, output_layer_name)) } } ## ---------------------- vaata layer'id ---------------------- # Vaata layer'eid sf::st_layers(dsn = dsn) } # piirkonnale_punktide_lisamine(obj = NULL, pk = NULL, gpkg_home = "/tmp")