Randomly samples longitude and latitude on earth so that equal areas are (approximately) equally likely to be sampled. (Approximation assumes earth as a perfect sphere.)

rlatlon(...)

rlonlat(...)

rgeo(n = 1, latlim = c(-90, 90), lonlim = c(-180, 180), verbose = FALSE)

rgeo2(n = 1, latlim = c(-90, 90), lonlim = c(-180, 180), verbose = FALSE)

Arguments

...

arguments passed through to other functions

n

number of random locations

latlim, lonlim

range of latitudes and longitudes to sample within, only implemented for rgeo.

verbose

return verbose output that includes Euclidean coordinates on unit sphere as well as longitude and latitude.

Value

a data frame with variables long and lat. If verbose is TRUE, then x, y, and z coordinates are also included in the data frame.

Details

rgeo and rgeo2 differ in the algorithms used to generate random positions. Each assumes a spherical globe. rgeo uses that fact that each of the x, y and z coordinates is uniformly distributed (but not independent of each other). Furthermore, the angle about the z-axis is uniformly distributed and independent of z. This provides a straightforward way to generate Euclidean coordinates using runif. These are then translated into latitude and longitude.

rlatlon is an alias for rgeo and rlonlat is too, expect that it reverses the order in which the latitude and longitude values are returned.

rgeo2 samples points in a cube by independently sampling each coordinate. It then discards any point outside the sphere contained in the cube and projects the non-discarded points to the sphere. This method must oversample to allow for the discarded points.

Examples

rgeo(4)
#>         lat        lon
#> 1  19.05610  -19.50941
#> 2 -46.04375 -159.67086
#> 3  29.63209   15.40611
#> 4  72.95190  -82.24508
# sample from a region that contains the continental US
rgeo(4, latlim = c(25,50), lonlim = c(-65, -125))
#>        lat       lon
#> 1 36.36937 -66.79376
#> 2 49.46031 -96.11946
#> 3 34.01832 -78.01901
#> 4 48.02587 -93.43284
rgeo2(4)
#>         lat      lon
#> 1 -22.57304 -36.6247
#> 2 -54.70960 134.5217
#> 3  20.75593 -48.0073
#> 4 -77.45501 162.2262