diff --git a/lib/xmet/spc.py b/lib/xmet/spc.py index 9d0f331..f37b5d0 100644 --- a/lib/xmet/spc.py +++ b/lib/xmet/spc.py @@ -5,6 +5,7 @@ import datetime from xmet.db import DatabaseTable from xmet.coord import COORD_SYSTEM +from xmet.geo import PointSequence from xmet.afos import MONTHS, TIMEZONES RE_HEADER = re.compile(r''' @@ -71,7 +72,7 @@ def parse_coord(coord: str) -> tuple[float, float]: return shapely.Point(0.01 * -lon, 0.01 * int(coord[0:4])) -def each_poly(parts: list[str]): +def each_point_sequence(parts: list[str]): points = list() for part in parts: @@ -80,8 +81,14 @@ def each_poly(parts: list[str]): else: points.append(parse_coord(part)) - if len(points) >= 3: - yield shapely.Polygon(points) + if len(points) > 1: + yield PointSequence(points) + +def each_poly(parts: list[str]): + for sequence in each_point_sequence(parts): + sequence.close() + + yield sequence.poly class SPCOutlookArea(DatabaseTable): __slots__ = ('id', 'outlook_id', 'poly')