I am trying to calculate over-water distance between all study subtidal locations in lat/long. The getNOAA.bathy function from marmap appears to be the best and most efficient way to do this. However, I am finding that some of the locations show up on land which is obviously impossible. Thus, I am unable to calculate overwater distance. Code here:
library(rgdal)
library(marmap)
library(RColorBrewer)
california <-getNOAA.bathy(lon1 = -120.5,lon2 = -119.1,lat1 = 34.2, lat2 =33.8, resolution = 1, keep = T)
summary(california)
pal <- colorRampPalette(c("black","darkblue","blue","lightblue"))
plot(california,image=TRUE,bpal=pal(100),asp=1,col="grey40",lwd=.7,
main="Bathymetric map of Channel Islands")
plot(california, n = 1, lwd = 0.4, add = TRUE)
sites<-data.frame()
sites$latitude<-c(34.01767 ,34.01703,34.01587 ,34.01278,34.01390,34.01078,34.00988,34.00850,34.00783,34.01698,34.01608, 34.01742, 34.0542, 34.05275, 34.0449, 34.0426, 34.0514, 34.0538, 33.9464, 33.9481, 34.0565, 34.05438, 34.05810, 34.0728, 34.07190, 34.0744, 34.0306, 34.0280, 34.0358, 34.0484, 34.0525, 33.9836, 33.98355, 33.98170, 33.9885, 33.98930, 34.0158, 34.0138, 34.0517, 34.0570, 34.0527, 34.0636, 34.0254, 34.02729, 33.93167, 33.9238, 33.89743, 33.8951, 33.8915, 33.8941)
sites$longitude<-c(-119.3637,-119.3611,-119.3717,-119.3631,-119.3600 ,-119.3725,-119.3883,-119.3882,-119.3945 -119.4329, -119.421, -119.438, -119.566, -119.571, -119.6014, -119.604, -119.909, -119.918, -119.8232 -119.828, -119.821, -119.819, -119.824, -119.871, -119.8576, -119.882, -119.696, -119.690, -119.7023 -119.546,-119.555, -119.638, -119.620, -119.663, -119.5470, -119.564, -120.330, -120.337, -120.3462 -120.352, -120.337, -120.356, -120.406, -120.411, -120.1974, -120.192, -120.100, -120.104, -120.1192 -120.124)
points(sites$longitude, sites$latitude, pch = 21, col = "black",
bg = "yellow", cex = 1.3)
# Compute transition object with no depth constraint
trans1 <- trans.mat(california)
# Compute transition object with minimum depth constraint:
# path impossible in waters shallower than -5 meters depth
trans2 <- trans.mat(california,min.depth=-5)
# Computes least cost distances for both transition matrix and plots the results on the map
out1 <- lc.dist(trans1,sites,res="path")
out2 <- lc.dist(trans2,sites,res="path")
lapply(out1,lines,col="yellow",lwd=4,lty=1) # No depth constraint (yellow paths)
lapply(out2,lines,col="red",lwd=1,lty=1) # Min depth set to -5 meters (red paths)
# Computes and display distance matrices for both situations
dist1 <- lc.dist(trans1,sites,res="dist")
dist2 <- lc.dist(trans2,sites,res="dist")
dist1
dist2
I also received a warning telling me that because some of my sites are at a greater altitude than "-5" m distance cannot be calculated.
Warning message:
In lc.dist(trans1, sites, res = "dist") :
One or more points are located outside of the [0;-1853] depth range. You will get unrealistically huge distances unless you either increase the range of possible depths in trans.mat() or you move the problematic points in a spot where their depths fall within the [0;-1853] depth range.
You can use get.depth() to determine the depth of any point on a bathymetric map
I have checked my site locations in Google Earth and with shapefile projections and they appear to be correct. Am I doing something terribly wrong or is the resolution from getNOAA.bathy not fine enough to get this level of detail?
Thanks!