View source: R/minDistanceToCoast.R
minDistanceToCoast | R Documentation |
Get the minumim distance to coast
minDistanceToCoast(
data,
colLon = "lon",
colLat = "lat",
countryFilter = "peru",
unit = "nm",
multicore = FALSE,
ncores = 1,
out = c("value", "position")
)
data |
|
colLon |
Name or position of column for longitude. As default, it will
be |
colLat |
Name or position of column for latitude. As default, it will be
|
unit |
Define the unit for outputs: |
multicore |
|
ncores |
If |
out |
|
country |
|
This function uses internaly distance[terra] function, with argument
longlat = TRUE
.
If country
is not defined (NULL
), the internal algorithm will
perform a search along the ENTIRE west coast of America: from Alaska to Chile.
This might be (very) inefficient especially if the calculation is performed
over many (thousands of) points, so it is suggested to define the country or
countries with which you want to make the comparison.
If data
is a matrix, colLon
and colLat
must be ONLY
numeric values.
It is recommended to use multicore mode only when the database exceeds 2000 rows, less than this, single core mode have proved to be faster.
out
argument allows to users to decide having between: the values (the
values of minimum distance to coast), the positions (where this minimum
distance where achieved in coast) or both.
It returns a list with 2 levels: value
, The minimum distance
to coast line and position
, the point where this minimum distance is
reached.
n <- 100
allData <- data.frame(lon = runif(n, -80, -70), lat = runif(n, -18, -2),
stringsAsFactors = FALSE)
allData <- allData[!is.na(isopArea.assigner(allData)),]
minValues <- minDistanceToCoast(allData)
xlim <- c(-85, -70)
ylim <- c(-20, -2)
dev.new()
par(mar = c(2, 3, 1, 1), xaxs = "i", yaxs = "i")
plot(1, 1, pch = NA, axes = FALSE, xlab = NA, ylab = NA, xlim = xlim, ylim = ylim)
points(allData$lon, allData$lat, pch = 16, cex = 0.5, xlim = c(-85, -70), ylim = c(-20, -2))
lines(coastline$lon, coastline$lat)
for(i in 1:nrow(minValues$position)){
lines(c(allData$lon[i], minValues$position$lon[i]), c(allData$lat[i], minValues$position$lat[i]),
lty = "dotted", col = "red")
}
axis(side = 1, at = seq(xlim[1], xlim[2], length.out = 4),
labels = getCoordsAxes(seq(xlim[1], xlim[2], length.out = 4), "lon"))
axis(side = 2, at = seq(ylim[1], ylim[2], length.out = 10),
labels = getCoordsAxes(seq(ylim[1], ylim[2], length.out = 10), "lat"), las = 2)
box()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.