Here's the original cost surface raster with NA regions the rectangular chunks at the borders of the image.
Here's what it looks like when grain() is run on it, and the various spatial outputs are plotted. Note the errant centroid in the top middle region. It appears to be associated with the centroid of the NA cells on the raster. Links are wacky as well, corresponding likely to this centroid throwing everything off. This is a hard to notice problem on simple rasters like this, but very obvious on large real-world rasters, which tend to have NAs around the edges as they are irregular regions of interest. The result is cases where links go every which way in a meaningless pattern when grain() is used to extract a GOC. Visualizations of MPG() outputs are perfect however!
Here is some reproducible code:
## Make a raster with NA values around edge
## as would typically occur in most GIS applications
tiny <- raster(system.file("extdata/tiny.asc", package = "grainscape"))
tinyCost <- reclassify(tiny, rcl = cbind(c(1, 2, 3, 4), c(1, 5, 10, 12)))
tinyCostNA <- tinyCost
tinyCostNA[0:40, 0:40] <- NA
tinyCostNA[0:20, 60:100] <- NA
tinyCostNA[50:80, 90:100] <- NA
tinyCostNA[90:100, 0:80] <- NA
## Extract MPG and GOC
tinyCostNAMPG <- MPG(tinyCostNA, tinyCostNA==1)
tinyCostNAGOC <- GOC(tinyCostNAMPG, 5, verbose=10)
## Use new export function to create simple to visualize things
spExport <- export(grain(tinyCostNAGOC,4), R=TRUE, vorBound=TRUE)
badCentroids <- spExport$nodes
badLinks <- spExport$linksCentroid
vorBound <- spExport$vorBound
## Plot
plot(vorBound, col=c("NA", "black"))
plot(badCentroids, add=TRUE, col="red", cex=2, pch=20)
plot(badLinks, add=TRUE, col="red")
Here's the original cost surface raster with NA regions the rectangular chunks at the borders of the image.
Here's what it looks like when
grain()
is run on it, and the various spatial outputs are plotted. Note the errant centroid in the top middle region. It appears to be associated with the centroid of the NA cells on the raster. Links are wacky as well, corresponding likely to this centroid throwing everything off. This is a hard to notice problem on simple rasters like this, but very obvious on large real-world rasters, which tend to have NAs around the edges as they are irregular regions of interest. The result is cases where links go every which way in a meaningless pattern whengrain()
is used to extract a GOC. Visualizations ofMPG()
outputs are perfect however!Here is some reproducible code: