Skip to content

Commit

Permalink
fixes #1604
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Sep 16, 2024
1 parent 7fac0dc commit e62c733
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/SpatRasterDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ setReplaceMethod("[", c("SpatRasterDataset", "numeric", "missing"),
if (j == (length(x)+1)) {
x@ptr$add(value@ptr, "", "", "", FALSE)
} else {
x@ptr$replace(j-1, value@ptr)
x@ptr$replace(j-1, value@ptr, FALSE)
}
}
messages(x, "`[`")
Expand Down
11 changes: 7 additions & 4 deletions src/spatRasterMultiple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ SpatRasterStack SpatRasterStack::crop(SpatExtent e, std::string snap, bool expan
return out;
}

void SpatRasterStack::replace(unsigned i, SpatRaster x) {
void SpatRasterStack::replace(unsigned i, SpatRaster x, bool setname) {
if (i > (ds.size()-1)) {
setError("invalid index");
return;
Expand All @@ -422,9 +422,12 @@ void SpatRasterStack::replace(unsigned i, SpatRaster x) {
}

ds[i] = x;
names[i] = x.getNames()[0];
long_names[i] = x.getLongSourceNames()[0];
units[i] = x.getUnit()[0];
// for clause for #1604
if (setname) {
names[i] = x.getNames()[0];
long_names[i] = x.getLongSourceNames()[0];
units[i] = x.getUnit()[0];
}
}

SpatRaster SpatRasterStack::collapse() {
Expand Down
2 changes: 1 addition & 1 deletion src/spatRasterMultiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SpatRasterStack {
SpatRasterStack subset(std::vector<unsigned> x);

SpatRasterStack crop(SpatExtent e, std::string snap, bool expand, SpatOptions &opt);
void replace(unsigned i, SpatRaster x);
void replace(unsigned i, SpatRaster x, bool setname);
SpatRaster collapse();
SpatRaster summary_numb(std::string fun, std::vector<double> add, bool narm, SpatOptions &opt);
SpatRaster summary(std::string fun, bool narm, SpatOptions &opt);
Expand Down

0 comments on commit e62c733

Please sign in to comment.