Search code examples
rrgdalr-sp

R remove duplicate spatial points according an attribute


In R I have a SpatialPointsDataFrame whit duplicated point (coordinates and attributes), I would like to remove all point with same data ...

I have find in the sp package the remove.duplicates() function but it seems to remove only on location ... Is there another way?

thank you

E.


Solution

  • Would something like this work?

    library(sp)
    pts <- SpatialPoints(cbind(c(1, 1, 1, 2, 3, 4), c(1, 1, 1, 4, 2, 4)))
    pts <- SpatialPointsDataFrame(pts, data=data.frame(id = c(1, 2, 2, 3, 4, 5)))
    
    ## All points
    pts
    
    ## No spatial duplicates
    remove.duplicates(pts)
    
    ## No duplicates in attributes
    pts[which(!duplicated(pts$id)), ]
    
    ## Combination
    pts[which(!duplicated(as.data.frame(pts))), ]