Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 13, 2024
1 parent 12b2962 commit 0cf8f8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## new


- `$<SpatRaster>` can now be used to set the active category for categorical rasters


# version 1.8-5
Expand Down
9 changes: 8 additions & 1 deletion R/subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ setMethod("subset", signature(x="SpatRaster"),
)



## exact matching
setMethod("$", "SpatRaster",
function(x, name) {
if ((nlyr(x) == 1) && is.factor(x)) {
factnms <- names(cats(x)[[1]])
i <- match(name, factnms[-1])
if (!is.na(i)) {
activeCat(x) <- i
return(x)
}
}
subset(x, name, NSE=FALSE)
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/RcppModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ RCPP_MODULE(spat){
.method("related_within", ( std::vector<std::vector<double>> (SpatVector::*)(std::string, bool))( &SpatVector::which_relate))

// .method("relate_first", &SpatVector::relateFirst)
.method("relate_between", ( std::vector<int> (SpatVector::*)(SpatVector, std::string, bool, bool))( &SpatVector::relate ))
// .method("relate_between", ( std::vector<int> (SpatVector::*)(SpatVector, std::string, bool, bool))( &SpatVector::relate ))
.method("relate_within", ( std::vector<int> (SpatVector::*)(std::string, bool))( &SpatVector::relate ))
.method("equals_between", ( std::vector<unsigned> (SpatVector::*)(SpatVector, double))( &SpatVector::equals_exact ))
.method("equals_within", ( std::vector<unsigned> (SpatVector::*)(bool, double))( &SpatVector::equals_exact ))
Expand Down

0 comments on commit 0cf8f8d

Please sign in to comment.