Learn R Programming

Waypoint (version 1.1.0)

validate: Validate Coords or Waypoints

Description

Validate objects of class "coords" or "waypoints" as geographic locations.

Usage

validate(x, ...)

# S3 method for coords validate(x, ...)

# S3 method for waypoints validate(x, ...)

Value

validate() returns its argument with logical vector attribute "valid", or attributes "validlat" and "validlon" updated as appropriate for "coords" and' "waypoints" objects respectively.

Arguments

x

object of class "coords" created by function as_coords(), or class "waypoints" created by function as_waypoints().

...

further arguments passed to or from other methods.

Details

Individual coordinate values within "coords" or "waypoints" objects are checked to ensure they represent valid geographic locations.

To be valid, the absolute values of coordinates in degrees must not exceed 180°, or 90° if degrees of latitude and, similarly, the absolute values of the minutes and seconds components, where given, must not exceed 60. Otherwise, a warning will be issued and the "valid" attribute in the case of a "coords" object, or "validlat" and "validlon" attributes in the case of a "waypoints" object will be set to FALSE for any non-compliant coordinate values.

See Also

"coords" and "waypoints".

Other validate: review()

Examples

Run this code
## Continuing example from `as_coords()`...
# \dontshow{
   dm <-
       c(5130.4659, 4932.7726, 4806.4339, 3853.3696, 0.0000, -3706.7044, -5306.2869, -2514.4093,
	   -007.6754, 1823.9137, -12246.7203, -7702.1145, 0.0000, -1217.3178, 7331.0370, -5731.1536)
   names(dm) <- 
       rep(c("Nelson's Column", "Ostravice", "Tally Ho", "Washington Monument", "Null Island",
             "Tristan da Cunha", "Mawson Peak", "Silvio Pettirossi International Airport"), 2)
   invisible(as_coords(dm, fmt = 2))
   latlon(dm) <- rep(c(TRUE, FALSE), each = 8)
# }

## Validate "coords" object in degrees and minutes
validate(dm)

## Deliberately change the first coordinate
## to a value greater than 60 minutes
dm[1] <- 5160.4659

validate(dm)

## Examine "valid" attribute of dm
attr(dm, "valid")

###
## Continuing second example from `as_waypoints()`...
# \dontshow{
   wp <- data.frame(
       lat = c(51.507765, 49.54621, 48.107232, 38.889494, 0, -37.11174, -53.104781, -25.240156),
       lon = c(-0.127924, 18.398562, -122.778671, -77.035242, 0, -12.28863, 73.517283, -57.519227)
   )
   row.names(wp) <-
       c("Nelson's Column", "Ostravice", "Tally Ho", "Washington Monument", "Null Island",
         "Tristan da Cunha", "Mawson Peak", "Silvio Pettirossi International Airport")
   invisible(as_waypoints(wp))
# }

## Validate "waypoints" object in decimal degrees

validate(wp)

## Deliberately change the penultimate latitude
## to an absolute value greater than 90 degrees
wp$lat[7] <- -93.104781

validate(wp)

## Examine "validlat" attribute of wp
attr(wp, "validlat")

rm(dm, wp)

Run the code above in your browser using DataLab