I have sfc LINESTRING and I would like to remove overlapping lines. Object data
was created from an algorithm that joins lines with minimum distance. Using unique will not remove the initial lines.
In the example you can see that line 2 and 3 + other lines were the initial lines, then they were used to produce line 1, other lines were removed but 2 and 3 remained. and length of lines proves that!. Extracting the line with the maximum length will not work in my case because in some cases I have a non-overlaping line which I would like to keep!
> class(data)
[1] "sfc_LINESTRING" "sfc"
> length(data)
[1] 3
> data
Geometry set for 3 features
geometry type: LINESTRING
dimension: XY
bbox: xmin: 181.4494 ymin: 4.441853 xmax: 278.9707 ymax: 14.72429
CRS: +proj=longlat +datum=WGS84 +no_defs
LINESTRING (181.4494 4.462799, 181.4722 4.45583...
LINESTRING (181.4494 4.462799, 181.4722 4.45583...
LINESTRING (181.4494 4.462799, 181.4722 4.45583...
> st_overlaps(data,data)
although coordinates are longitude/latitude, st_overlaps assumes that they are planar
Sparse geometry binary predicate list of length 3, where the predicate was `overlaps'
1: 2, 3
2: 1, 3
3: 1, 2
> st_length(data)
Units: [m]
[1] 11628206 7143693 9899478
Criteria to remove:
- The line should be overlapping with other lines
- The line is not the longest line.