Learn R Programming

MazamaCoreUtils (version 0.6.2)

validateLonsLats: Validate longitude and latitude vectors

Description

Validate longitude and latitude vectors to ensure they are numeric, have matching lengths, and contain values within valid geographic bounds.

Usage

validateLonsLats(longitude = NULL, latitude = NULL, na.rm = FALSE)

Value

Invisibly returns TRUE if validation succeeds.

Arguments

longitude

Vector of longitudes in decimal degrees east.

latitude

Vector of latitudes in decimal degrees north.

na.rm

Logical specifying whether to remove NA values before validation.

Details

Longitudes must fall between -180 and 180 degrees and latitudes must fall between -90 and 90 degrees. If validation fails, an error is generated.

Examples

Run this code
longitude <- c(-122.5, -122.4)
latitude <- c(47.5, 47.6)

validateLonsLats(longitude, latitude)

# Remove missing values before validation
validateLonsLats(
  c(-122.5, NA),
  c(47.5, NA),
  na.rm = TRUE
)

if (FALSE) {
validateLonsLats(c(-200, 0), c(45, 46))
}

Run the code above in your browser using DataLab