prepCoord | R Documentation |
This function formats geographical coordinates to decimal degrees
prepCoord(x, lat = "decimalLatitude", lon = "decimalLongitude", flag = TRUE)
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. |
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.
The data frame x
with the edited geographical coordinates, in
decimal degrees. The new columns have the same name followed by the suffix
'.new'.
Renato A. F. de Lima
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.