-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I am just leaving this comment here for others that are interested in taking advantage of this package - I appreciate it is not necessarily designed for wider use though. I noticed that seegSDM::nearestLand()
assumes planar coordinates. It would be very helpful to add this to the documentation. Alternatively, you could consider tweaking the function to enable correct geodesic distance calculations, e.g.,:
nearestLand2 <-
function(points, raster, max_distance, lonlat) {
nearest <- function(lis, raster) {
neighbours <- matrix(lis[[1]], ncol = 2)
point <- lis[[2]]
land <- !is.na(neighbours[, 2])
if (!any(land)) {
return(c(NA, NA))
}
else {
coords <- raster::xyFromCell(raster, neighbours[land, 1])
if (nrow(coords) == 1) {
return(coords[1, ])
}
# Use raster::pointDistance() or a related function to permit lon/lat distance calculations
dists <- raster::pointDistance(coords, cbind(point[1], point[2]), lonlat = lonlat)
return(coords[which.min(dists), ])
}
}
neighbour_list <- raster::extract(raster, points, buffer = max_distance,
cellnumbers = TRUE)
neighbour_list <- lapply(1:nrow(points), function(i) {
list(neighbours = neighbour_list[[i]], point = as.numeric(points[i,
]))
})
return(t(sapply(neighbour_list, nearest, raster)))
}
Metadata
Metadata
Assignees
Labels
No labels