|
|
@@ -1,6 +1,6 @@
|
|
|
-#' Piirkonna hoonete lisamine
|
|
|
+#' Piirkonna polügoonide lisamine
|
|
|
#'
|
|
|
-#' Etteantud piirkonna geomeetrilise piirjoone ('piir') järele leitakse selles piirkonnas ja piirkonna piiriga piirnevad hooned ().
|
|
|
+#' Etteantud piirkonna geomeetrilise piirjoone ('piir') järele leitakse selles piirkonnas ja piirkonna piiriga piirnevad polügoonid (). Osasid polügoone on lõigatud piiriga.
|
|
|
#'
|
|
|
#' @param obj str Objekti nimi.
|
|
|
#' @param pk Piirkonna geomeetriline joon.
|
|
|
@@ -10,7 +10,7 @@
|
|
|
#' \dontrun{
|
|
|
#'
|
|
|
#' }
|
|
|
-piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tmp") {
|
|
|
+piirkonnale_polygoonide_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()
|
|
|
@@ -20,6 +20,10 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
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=Polygon checkPrimaryKeyUnicity=\'1\'",
|
|
|
+ conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password
|
|
|
+ )
|
|
|
dsn <- sprintf("%s/%s.gpkg", gpkg_home, obj)
|
|
|
input_layer_name <- "piir"
|
|
|
input_layer <- sprintf("%s|layername=%s", dsn, input_layer_name)
|
|
|
@@ -33,17 +37,15 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
j <- 1
|
|
|
for (j in 1:nrow(andmed.df)) {
|
|
|
output_layer_name <- as.character(andmed.df$table[j])
|
|
|
- input <- sprintf(
|
|
|
- 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
- andmed.df$schema[j], andmed.df$table[j]
|
|
|
- )
|
|
|
# ruut::qgis_algorithm_search_by_word(str = "extract")
|
|
|
algorithm <- "native:extractbylocation"
|
|
|
# cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
|
result <- qgisprocess::qgis_run_algorithm(
|
|
|
algorithm = algorithm,
|
|
|
- INPUT = input,
|
|
|
+ INPUT = sprintf(
|
|
|
+ '%s table=\"%s\".\"%s\" (geometry)',
|
|
|
+ postgres, andmed.df$schema[j], andmed.df$table[j]
|
|
|
+ ),
|
|
|
INTERSECT = input_layer,
|
|
|
OUTPUT = tmp_gpkg_file,
|
|
|
PREDICATE = c(0) # c(0, 1)
|
|
|
@@ -57,8 +59,6 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
## -------------- piiri -30 meetrise puhvri sisse jäävad polügoonid -------------
|
|
|
## --------------------------------- algandmed ---------------------------------
|
|
|
andmed.df <- data.frame("schema" = character(0), "table" = character(0))
|
|
|
- andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "landuse_a"))
|
|
|
- andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "water_a"))
|
|
|
# andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "aadressandmed")) # POINT
|
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "asustusyksus"))
|
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "shp_katastriyksus"))
|
|
|
@@ -71,7 +71,10 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
DISSOLVE = 0,
|
|
|
DISTANCE = -30,
|
|
|
END_CAP_STYLE = 2,
|
|
|
- INPUT = "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/valga.gpkg|layername=piir",
|
|
|
+ INPUT = sprintf(
|
|
|
+ "%s|layername=piir",
|
|
|
+ dsn
|
|
|
+ ),
|
|
|
JOIN_STYLE = 2,
|
|
|
MITER_LIMIT = 2,
|
|
|
OUTPUT = tmp_gpkg_file,
|
|
|
@@ -86,9 +89,8 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
for (j in 1:nrow(andmed.df)) {
|
|
|
output_layer_name <- as.character(andmed.df$table[j])
|
|
|
input <- sprintf(
|
|
|
- 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
- andmed.df$schema[j], andmed.df$table[j]
|
|
|
+ '%s table=\"%s\".\"%s\" (geometry)',
|
|
|
+ postgres, andmed.df$schema[j], andmed.df$table[j]
|
|
|
)
|
|
|
# ruut::qgis_algorithm_search_by_word(str = "extract")
|
|
|
algorithm <- "native:extractbylocation"
|
|
|
@@ -115,9 +117,8 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
for (j in 1:nrow(andmed.df)) {
|
|
|
output_layer_name <- as.character(andmed.df$table[j])
|
|
|
input <- sprintf(
|
|
|
- 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
- conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
- andmed.df$schema[j], andmed.df$table[j]
|
|
|
+ '%s table=\"%s\".\"%s\" (geometry)',
|
|
|
+ postgres, andmed.df$schema[j], andmed.df$table[j]
|
|
|
)
|
|
|
# ruut::qgis_algorithm_search_by_word(str = "intersect")
|
|
|
algorithm <- "native:intersection"
|
|
|
@@ -127,8 +128,8 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
INPUT = input,
|
|
|
INPUT_FIELDS = "",
|
|
|
OVERLAY = sprintf(
|
|
|
- "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/%s.gpkg|layername=piir",
|
|
|
- obj
|
|
|
+ "%s|layername=piir",
|
|
|
+ dsn
|
|
|
),
|
|
|
OVERLAY_FIELDS = "",
|
|
|
OVERLAY_FIELDS_PREFIX = "",
|
|
|
@@ -141,44 +142,8 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # ## ------------ andmed, mis jäävad piirikasti sisse ----------------
|
|
|
- # ## ------------------------- algandmed -----------------------------
|
|
|
- # andmed.df <- data.frame("schema" = character(0), "table" = character(0))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "buildings_a"))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "landuse_a"))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "water_a"))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "aadressandmed"))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "asustusyksus"))
|
|
|
- # # andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "shp_katastriyksus"))
|
|
|
- # j <- 1
|
|
|
- # for (j in 1:nrow(andmed.df)) {
|
|
|
- # output_layer_name <- andmed.df$table[j]
|
|
|
- # input <- sprintf(
|
|
|
- # 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=4326 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
- # conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
- # andmed.df$schema[j], andmed.df$table[j]
|
|
|
- # )
|
|
|
- # # ruut::qgis_algorithm_search_by_word(str = "extract")
|
|
|
- # algorithm <- "native:extractbylocation"
|
|
|
- # # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
|
- # result <- qgisprocess::qgis_run_algorithm(
|
|
|
- # algorithm = algorithm,
|
|
|
- # INPUT = input,
|
|
|
- # INTERSECT = sprintf("%s|layername=%s", dsn, "boundarybox_3301"),
|
|
|
- # OUTPUT = tmp_gpkg_file,
|
|
|
- # PREDICATE = c(0, 1)
|
|
|
- # # .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))
|
|
|
- # }
|
|
|
-
|
|
|
## ---------------------- vaata layer'id ----------------------
|
|
|
# Vaata layer'eid
|
|
|
sf::st_layers(dsn = dsn)
|
|
|
}
|
|
|
-# piirkonnale_hoonete_lisamine(obj = NULL, pk = NULL, gpkg_home = "/tmp")
|
|
|
+# piirkonnale_polygoonide_lisamine(obj = NULL, pk = NULL, gpkg_home = "/tmp")
|