Expand a table of location samples to location pairs.
gc_endpoints(data, lon, lat, distance = TRUE, keep = TRUE)
data | a data frame. |
---|---|
lon | character, the column in |
lat | character, the column in |
distance | logical, include a column of distances between locations along the shorter arc of the implied great circle. Defaults to |
keep | logical, retain copies of other columns in |
a data frame.
gc_endpoints
expands a data frame of with longitude and latitude coordinate columns into one with four columns of lon0
, lat0
, lon1
and lat1
representing pairs of locations.
This is done in preparation for generating great circle arcs between each pair of locations. gc_endpoints
provides the endpoints of these arcs.
See gc_lines
, which is used subsequently on output from gc_endpoints
, to generate an expanded data frame of the corresponding great circle ars.
gc_endpoints
merely splits a data frame into its first and second halves of rows and then expands a table that has rows for every combination of pairs between the first and second halves of the original table.
This is a handy utility function for preparing data for simulated examples of network maps in the current version of mapmate
.
In future versions a more robust gc_endpoints
may offer other more controllable options for assembling location pairs.
When keep=TRUE
columns in data
other than those of longitudes and latitudes are similarly appended with 0
and 1
in the output,
corresponding to the columns lon0/lat0
and to lon1/lat1
, respectively.
If data
contains n
rows, then the data frame returned by gc_endpoints
will contain \((n/2)^2\) rows.
# NOT RUN { library(dplyr) data(network) gc_endpoints(network, "lon", "lat") gc_endpoints(network, "lon", "lat", distance=FALSE) gc_endpoints(network, "lon", "lat", keep=FALSE) # }