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'''
|
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,19 +286,20 @@ class SPCOutlookParser():
|
||||||
self.state = SPCOutlookParserState.AREA_THREAT
|
self.state = SPCOutlookParserState.AREA_THREAT
|
||||||
|
|
||||||
def handle_area(self):
|
def handle_area(self):
|
||||||
if self.area_type == 'PROBABILISTIC':
|
for poly in each_poly(self.points):
|
||||||
area = SPCOutlookProbabilityArea()
|
if self.area_type == 'PROBABILISTIC':
|
||||||
area.hazard = self.hazard
|
area = SPCOutlookProbabilityArea()
|
||||||
area.probability = self.category
|
area.hazard = self.hazard
|
||||||
area.poly = parse_poly(self.points)
|
area.probability = self.category
|
||||||
|
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)
|
||||||
|
|
||||||
self.category = None
|
self.category = None
|
||||||
self.points = list()
|
self.points = list()
|
||||||
|
|
Loading…
Add table
Reference in a new issue