zerodist {sp} | R Documentation

## find point pairs with equal spatial coordinates

### Description

find point pairs with equal spatial coordinates

### Usage

    zerodist(obj, zero = 0.0)
    remove.duplicates(obj, zero = 0.0)

### Arguments

`obj` | object of, or extending, class SpatialPoints
`zero` | value to be compared to for establishing when a distance is considered zero (default 0.0)

### Value

pairs of row numbers with identical coordinates, numeric(0) if no such pairs are found

### 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. A matrix with all pair-wise distances is calculated, so if x, y and z are large this function is slow

### 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)

[Package sp version 0.7-12 Index]