###Using Hist2GE: the easy way
#Produce fake species occurrences
coords = cbind(rnorm(210, 6.32, 5), rnorm(210, 46.75, 5))
coords = coords[order(coords[,1]), ]
species = rep(c("sp1", "sp2", "sp3"), each = 70)
#Choose grid
data(grid10000) # choose among grid50, grid500, grid5000, grid1000, grid20000
grid = grid10000
Hist2GE(coords = coords,
species = species,
grid = grid,
goo = "Jura",
nedges = 6,
orient = 45,
maxAlt = 1e5)
###Using Hist2GE: using custom grids, when working at local scale (not accounting for earth curvature)
#Produce fake species occurrences
coords = cbind(rnorm(210, -110.954795, 0.1), rnorm(210, 32.228724, 0.1))
coords = coords[order(coords[,1]), ]
species = rep(c("sp1", "sp2", "sp3"), 70)
#Define the resolution (cell width, decimal degrees)
cellwdth = 0.02
#And produce the desired grid automatically
lonrange = range(coords[, 1])
if(sum(sign(lonrange)) == -2){
lonwdth = -cellwdth
}else{
lonwdth = cellwdth
}
latrange = range(coords[, 2])
if(sum(sign(latrange)) == -2){
latwdth = -cellwdth
}else{
latwdth = cellwdth
}
lonLeft = lonrange[1] - 0.01 * lonrange[1]
lonRight = lonrange[2] + 0.01 * lonrange[2]
latBottom = latrange[1] - 0.01 * latrange[1]
latTop = latrange[2] + 0.01 * latrange[2]
#Produce cell coordinates along lon and lat axes
lonmarks = seq(lonLeft, lonRight, by = lonwdth)
latmarks = seq(latBottom, latTop, by = latwdth)
#Produce complete grid
lonDD = rep(lonmarks, length(latmarks))
latDD = rep(latmarks, each = length(lonmarks))
gridDD = cbind(lonDD, latDD)
#Convert it to radians centered and formated as in a "grid50" array
DD2Rad = function(lon, lat){
lonrad = (lon + 180) * pi/180
latrad = (lat + 90) * pi/180
cbind(lonrad, latrad)
}
MyGridDD = cbind(lonDD, latDD)
MyGridRad = DD2Rad(MyGridDD[, 1], MyGridDD[, 2])
MyGridRad = data.frame("Num" = 1:nrow(MyGridRad),
"lon" = MyGridRad[, 1],
"lat" = MyGridRad[, 2]) #this step is only cosmetic and necessary for compatibily issues.
#Run Hist2GE
Hist2GE(coords = coords,
species = species,
grid = MyGridRad,
goo = "Tucson",
nedges = 4,
orient = 45,
maxAlt = 5e3)
Run the code above in your browser using DataLab