I'm using R and the gdistance
package to generate the shortest routes in the ocean. In the open ocean with no obstacles, the least-cost path should equal the great-circle path. But I can't seem to get this result using gdistance
(presumably because it uses a grid-based system).
Here's my approach so far (mimicking many resources on gdistance
):
library(marmap) # for bathymetry data
library(gdistance)
library(raster)
library(sf)
library(leaflet)
bathy <- getNOAA.bathy(lon1 = -180, lon2 = 180, lat1 = -90, lat2 = 90, resolution = 10)
bathy_rast <- as.raster(bathy)
# Treat land as NA (non-traversable)
bathy_rast@data@values <- ifelse(bathy_rast@data@values >= 0, NA, 1)
rast <- bathy_rast
tr_layer <- transition(rast, transitionFunction = mean, directions = 8)
tr_layer <- geoCorrection(tr_layer)
orig <- SpatialPoints(cbind(-70, 27))
dest <- SpatialPoints(cbind(-26, 33))
lc_route <- shortestPath(tr_layer, orig, dest, output = "SpatialLines")
# Inspect result
leaflet() %>%
addTiles() %>%
addPolylines(data = lc_route, color = "red") %>%
addCircles(data = rbind(orig, dest))
Ideally, the line would be curved to match the great-circle path (shown above in green). Instead, it gives a somewhat unrealistic path for a ship where it goes straight, takes a turn, and then heads straight again (red).
I'm wondering if there's a way to get true shortest-distance paths in an open environment using a grid/network-based system? I still want to use a grid-based approach because I will later have routes navigate around landmasses and around obstacles (e.g., weather systems).