I think this is fine, with two caveats:
- You should preserve order by using an ordered data structure (and not an unordered set).
- You should allow for some repetitions by using a data structure that allows for some repeated DGGS cells: this allows for the representation of self-intersecting lines. You can do this by eliminating only sequential duplicates (which are redundant, unless perhaps you wanted to record the original vertex density, which is possible).
I have an implementation of this in Python:
from typing import Iterator, Union
from shapely.geometry.linestring import LineString
from shapely.geometry.multilinestring import MultiLineString
def sequential_deduplication(func: Iterator[str]) -> Iterator[str]:
Decorator that doesn't permit two consecutive items to be the same
iterable = func(*args)
last = None
while (cell := next(iterable, None)) is not None:
if cell != last:
last = cell
def h3polyline(line: Union[LineString, MultiLineString], resolution: int) -> Iterator[str]:
Iterator yeilding H3 cells representing a (multi)line,
retaining order and self-intersections
if line.geom_type == 'MultiLineString':
# Recurse after getting component linestrings from the multiline
for l in map(lambda geom: h3polyline(geom, resolution), line.geoms):
yield from l
coords = zip(line.coords, line.coords[1:])
while (vertex_pair := next(coords, None)) is not None:
i, j = vertex_pair
a = h3.geo_to_h3(*i[::-1], resolution)
b = h3.geo_to_h3(*j[::-1], resolution)
yield from h3.h3_line(a, b) # inclusive of a and b
Although it accepts multilinestring input, it doesn't really retain the distinction of multiple parts (I just didn't need that distinction).
That said, you might not care about order or self-intersections. This really depends on the intended application of your H3-discretised representation of a line. For lines with really long distances between vertices, perhaps first projecting and densifying a line would be sensible.