Skip to content

Commit

Permalink
write_RAST(): error in case SpatRaster already linked to GRASS db
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdh committed Jun 15, 2024
1 parent 4389249 commit a06e782
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions R/rast_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ write_RAST <- function(
} else {
tf <- ""
}
# exit when the source is a GRASS database layer already:
if (grepl("[/\\\\]cellhd[/\\\\][^/\\\\]+$", tf)) {
grass_layername <- regmatches(
tf,
regexpr("(?<=[/\\\\]cellhd[/\\\\])[^/\\\\]+$", tf, perl = TRUE)
)
stop(
"This SpatRaster already links to the following raster layer in the ",
"GRASS GIS database: ",
grass_layername
)
}
if (!file.exists(tf)) {
drv <- "RRASTER"
fxt <- ".grd"
Expand Down
8 changes: 5 additions & 3 deletions man/readRAST.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ if (run) {
inMemory(v1)
}
if (run) {
write_RAST(v1, "landuse1", flags=c("o", "overwrite"))
execGRASS("r.stats", flags="c", input="landuse1")
execGRASS("g.remove", flags="f", name="landuse1", type="raster")
try({
write_RAST(v1, "landuse1", flags=c("o", "overwrite"))
execGRASS("r.stats", flags="c", input="landuse1")
execGRASS("g.remove", flags="f", name="landuse1", type="raster")
})
}
Sys.setenv("_SP_EVOLUTION_STATUS_"="2")
run <- run && require("sp", quietly=TRUE)
Expand Down

0 comments on commit a06e782

Please sign in to comment.