prepCoord: Format Geographical Coordinates

View source: R/prepCoord.R

prepCoordR Documentation

Format Geographical Coordinates

Description

This function formats geographical coordinates to decimal degrees

Usage

prepCoord(x, lat = "decimalLatitude", lon = "decimalLongitude", flag = TRUE)

Arguments

x

a data.frame containing the geographical coordinates

lat

character. The name of the column containing the latitude. Default to "decimalLatitude".

lon

character. The name of the column containing the longitude. Default to "decimalLongitude".

flag

logical. Should the differences between the original and edited coordinates be flagged? Default to TRUE.

Details

This is a simple function that works for standardizing common issues in geographical coordinates, such as format and spacing. It was designed to process coordinates already in decimal degrees. So, it does not handle all formats and may return NA even if a coordinates are given and valid.

Currently, the function does not differentiate missing coordinates from those provided in a format that prepCoord does not handle (e.g. UTM). Function should work fine for coordinates in the degrees + decimal minutes format. See examples below.

Note that if one of the coordinates is valid and the other is not, the function returns NAs for both coordinates.

Value

The data frame x with the edited geographical coordinates, in decimal degrees. The new columns have the same name followed by the suffix '.new'.

Author(s)

Renato A. F. de Lima

Examples


## Creating some geographical coordinates in different formats
coords <- data.frame(
decimalLatitude = c(-23.475389, "-23,475389",
"23o 28' 31.40\"S", -93.475389, NA, 0, "missing", "blocked", NA,
"23° 28.5233'S","283088.52 E","-23,475,389"),
decimalLongitude = c(-47.123768, "-47,123768", "47o 07' 25.56\"W",
-47.123768, 185.578, 0, "missing","blocked", NA, "47° 07.4260'W",
"7402251.30 S","-47,123,768"),
stringsAsFactors = FALSE)
Encoding(coords[,1]) <- "latin1"
Encoding(coords[,2]) <- "latin1"
coords


## Formatting the geographical coordinates
prepCoord(coords)


LimaRAF/plantR documentation built on Jan. 1, 2023, 10:18 a.m.