Learn R Programming

MazamaCoreUtils (version 0.6.2)

createLocationMask: Create a mask of valid locations

Description

Create a logical mask identifying valid longitude/latitude pairs.

Usage

createLocationMask(
  longitude = NULL,
  latitude = NULL,
  lonRange = c(-180, 180),
  latRange = c(-90, 90),
  removeZeroZero = TRUE
)

Value

Logical vector identifying valid locations.

Arguments

longitude

Vector of longitudes in decimal degrees east.

latitude

Vector of latitudes in decimal degrees north.

lonRange

Range of valid longitudes.

latRange

Range of valid latitudes.

removeZeroZero

Logical specifying whether the coordinate pair (0, 0) should be treated as invalid.

Details

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.

Examples

Run this code
createLocationMask(
  longitude = c(-120, NA, -120, -220, -120, 0),
  latitude = c(45, 45, NA, 45, 100, 0)
)

createLocationMask(
  longitude = -120:-90,
  latitude = 20:50,
  lonRange = c(-110, -100),
  latRange = c(30, 40)
)

Run the code above in your browser using DataLab