library(GeoDist)
#> Loading required package: geoR
#> --------------------------------------------------------------
#> Analysis of Geostatistical Data
#> For an Introduction to geoR go to http://www.leg.ufpr.br/geoR
#> geoR version 1.9-6 (built on 2025-08-29) is now loaded
#> --------------------------------------------------------------
library(raster)
#> Loading required package: sp
library(sp)
crs_merc <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m"
# Create raster
r <- raster(ncol = 20, nrow = 20,
crs = crs_merc)
values(r) <- 1
values(r)[125:127] <- NA
values(r)[145:147] <- NA
values(r)[165:167] <- NA
plot(r)
# Create points
from_coords <- cbind(-150, 40)
from_sp <- SpatialPointsDataFrame(coords = from_coords,
data = data.frame(label = "start"),
proj4string = CRS(crs_merc))
to_coords <- matrix(c(50, 0, 100, -50), byrow = TRUE, ncol = 2)
to_sp <- SpatialPointsDataFrame(coords = to_coords,
data = data.frame(label = c("end1", "end2")),
proj4string = CRS(crs_merc))
plot(r)
points(from_sp, pch = 20, col = "blue")
points(to_sp, pch = 20, col = "red")
# For "from" and "to" being SpatialPoints
allpath <- dist.obstacle(from = from_sp, to = to_sp, r.ref = r, keep.path = TRUE)
#> step.ang was set to 5 degrees. This conducts to potential error of 0.095178 % of distances calculated.
#> r.ref has been stored in temporary directory: /tmp/RtmpDYH6wd/r.ref.grd
# All path from "from[1,]" to all "to"
lines(allpath$listLines)