Use 99999999 as polygon delimiter
This commit is contained in:
parent
698ac23033
commit
90993e08d1
1 changed files with 25 additions and 14 deletions
|
@ -48,7 +48,7 @@ RE_HAZARD = re.compile(r'''
|
|||
|
||||
RE_POINTS_START = re.compile(r'''
|
||||
^(?P<category>[A-Z0-9\.]+)
|
||||
(?P<rest>\s+\d{8}){1,6}
|
||||
(?P<rest>(?:\s+\d{8}){1,6})
|
||||
''', re.X)
|
||||
|
||||
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])
|
||||
)
|
||||
|
||||
def parse_poly(points: list[str]) -> shapely.Polygon:
|
||||
return shapely.Polygon([parse_coord(p) for p in points])
|
||||
def each_poly(parts: list[str]):
|
||||
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):
|
||||
__slots__ = ('id', 'outlook_id', 'poly')
|
||||
|
@ -276,17 +286,18 @@ class SPCOutlookParser():
|
|||
self.state = SPCOutlookParserState.AREA_THREAT
|
||||
|
||||
def handle_area(self):
|
||||
for poly in each_poly(self.points):
|
||||
if self.area_type == 'PROBABILISTIC':
|
||||
area = SPCOutlookProbabilityArea()
|
||||
area.hazard = self.hazard
|
||||
area.probability = self.category
|
||||
area.poly = parse_poly(self.points)
|
||||
area.poly = poly
|
||||
|
||||
self.outlook.probabilities.append(area)
|
||||
elif self.area_type == 'CATEGORICAL':
|
||||
area = SPCOutlookCategoryArea()
|
||||
area.category = self.category
|
||||
area.poly = parse_poly(self.points)
|
||||
area.poly = poly
|
||||
|
||||
self.outlook.categories.append(area)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue