Skip to content

Commit

Permalink
Workaround (fix?) broken pathInc() call in Overview vignette
Browse files Browse the repository at this point in the history
Addresses #19

Remove disconnected patches in the raster. The clump number is specific
to this raster and may not be the same for other rasters.

I'm not clear yet if this is actually necessary or is just a workaround
for a different issue. It's possible that disconnected (unreachable)
patches in the transition matrix is not possible with the matrix
decomposition, but I haven't determined yet why it used to work. It's
possible a bug was fixed in the Matrix package that was allowing the
matrix to be incorrectly decomposed, or it's possible a new bug was
introduced to the Matrix package that breaks the decomposition in
certain circumstances.
  • Loading branch information
andrewmarx committed Jun 4, 2023
1 parent d295b90 commit 305f1b9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vignettes/Overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ First, we read in the data: a map of Europe, the coordinates of the populations

```{r gdistance-24}
Europe <- raster(system.file("external/Europe.grd", package = "gdistance"))
Europe[is.na(Europe)] <- 0
data(genDist)
data(popCoord)
pC <- as.matrix(popCoord[c("x", "y")])
```

Expand All @@ -454,6 +455,15 @@ geoDist <- pointDistance(pC, longlat = TRUE)
geoDist <- as.dist(geoDist)
Europe <- aggregate(Europe, 3)
# Keep only the largest "clump" and remove patches that cannot be reached.
# Having disconnected patches might sometimes cause issues with some of the
# linear algebra calculations.
# Note that this clump code is not robust to other rasters that will need to identify
# the correct clump number
clumps = raster::clump(Europe, directions = 8)
clumps[clumps[] != 1] <- NA
Europe = Europe * clumps
tr <- transition(Europe, mean, directions = 8)
trC <- geoCorrection(tr, "c", scl = TRUE)
trR <- geoCorrection(tr, "r", scl = TRUE)
Expand Down

0 comments on commit 305f1b9

Please sign in to comment.