getGeoDist | R Documentation |
Function to calculate geodesic distances
getGeoDist(xygrid, polys, datalocations = NULL, plot.transition = TRUE)
xygrid |
Regular grid of x and y coordinates, must have an extent greater than that of |
polys |
Either a single polygon (defined by a dataframe with x and y) or a list object containing multiple polygons that define exclusion zones. |
datalocations |
data frame of x and y coordinates of locations to calculate distances between. Default = NULL, in which case distances are returned between locations in |
plot.transition |
( |
Using the raster, spancs and gdistance packages to calculate the geodesic distance between pairs of points. The polygons define the areas that an animal/object cannot be. E.g. Land if the animal is a marine mammal.
The object returned is a matrix of distances between pairs of points and the x,y coordinates of each pair of points.
Nx=100
Ny=100
xygrid<-expand.grid(x=1:Nx, y=1:Ny)
# make exclusion polygon,
bnd<-data.frame(x=c(78 ,79, 52, 53 , 82 , 82, 100, 103 ,104 , 70),
y= c( 99 ,65 , 66 , 43 , 42 , 16, 19, 16 ,102 ,105))
bnd2<-data.frame(x= c(37 ,54 ,55, 37), y=c(35 ,35, 17, 18))
geodistsoutput<-getGeoDist(xygrid=xygrid, polys=list(bnd, bnd2))
# show on plot
i=2150
a.dist.mesh = data.frame(geodistsoutput$xydata, value=geodistsoutput$distance[i,])
iLCdsitance = rasterFromXYZ(a.dist.mesh)
plot(iLCdsitance, col=topo.colors(100))
points(geodistsoutput$xydata[i,1],geodistsoutput$xydata[i,2])
polymap(bnd, add=T)
polymap(bnd2, add=T)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.