File: zerodist.Rd

package info (click to toggle)
r-cran-sp 1:0.9-66-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,696 kB
  • ctags: 123
  • sloc: ansic: 1,475; sh: 6; makefile: 5
file content (55 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
\name{zerodist}
\alias{zerodist}
\alias{zerodist2}
\alias{remove.duplicates}
\title{ find point pairs with equal spatial coordinates }
\description{ find point pairs with equal spatial coordinates }
\usage{ 
zerodist(obj, zero = 0.0, unique.ID = FALSE) 
zerodist2(obj1, obj2, zero = 0.0) 
remove.duplicates(obj, zero = 0.0, remove.second = TRUE)
}
\arguments{
\item{obj}{ object of, or extending, class \link{SpatialPoints} }
\item{obj1}{ object of, or extending, class \link{SpatialPoints} }
\item{obj2}{ object of, or extending, class \link{SpatialPoints} }
\item{zero}{ distance values less than or equal to this threshold value are
considered to have zero distance (default 0.0) }
\item{unique.ID}{logical; if TRUE, return an ID (integer) for each point 
that is different only when two points do not share the same location }
\item{remove.second}{logical; if TRUE, the second of each pair of duplicate
points is removed, if FALSE remove the first}
}
\value{\code{zerodist} and \code{zerodist2} return a two-column matrix
with in each row pairs of row numbers with identical coordinates;
a matrix with zero rows is returned if no such pairs are found. For
\code{zerodist}, row number pairs refer to row pairs in \code{obj}. For
\code{zerodist2}, row number pairs refer to rows in \code{obj} and
\code{obj2}, respectively. \code{remove.duplicates} removes duplicate
observations, or obj if none are present. }

\note{ When using kriging, duplicate observations sharing identical spatial 
locations result in singular covariance matrices in kriging situations.
This function may help identifying spatial duplications, so they
can be removed.  The full matrix with all pair-wise distances is not stored;
the double loop is done at the C level.
}
\examples{
data(meuse)
summary(meuse)
# pick 10 rows
n <- 10
ran10 <- sample(nrow(meuse), size = n, replace = TRUE)
meusedup <- rbind(meuse, meuse[ran10, ])
coordinates(meusedup) <- c("x", "y")
zd <- zerodist(meusedup)
sum(abs(zd[1:n,1] - sort(ran10))) # 0!
# remove the duplicate rows:
meusedup2 <- meusedup[-zd[,2], ]
summary(meusedup2)
meusedup3 <- subset(meusedup, !(1:nrow(meusedup) \%in\% zd[,2]))
summary(meusedup3)
coordinates(meuse) <- c("x", "y")
zerodist2(meuse, meuse[c(10:33,1,10),])
}
\keyword{dplot}