Learn R Programming

SpatialTools (version 0.4.1)

coincident: Determine coincident locations

Description

Determines the coincident locations for two sets of coordinates.

Usage

coincident(coords1, coords2)

Arguments

coords1
A numeric matrix of size $n1 \times 2$ containing a set of coordinates.
coords2
A numeric matrix of size $n2 \times 2$ containing a set of coordinates.

Value

  • Returns a matrix with the indices of the coincident locations. Specifically, an $r \times 2$ matrix will be returned, with $r$ being the number of coordinates in coords1 coinciding with coordinates in $coords2$. If row i of the matrix was (2, 5), then the ith set of coincident locations was between the 2nd row of coords1 and the 5th row of coords2. If there are no coincident locations, then a matrix of size $0 \times 2$ will be returned.

Details

This function calls a C++ algorithm using the Rcpp package. This (may) result in a significant speedup over pure R code since the search algorithm involves loops. An implicit assumptions is that there are no duplicate coordinates in coords1 and coords2, respectively. In other words, each row of coords1 is unique and each row of coords2 is unique. There is at most 1 row of coords1 that will match with a row in coords2.

See Also

cov.st

Examples

Run this code
#Generate two sets of coordinates
loc1 <- as.matrix(expand.grid(seq(0, 1, len = 25), seq(0, 1, len = 25)))
loc2 <- as.matrix(expand.grid(seq(0, 1, len = 101), seq(0, 1, len = 101)))

#Return indices of coincident coordinates
coincident(loc1, loc2)

Run the code above in your browser using DataLab