|
@@ -6,7 +6,10 @@
|
|
|
#' @param pk Piirkonna geomeetriline joon.
|
|
#' @param pk Piirkonna geomeetriline joon.
|
|
|
#' @param gpkg_home path Salvestatavate GPKG faili asukoht.
|
|
#' @param gpkg_home path Salvestatavate GPKG faili asukoht.
|
|
|
#'
|
|
#'
|
|
|
|
|
+#' @examples
|
|
|
|
|
+#' \dontrun{
|
|
|
#'
|
|
#'
|
|
|
|
|
+#' }
|
|
|
piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tmp") {
|
|
piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tmp") {
|
|
|
if (is.null(pk) || !sf::st_is_valid(pk)) {
|
|
if (is.null(pk) || !sf::st_is_valid(pk)) {
|
|
|
cat("\nPalun kontrolli geomeetrilise kujundi õigsust.\n")
|
|
cat("\nPalun kontrolli geomeetrilise kujundi õigsust.\n")
|
|
@@ -22,20 +25,68 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
input_layer <- sprintf("%s|layername=%s", dsn, input_layer_name)
|
|
input_layer <- sprintf("%s|layername=%s", dsn, input_layer_name)
|
|
|
tmp_gpkg_file <- tempfile(fileext = ".gpkg")
|
|
tmp_gpkg_file <- tempfile(fileext = ".gpkg")
|
|
|
|
|
|
|
|
- ## -------------- andmed, mis jäävad piiri sisse -------------------
|
|
|
|
|
- ## ------------------------- algandmed -----------------------------
|
|
|
|
|
|
|
+ ## ----------------- piiri sisse jäävad polügoonid -------------------
|
|
|
|
|
+ ## --------------------------- algandmed -----------------------------
|
|
|
andmed.df <- data.frame("schema" = character(0), "table" = character(0))
|
|
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" = "buildings_a"))
|
|
|
|
|
+ # andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "aadressandmed")) # POINT
|
|
|
|
|
+ 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,
|
|
|
|
|
+ INTERSECT = input_layer,
|
|
|
|
|
+ OUTPUT = tmp_gpkg_file,
|
|
|
|
|
+ PREDICATE = c(0) # 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))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ## -------------- 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" = "landuse_a"))
|
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "osm_shp", "table" = "water_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" = "aadressandmed")) # POINT
|
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "asustusyksus"))
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "asustusyksus"))
|
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "shp_katastriyksus"))
|
|
andmed.df <- rbind(andmed.df, data.frame("schema" = "maaamet", "table" = "shp_katastriyksus"))
|
|
|
|
|
+ ## Esmalt leiame piirile uhverjoone.
|
|
|
|
|
+ # ruut::qgis_algorithm_search_by_word(str = "buffer")
|
|
|
|
|
+ algorithm <- "native:buffer"
|
|
|
|
|
+ # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
|
|
|
+ result <- qgisprocess::qgis_run_algorithm(
|
|
|
|
|
+ algorithm = algorithm,
|
|
|
|
|
+ DISSOLVE = 0,
|
|
|
|
|
+ DISTANCE = -30,
|
|
|
|
|
+ END_CAP_STYLE = 2,
|
|
|
|
|
+ INPUT = "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/valga.gpkg|layername=piir",
|
|
|
|
|
+ JOIN_STYLE = 2,
|
|
|
|
|
+ MITER_LIMIT = 2,
|
|
|
|
|
+ OUTPUT = tmp_gpkg_file,
|
|
|
|
|
+ SEGMENTS = 5
|
|
|
|
|
+ # .quiet = TRUE
|
|
|
|
|
+ )
|
|
|
|
|
+ result
|
|
|
|
|
+ piir_buffer <- sf::read_sf(qgisprocess::qgis_output(result, "OUTPUT"))
|
|
|
|
|
+ # st_geometry(pk) %>% plot()
|
|
|
|
|
+ # st_geometry(piir_buffer) %>% plot(add=T, col = 'red')
|
|
|
j <- 1
|
|
j <- 1
|
|
|
for (j in 1:nrow(andmed.df)) {
|
|
for (j in 1:nrow(andmed.df)) {
|
|
|
- output_layer_name <- andmed.df$table[j]
|
|
|
|
|
|
|
+ output_layer_name <- as.character(andmed.df$table[j])
|
|
|
input <- sprintf(
|
|
input <- sprintf(
|
|
|
- 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=3301 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
|
|
|
|
+ '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,
|
|
conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
andmed.df$schema[j], andmed.df$table[j]
|
|
andmed.df$schema[j], andmed.df$table[j]
|
|
|
)
|
|
)
|
|
@@ -45,16 +96,54 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
result <- qgisprocess::qgis_run_algorithm(
|
|
result <- qgisprocess::qgis_run_algorithm(
|
|
|
algorithm = algorithm,
|
|
algorithm = algorithm,
|
|
|
INPUT = input,
|
|
INPUT = input,
|
|
|
- INTERSECT = input_layer,
|
|
|
|
|
|
|
+ INTERSECT = piir_buffer,
|
|
|
OUTPUT = tmp_gpkg_file,
|
|
OUTPUT = tmp_gpkg_file,
|
|
|
- PREDICATE = c(0) # c(0, 1)
|
|
|
|
|
|
|
+ PREDICATE = c(0, 1)
|
|
|
# .quiet = TRUE
|
|
# .quiet = TRUE
|
|
|
)
|
|
)
|
|
|
result
|
|
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", dsn, tmp_gpkg_file, output_layer_name))
|
|
|
|
|
|
|
+ # 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))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ ## ----------------- piiriga lõigatud 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"))
|
|
|
|
|
+ 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 = "intersect")
|
|
|
|
|
+ algorithm <- "native:intersection"
|
|
|
|
|
+ # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
|
|
|
|
|
+ result <- qgisprocess::qgis_run_algorithm(
|
|
|
|
|
+ algorithm = algorithm,
|
|
|
|
|
+ INPUT = input,
|
|
|
|
|
+ INPUT_FIELDS = "",
|
|
|
|
|
+ OVERLAY = sprintf(
|
|
|
|
|
+ "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/%s.gpkg|layername=piir",
|
|
|
|
|
+ obj
|
|
|
|
|
+ ),
|
|
|
|
|
+ OVERLAY_FIELDS = "",
|
|
|
|
|
+ OVERLAY_FIELDS_PREFIX = "",
|
|
|
|
|
+ OUTPUT = tmp_gpkg_file
|
|
|
|
|
+ # .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))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# ## ------------ andmed, mis jäävad piirikasti sisse ----------------
|
|
# ## ------------ andmed, mis jäävad piirikasti sisse ----------------
|
|
|
# ## ------------------------- algandmed -----------------------------
|
|
# ## ------------------------- algandmed -----------------------------
|
|
|
# andmed.df <- data.frame("schema" = character(0), "table" = character(0))
|
|
# andmed.df <- data.frame("schema" = character(0), "table" = character(0))
|
|
@@ -68,7 +157,7 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
# for (j in 1:nrow(andmed.df)) {
|
|
# for (j in 1:nrow(andmed.df)) {
|
|
|
# output_layer_name <- andmed.df$table[j]
|
|
# output_layer_name <- andmed.df$table[j]
|
|
|
# input <- sprintf(
|
|
# input <- sprintf(
|
|
|
- # 'postgres://dbname=\'%s\' host=%s port=%s user=\'%s\' sslmode=%s password=\'%s\' key=\'fid\' srid=3301 type=Polygon checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geometry)',
|
|
|
|
|
|
|
+ # '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,
|
|
# conf$dbname, conf$host, conf$port, conf$user, conf$sslmode, conf$password,
|
|
|
# andmed.df$schema[j], andmed.df$table[j]
|
|
# andmed.df$schema[j], andmed.df$table[j]
|
|
|
# )
|
|
# )
|
|
@@ -85,7 +174,7 @@ piirkonnale_hoonete_lisamine <- function(obj = NULL, pk = NULL, gpkg_home = "/tm
|
|
|
# )
|
|
# )
|
|
|
# result
|
|
# result
|
|
|
# assign(as.character(andmed.df$table[j]), sf::read_sf(qgisprocess::qgis_output(result, "OUTPUT")))
|
|
# 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", dsn, tmp_gpkg_file, output_layer_name))
|
|
|
|
|
|
|
+ # 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'id ----------------------
|