Skip to content

Commit

Permalink
Implement RemoveRepeatedPoints for MultiLineString
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Nov 28, 2021
1 parent b0a85e7 commit 04f1e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions geom/alg_remove_repeated_points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func TestRemoveRepeatedPoints(t *testing.T) {
{"LINESTRING M(0 0 0,0 0 1,1 1 1)", "LINESTRING M(0 0 0,1 1 1)"},
{"LINESTRING Z(0 0 0,0 0 1,1 1 1)", "LINESTRING Z(0 0 0,1 1 1)"},
{"LINESTRING ZM(0 0 1 2,0 0 2 3,1 1 4 5)", "LINESTRING ZM(0 0 1 2,1 1 4 5)"},

{"MULTILINESTRING EMPTY", "MULTILINESTRING EMPTY"},
{"MULTILINESTRING(EMPTY)", "MULTILINESTRING(EMPTY)"},
{"MULTILINESTRING((0 0,1 1))", "MULTILINESTRING((0 0,1 1))"},
{"MULTILINESTRING((0 0,0 0,1 1))", "MULTILINESTRING((0 0,1 1))"},
{"MULTILINESTRING((0 0,1 1))", "MULTILINESTRING((0 0,1 1))"},
{"MULTILINESTRING((0 0,1 1),(2 2,3 3))", "MULTILINESTRING((0 0,1 1),(2 2,3 3))"},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
inputG := geomFromWKT(t, tt.input)
Expand Down
2 changes: 1 addition & 1 deletion geom/type_geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ func (g Geometry) RemoveRepeatedPoints() Geometry {
case TypeMultiPoint:
return g.MustAsMultiPoint().RemoveRepeatedPoints().AsGeometry()
case TypeMultiLineString:
return g
return g.MustAsMultiLineString().RemoveRepeatedPoints().AsGeometry()
case TypeMultiPolygon:
return g
default:
Expand Down
10 changes: 10 additions & 0 deletions geom/type_multi_line_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,13 @@ func (m MultiLineString) Simplify(threshold float64) MultiLineString {
}
return NewMultiLineString(lss)
}

// RemoveRepeatedPoints returns a version of the MultiLineString that has had
// repeated points in its child LineStrings removed.
func (m MultiLineString) RemoveRepeatedPoints() MultiLineString {
lss := make([]LineString, m.NumLineStrings())
for i := range lss {
lss[i] = m.LineStringN(i).RemoveRepeatedPoints()
}
return NewMultiLineString(lss)
}

0 comments on commit 04f1e5a

Please sign in to comment.