I looked at the shapefile. There is an id column, but if you are drawing data, it seems that the identifier is not ordered from north to south or something like that. Extra rows are created because the point order is not perfect, connecting the points that are next to each other in the table, but far from each other in terms of space. You can try to figure out the correct ordering of the data by calculating the distances between the points and then arranging them at a distance.
A workaround is to remove those lines whose length exceeds a certain distance, for example. 500 m. First find out where the distance between successive coordinates is greater than this distance: breaks . Then grab a subset of the coordinates between the two breaks and finally create Lines for that subset. As a result, you get a coastline consisting of several segments ( breaks-1 ) and without error.
# read data library(rgdal) pst<-readOGR("/data_spatial/coast/","points_coast") coord<-as.data.frame(coordinates(pst)) colnames(coord) <- c('X','Y')

source share