Learn R Programming

prabclus (version 2.3-4)

coord2dist: Geographical coordinates to distances

Description

Computes geographical distances from geographical coordinates

Usage

coord2dist(file=NULL, coordmatrix=NULL, cut=NULL,
                       file.format="degminsec",
                       output.dist=FALSE, radius=6378.137,
              fp=1/298.257223563, neighbors=FALSE)

Value

If neighbors==TRUE, a list with components

distmatrix

distance matrix between locations. See output.dist above. This is in km by default; the measurement unit is determined by the value used for radius.

nblist

list with a vector for every location containing the numbers of its neighbors, see neighbors.

If neighbors==FALSE, only the distance matrix.

Arguments

file

string. A filename for the coordinate file. The file should have 2, 4 or 6 numeric columns and one row for each location. See file.format. One of file and coordmatrix needs to be specified (if coordmatrix is not specified, coordinates are read from file).

coordmatrix

something that can be coerced into a matrix with 2, 4 or 6 columns. Matrix of coordinates, one row for each location. See file.format. One of file and coordmatrix needs to be specified.

cut

numeric. Only active if neighbors==TRUE; see neighbors.

file.format

one of "degminsec", "decimal2" or "decimal4". The format of the required file or coordmatrix consists of the following columns:

"degminsec"

6 columns; the first three give degrees, minutes and seconds for latitude, columns 4-6 the same for longitude. Values in column 1 and 4 can be positive or negative (negative means "South", "West", respectively). Values in the other columns should be non-negative.

"decimal2"

2 columns; the first one gives latitude, the second one longitude in proper decimal notation. Values can be positive or negative (negative means "South", "West", respectively).

"decimal4"

4 columns; the first two give latitude, no. 3 and 4 give longitude. Values in column 1 and 3 can be positive or negative (negative means "South", "West", respectively). The give integer degrees. Values in the other columns should be non-negative. They give percentages (<=100).

output.dist

logical. If TRUE, the resulting distance matrix is given out as a dist object.

radius

numeric. Radius of the earth in km used in computation (the default is the equatorial radius but this is not the uniquely possible choice).

fp

flattening of the earth; the default is from WGS-84.

neighbors

logical. If TRUE, a neighborhood list is also computed, listing for every location all locations with distance <=cut as neighbors.

References

German Wikipedia from 29 August 2010: https://de.wikipedia.org/wiki/Orthodrome

See Also

geo2neighbor

Examples

Run this code
  options(digits=4)
  data(veronica)
  coord2dist(coordmatrix=veronica.coord[1:20,], cut=20, file.format="decimal2",neighbors=TRUE)

Run the code above in your browser using DataLab