zerodist                 package:sp                 R Documentation

_f_i_n_d _p_o_i_n_t _p_a_i_r_s _w_i_t_h _e_q_u_a_l _s_p_a_t_i_a_l _c_o_o_r_d_i_n_a_t_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     find point pairs with equal spatial coordinates

_U_s_a_g_e:

      
     zerodist(obj, zero = 0.0, unique.ID = FALSE) 
     zerodist2(obj1, obj2, zero = 0.0) 
     remove.duplicates(obj, zero = 0.0, remove.second = TRUE)

_A_r_g_u_m_e_n_t_s:

     obj: object of, or extending, class SpatialPoints 

    obj1: object of, or extending, class SpatialPoints 

    obj2: object of, or extending, class SpatialPoints 

    zero: distance values less than or equal to this threshold value
          are considered to have zero distance (default 0.0) 

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 

remove.second: logical; if TRUE, the second of each pair of duplicate
          points is removed, if FALSE remove the first

_V_a_l_u_e:

     pairs of row numbers with identical coordinates; matrix with zero
     rows  if no such pairs are found. For 'zerodist', row number pairs
     refer to row pairs in 'obj'. For 'zerodist2', row number pairs
     refer to rows in 'obj' and 'obj2', respectively.

_N_o_t_e:

     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.

_E_x_a_m_p_l_e_s:

     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),])

