From 01ff03e7b46e145e80aaafbdf40ff7a8afb8619a Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sat, 22 Mar 2025 14:48:47 -0400 Subject: [PATCH] Split each_point_sequence() from each_poly() --- lib/xmet/spc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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')