# Load and plot bathymetry
data(hawaii)
pal <- colorRampPalette(c("black","darkblue","blue","lightblue"))
plot(hawaii,image=TRUE,bpal=pal(100),asp=1,col="grey40",lwd=.7,
main="Bathymetric map of Hawaii")
# Load and plot several locations
data(hawaii.sites)
sites <- hawaii.sites[-c(1,4),]
rownames(sites) <- 1:4
points(sites,pch=21,col="yellow",bg=col2alpha("yellow",.9),cex=1.2)
text(sites[,1],sites[,2],lab=rownames(sites),pos=c(3,4,1,2),col="yellow")
if (FALSE) {
# Compute transition object with no depth constraint
trans1 <- trans.mat(hawaii)
# Compute transition object with minimum depth constraint:
# path impossible in waters shallower than -200 meters depth
trans2 <- trans.mat(hawaii,min.depth=-200)
# 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 -200 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
# plots the depth profile between location 1 and 3 in the two situations
dev.new()
par(mfrow=c(2,1))
path.profile(out1[[2]],hawaii,pl=TRUE,
main="Path between locations 1 & 3\nProfile with no depth constraint")
path.profile(out2[[2]],hawaii,pl=TRUE,
main="Path between locations 1 & 3\nProfile with min depth set to -200m")
}
Run the code above in your browser using DataLab