Create a logical mask identifying valid longitude/latitude pairs.
Logical vector identifying valid locations.
The returned logical vector contains TRUE for valid locations and FALSE
for invalid locations. This is useful for filtering data frames to retain
only records with valid geographic coordinates.
Longitude and latitude values are considered valid when they:
fall within lonRange and latRange
are not missing
are not located at (0, 0) when removeZeroZero = TRUE
The lonRange and latRange arguments can be used to restrict valid
locations to a rectangular geographic region.
createLocationMask(
longitude = c(-120, NA, -120, -220, -120, 0),
latitude = c(45, 45, NA, 45, 100, 0)
)
#> [1] TRUE FALSE FALSE FALSE FALSE FALSE
createLocationMask(
longitude = -120:-90,
latitude = 20:50,
lonRange = c(-110, -100),
latRange = c(30, 40)
)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
#> [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE