|
|
@@ -135,6 +135,63 @@ gpkg_piirkonnale_polygoonide_lisamine <- function(obj = NULL, gpkg_home = "/tmp"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ ## ====================== teisendused =====================
|
|
|
+ # Layers list
|
|
|
+ gpkg_info <- sf::st_layers(dsn = dsn)
|
|
|
+ layer_names <- gpkg_info$name
|
|
|
+ layer_names[!layer_names %in% c("bb", "bb_epk10t_grid", "bb_epk02t_grid", "bb_epk2t_grid", "bb_epk10t", "bb_epk02t")]
|
|
|
+ for (layer_name in layer_names[1]) {
|
|
|
+ ruumiline_obj <- sf::read_sf(dsn = dsn, layer = layer_name)
|
|
|
+ ## Kontlrollime kas geomeetriline objekt on polügoon.
|
|
|
+ ## Arvutame sel juhul pindala.
|
|
|
+ is_polygon <- any(grepl("polygon", tolower(attributes(ruumiline_obj$geom)$class), fixed = TRUE))
|
|
|
+ if (is_polygon) {
|
|
|
+ ## Lõikame objekti ruudistikga tükkideks. Ühte ruutu võib jääda mitu tükki.
|
|
|
+ ## Peame need pärast ühendama
|
|
|
+ # ruut::qgis_algorithm_search_by_word("Intersection")
|
|
|
+ algorithm <- "native:intersection"
|
|
|
+ conf$gpkg_table <- sprintf("%s", layer_name)
|
|
|
+ input <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer")
|
|
|
+ output <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = F)
|
|
|
+ conf$gpkg_table <- sprintf("%s", "bb_epk02t_grid")
|
|
|
+ overlay <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
|
|
|
+ str <- sprintf("{ 'INPUT' : '%s', 'INPUT_FIELDS' : ['fid'], 'OUTPUT' : '%s', 'OVERLAY' : '%s', 'OVERLAY_FIELDS' : [], 'OVERLAY_FIELDS_PREFIX' : '' }", input, output, overlay)
|
|
|
+ cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ system(cmd)
|
|
|
+ ## Ühendame ruudus olevad pinnad
|
|
|
+ # ruut::qgis_algorithm_search_by_word("Dissolve")
|
|
|
+ algorithm <- "native:dissolve"
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer")
|
|
|
+ input <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer_2")
|
|
|
+ output <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = F)
|
|
|
+ str <- sprintf("{ 'FIELD' : ['%s'], 'INPUT' : '%s', 'OUTPUT' : '%s' }", "id", input, output)
|
|
|
+ cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ system(cmd)
|
|
|
+ ## Lisame pindade pindalad ja perimeetri
|
|
|
+ # ruut::qgis_algorithm_search_by_word("attributes")
|
|
|
+ algorithm <- "qgis:exportaddgeometrycolumns"
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer_2")
|
|
|
+ input <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer")
|
|
|
+ output <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = F)
|
|
|
+ str <- sprintf("{ 'CALC_METHOD' : 0, 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
|
|
|
+ cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ system(cmd)
|
|
|
+ ## Add field
|
|
|
+ ## Arvutame pindala protsendi ruudust
|
|
|
+ # ruut::qgis_algorithm_search_by_word("pythonfield")
|
|
|
+ algorithm <- "qgis:advancedpythonfieldcalculator"
|
|
|
+ conf$gpkg_table <- sprintf("%s", "test_layer")
|
|
|
+ input <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
|
|
|
+ conf$gpkg_table <- sprintf("%s_epk02t", layer_name)
|
|
|
+ output <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = F)
|
|
|
+ str <- sprintf("{ 'FIELD_NAME' : 'area_pc', 'FIELD_TYPE' : 1, 'FIELD_LENGTH' : 4, 'FIELD_PRECISION' : 2, 'GLOBAL' : '', 'FORMULA' : 'value = round($geom.area()/10000,4)', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
|
|
|
+ cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ system(cmd)
|
|
|
+ }
|
|
|
+ }
|
|
|
## Layers list
|
|
|
sf::st_layers(dsn = dsn)
|
|
|
}
|