Use 99999999 as polygon delimiter

This commit is contained in:
XANTRONIX 2025-03-16 00:15:40 -04:00
parent 698ac23033
commit 90993e08d1

View file

@ -48,7 +48,7 @@ RE_HAZARD = re.compile(r'''
RE_POINTS_START = re.compile(r''' RE_POINTS_START = re.compile(r'''
^(?P<category>[A-Z0-9\.]+) ^(?P<category>[A-Z0-9\.]+)
(?P<rest>\s+\d{8}){1,6} (?P<rest>(?:\s+\d{8}){1,6})
''', re.X) ''', re.X)
RE_POINTS = re.compile(r'^(?:\s+\d{8}){1,6}$') RE_POINTS = re.compile(r'^(?:\s+\d{8}){1,6}$')
@ -68,8 +68,18 @@ def parse_coord(coord: str) -> tuple[float, float]:
0.01 * int(coord[0:4]) 0.01 * int(coord[0:4])
) )
def parse_poly(points: list[str]) -> shapely.Polygon: def each_poly(parts: list[str]):
return shapely.Polygon([parse_coord(p) for p in points]) points = list()
for part in parts:
if part == '99999999':
yield shapely.Polygon(points)
points = list()
else:
points.append(parse_coord(part))
if len(points) > 0:
yield shapely.Polygon(points)
class SPCOutlookArea(DatabaseTable): class SPCOutlookArea(DatabaseTable):
__slots__ = ('id', 'outlook_id', 'poly') __slots__ = ('id', 'outlook_id', 'poly')
@ -276,17 +286,18 @@ class SPCOutlookParser():
self.state = SPCOutlookParserState.AREA_THREAT self.state = SPCOutlookParserState.AREA_THREAT
def handle_area(self): def handle_area(self):
for poly in each_poly(self.points):
if self.area_type == 'PROBABILISTIC': if self.area_type == 'PROBABILISTIC':
area = SPCOutlookProbabilityArea() area = SPCOutlookProbabilityArea()
area.hazard = self.hazard area.hazard = self.hazard
area.probability = self.category area.probability = self.category
area.poly = parse_poly(self.points) area.poly = poly
self.outlook.probabilities.append(area) self.outlook.probabilities.append(area)
elif self.area_type == 'CATEGORICAL': elif self.area_type == 'CATEGORICAL':
area = SPCOutlookCategoryArea() area = SPCOutlookCategoryArea()
area.category = self.category area.category = self.category
area.poly = parse_poly(self.points) area.poly = poly
self.outlook.categories.append(area) self.outlook.categories.append(area)