| 1 |
\name{zerodist} |
| 2 |
\alias{zerodist} |
| 3 |
\alias{zerodist2} |
| 4 |
\alias{remove.duplicates} |
| 5 |
\title{ find point pairs with equal spatial coordinates } |
| 6 |
\description{ find point pairs with equal spatial coordinates } |
| 7 |
\usage{ |
| 8 |
zerodist(obj, zero = 0.0, unique.ID = FALSE, memcmp = TRUE) |
| 9 |
zerodist2(obj1, obj2, zero = 0.0, memcmp = TRUE) |
| 10 |
remove.duplicates(obj, zero = 0.0, remove.second = TRUE, memcmp = TRUE) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{obj}{ object of, or extending, class \link{SpatialPoints} } |
| 14 |
\item{obj1}{ object of, or extending, class \link{SpatialPoints} } |
| 15 |
\item{obj2}{ object of, or extending, class \link{SpatialPoints} } |
| 16 |
\item{zero}{ distance values less than or equal to this threshold value are |
| 17 |
considered to have zero distance (default 0.0); |
| 18 |
units are those of the coordinates for projected data or unknown projection, |
| 19 |
or km if coordinates are defined to be longitude/latitude } |
| 20 |
\item{unique.ID}{logical; if TRUE, return an ID (integer) for each point |
| 21 |
that is different only when two points do not share the same location } |
| 22 |
\item{memcmp}{use \code{memcmp} to find exactly equal coordinates; see NOTE} |
| 23 |
\item{remove.second}{logical; if TRUE, the second of each pair of duplicate |
| 24 |
points is removed, if FALSE remove the first} |
| 25 |
} |
| 26 |
\value{\code{zerodist} and \code{zerodist2} return a two-column matrix |
| 27 |
with in each row pairs of row numbers with identical coordinates; |
| 28 |
a matrix with zero rows is returned if no such pairs are found. For |
| 29 |
\code{zerodist}, row number pairs refer to row pairs in \code{obj}. For |
| 30 |
\code{zerodist2}, row number pairs refer to rows in \code{obj} and |
| 31 |
\code{obj2}, respectively. \code{remove.duplicates} removes duplicate |
| 32 |
observations if present, and else returns \code{obj}. } |
| 33 |
|
| 34 |
\note{ When using kriging, duplicate observations sharing identical |
| 35 |
spatial locations result in singular covariance matrices. |
| 36 |
This function may help identify and remove spatial duplices. |
| 37 |
The full matrix with all pair-wise distances is not stored; the |
| 38 |
double loop is done at the C level. |
| 39 |
|
| 40 |
When \code{unique.ID=TRUE} is used, an integer index is returned. sp |
| 41 |
1.0-14 returned the highest index, sp 1.0-15 and later return the |
| 42 |
lowest index. |
| 43 |
|
| 44 |
When \code{zero} is 0.0 and \code{memcmp} is not \code{FALSE}, |
| 45 |
\code{zerodist} uses \code{memcmp} to evaluate exact equality of |
| 46 |
coordinates; there may be cases where this results in a different |
| 47 |
evaluation compared to doing the double arithmetic of computing |
| 48 |
distances. |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
\examples{ |
| 53 |
data(meuse) |
| 54 |
summary(meuse) |
| 55 |
# pick 10 rows |
| 56 |
n <- 10 |
| 57 |
ran10 <- sample(nrow(meuse), size = n, replace = TRUE) |
| 58 |
meusedup <- rbind(meuse, meuse[ran10, ]) |
| 59 |
coordinates(meusedup) <- c("x", "y") |
| 60 |
zd <- zerodist(meusedup) |
| 61 |
sum(abs(zd[1:n,1] - sort(ran10))) # 0! |
| 62 |
# remove the duplicate rows: |
| 63 |
meusedup2 <- meusedup[-zd[,2], ] |
| 64 |
summary(meusedup2) |
| 65 |
meusedup3 <- subset(meusedup, !(1:nrow(meusedup) \%in\% zd[,2])) |
| 66 |
summary(meusedup3) |
| 67 |
coordinates(meuse) <- c("x", "y") |
| 68 |
zerodist2(meuse, meuse[c(10:33,1,10),]) |
| 69 |
} |
| 70 |
\keyword{dplot} |