Преглед изворни кода

TIF failide salvestamine andmebaasi.

Ardo Kubjas пре 5 година
родитељ
комит
cde8fde134

+ 2 - 0
R/construct_qgis_output_result_to_better_format.R

@@ -53,6 +53,8 @@ construct_qgis_output_result_to_better_format <- function(str = "", algorithm =
   # Nurksulgude asendamine
   str <- gsub("[[]", "", str)
   str <- gsub("[]]", "", str)
+  # EPSG: kandiliste sulgude lisamine tagasi
+  str <- gsub("(EPSG:[0-9]+\\.{0,1}[0-9]*)", "[\\1]", str)
   cat(str)
   str
 }

+ 25 - 1
R/gpkg_teisendame_punkte.R

@@ -44,7 +44,7 @@ gpkg_teisendame_punkte <- function(obj = NULL, gpkg_home = "/tmp") {
   layer_names <- layer_names[!layer_names %in% c("bb2", "bb2_epk10t_grid", "bb2_epk02t_grid", "bb2_epk2t_grid")] # c("bb", "bb2", "bb_epk10t_grid", "bb_epk02t_grid", "bb_epk2t_grid", "bb_epk10t", "bb_epk02t")]
   for (layer_name in layer_names) {
     ruumiline_obj <- sf::read_sf(dsn = dsn, layer = layer_name)
-    ## Punktide arv ruudus
+    ## ------------- Punktide arv ruudus ---------------
     ## Kontlrollime kas geomeetriline objekt on punkt.
     (is_point <- any(grepl("point", tolower(attributes(ruumiline_obj$geom)$class), fixed = TRUE)))
     if (is_point) {
@@ -59,6 +59,30 @@ gpkg_teisendame_punkte <- function(obj = NULL, gpkg_home = "/tmp") {
       str <- sprintf("{ 'CLASSFIELD' : '', 'FIELD' : 'numpoints', 'OUTPUT' : '%s', 'POINTS' : '%s', 'POLYGONS' : '%s', 'WEIGHT' : '' }", output, points, polygons)
       cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
       system(cmd)
+      ## ------------- TIFF ----------------
+      grid_layer <- sf::read_sf(dsn = dsn, layer = "bb2_epk02t_grid")
+      # sf::st_crs(grid_layer) <- 3301
+      pk_attributes <- attributes(grid_layer$geom)
+      extent <- sprintf("%s,%s,%s,%s [EPSG:3301]", round((pk_attributes$bbox["xmin"] / 100), digits = 0) * 100, ceiling((pk_attributes$bbox["xmax"] / 100)) * 100, round((pk_attributes$bbox["ymin"] / 100), digits = 0) * 100, ceiling((pk_attributes$bbox["ymax"] / 100)) * 100)
+      # ruut::qgis_algorithm_search_by_word("Rasterize")
+      algorithm <- "gdal:rasterize"
+      ruut::qgis_show_help(algorithm = algorithm)
+      conf$gpkg_table <- sprintf("%s_epk02t", layer_name)
+      input <- ruut::construct_to_gpkg_output_file_str(conf = conf, geometry_field = "geom", is_input_str = T)
+      output <- sprintf("%s/tif/%s.tif", conf$gpkg_home, layer_name)
+      str <- sprintf(
+        "{ 'BURN' : 0, 'DATA_TYPE' : 5, 'EXTENT' : '%s', 'EXTRA' : '-a_srs epsg:3301', 'FIELD' : 'numpoints', 'HEIGHT' : 100, 'INIT' : None, 'INPUT' : '%s', 'INVERT' : False, 'NODATA' : -1, 'OPTIONS' : '', 'OUTPUT' : '%s', 'UNITS' : 1, 'WIDTH' : 100 }",
+        extent, input, output
+      )
+      cmd <- ruut::construct_qgis_output_result_to_better_format(str = str, algorithm = algorithm)
+      system(cmd)
+
+      ## ----------- TIF TO POSTGIS -------------
+      conf$schema <- conf$gpkg_file
+      ruut::db_create_new_schema(conf = conf)
+      (cmd <- sprintf("export PGPASSWORD=%s && raster2pgsql -I %s %s.%s_tif | psql -U %s -d %s -h %s -p %s",
+                      conf$password, output, conf$schema, layer_name, conf$user, conf$dbname, conf$host, conf$port))
+      system(cmd)
     }
   }
   ## Layers list

+ 4 - 4
inst/extdata/config.json

@@ -6,14 +6,14 @@
   "user":"osm",
   "password":"osm",
   "schema":"date_YYMMDD",
-  "table":"",
+  "table":"test_table",
   "encoding":"UTF-8",
   "geometry_column":"geom",
   "primary_key":"fid",
   "gtype":0,
-  "a_srs":"EPSG:3301",
-  "t_srs":"EPSG:3301",
-  "s_srs":"EPSG:4326",
+  "a_srs":"epsg:3301",
+  "t_srs":"epsg:3301",
+  "s_srs":"epsg:4326",
   "gpkg_home":"/data/gpkg",
   "gpkg_file":"tmp_gpkg",
   "gpkg_table":"test_layer"