Learn R Programming

rangeBuilder (version 1.6)

closestCountry: Return country from point

Description

Determines which country a given point falls in.

Usage

closestCountry(pt, proj = "+proj=longlat +datum=WGS84")

Value

If one point is provided, a character vector is returned. If multiple points are provided, a list of character vectors is returned.

Arguments

pt

longitude and latitude, as a numeric vector, 2-column table, or SpatialPoints object.

proj

the proj4string of the coordinate. If pt is a SpatialPoints object, proj is ignored.

Author

Pascal Title

Details

Based on a predetermined set of global points, this function finds the country of occurrence. This can be useful for checking the validity of a point by comparing the returned country to the country listed with the occurrence record. If a point falls close to the boundary between two countries, the names of the nearby countries are returned. This function will not be of much value if the point falls in the ocean, as it will return the country that is closest, regardless of how far away it is.

Examples

Run this code
#point near a country border
closestCountry(c(-115.436, 32.657))

Run the code above in your browser using DataLab