|
|
@@ -79,12 +79,10 @@ for (x in layer_names) {
|
|
|
|
|
|
## plot to file
|
|
|
png(filename = sprintf("tmp/img/matrix_true_false/%s.png", x))
|
|
|
-
|
|
|
sf::st_geometry(ruudustik) %>% plot(main = x, sub = "True/False")
|
|
|
sf::st_geometry(ruumiline_obj) %>% plot(add = T, border = "dark red", lwd = 1, col = "blue", pch = 16)
|
|
|
text(x = (ruudustik$left + ruudustik$right) / 2, y = (ruudustik$bottom + ruudustik$top) / 2, labels = as.character(ruudustik$value))
|
|
|
sf::st_geometry(ruudustik) %>% plot(add = T)
|
|
|
-
|
|
|
dev.off()
|
|
|
|
|
|
|
|
|
@@ -110,7 +108,73 @@ for (x in layer_names) {
|
|
|
## 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) {
|
|
|
+ is_line <- any(grepl("line", tolower(attributes(ruumiline_obj$geom)$class), fixed = TRUE))
|
|
|
+
|
|
|
+ if (is_polygon || is_line) {
|
|
|
+ ## 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", x)
|
|
|
+ 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)
|
|
|
+ # processing.runalg('qgis:addfieldtoattributestable', input_layer, field_name, field_type, field_length, field_precision, output_layer)
|
|
|
+ # processing.runalg('qgis:advancedpythonfieldcalculator', input_layer, field_name, field_type, field_length, field_precision, global, formula, output_layer)
|
|
|
+ if (is_polygon) {
|
|
|
+ ## 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_area", x)
|
|
|
+ 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()/10001,4)', 'INPUT' : '%s', 'OUTPUT' : '%s' }", input, output)
|
|
|
+ cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
|
|
|
+ system(cmd)
|
|
|
+ } else {
|
|
|
+ ## Lisame joonte pikkused
|
|
|
+ # 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_length", x)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|