5

I am just starting to use R.

I came across R function -alphahull- and believe it is the best option to turn gps points into a polygon (3 or 4 days worth of gps points across residence/neighborhood for each of 300 subjects).

How do I remove duplicate points?

I am getting the following error: "Error in tri.mesh(X) : duplicate data points" after running:

library(sp)
library(alphahull)
library(maptools)

#define projection project2<-"+proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"

read point shapefile

data.shape <- readShapePoints("D:/clayera/UWO/msthesistake2/tesisGIS/D1001_GPS_WalkExtSel.shp",proj4string=CRS(project2)) plot(data.shape) summary(data.shape)

extract coordinates

x.coords <- coordinates(data.shape) #this way we get duplicate coordinates

alpha-shape: 100 meter threshold

x.as <- ashape(x.coords[,1], x.coords[,2], alpha=100)

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user9914
  • 71
  • 1
  • 3

2 Answers2

1

I remove duplicate points using the sp zerodist function.

sdata <- sdata[-zerodist(sdata )[,1],]

There is a formalized alphahull function that will return an sp SpatialPolygonDataFrame object suitable for export as a shapefile in this thread: Concave Hull: Definition, Algorithms and Practical Solutions

Jeffrey Evans
  • 31,750
  • 2
  • 47
  • 94
1

If you don't want to modify the SpatialPointsDataFrame object data.shape, just insert unique (an efficient function built into base R for such purposes):

x.coords <- unique(coordinates(data.shape))
whuber
  • 69,783
  • 15
  • 186
  • 281