Implement VTEC event polygon parsing
This commit is contained in:
parent
a43dc50c03
commit
a96c982991
1 changed files with 22 additions and 5 deletions
|
@ -55,13 +55,33 @@ RE_HYDRO = re.compile(r'''
|
||||||
/$
|
/$
|
||||||
''', re.X)
|
''', re.X)
|
||||||
|
|
||||||
RE_POLY = re.compile(r'^LAT\.\.\.LON(?P<coords> \d{4})+')
|
RE_POLY = re.compile(r'^LAT\.\.\.LON (?P<coords>\d{4}(?: \d{4})+)')
|
||||||
|
|
||||||
def parse_timestamp(text: str, post_2016_05_11: bool):
|
def parse_timestamp(text: str, post_2016_05_11: bool):
|
||||||
return datetime.datetime.strptime(
|
return datetime.datetime.strptime(
|
||||||
text, '%y%m%dT%H%M%SZ'
|
text, '%y%m%dT%H%M%SZ'
|
||||||
).astimezone(datetime.UTC)
|
).astimezone(datetime.UTC)
|
||||||
|
|
||||||
|
def parse_lon(text: str):
|
||||||
|
return 0 - float(text[0:2]) + (float(text[3:4]) / 100)
|
||||||
|
|
||||||
|
def parse_lat(text: str):
|
||||||
|
return float(text[0:2]) + (float(text[3:4]) / 100)
|
||||||
|
|
||||||
|
def parse_shape(text: str):
|
||||||
|
points = list()
|
||||||
|
coords = text.split(' ')
|
||||||
|
|
||||||
|
for i in range(0, len(coords), 2):
|
||||||
|
lat = coords[i]
|
||||||
|
lon = coords[i+1]
|
||||||
|
|
||||||
|
points.append([parse_lon(lon), parse_lat(lat)])
|
||||||
|
|
||||||
|
points.append([parse_lon(coords[0]), parse_lat(coords[1])])
|
||||||
|
|
||||||
|
return shapely.Polygon(points)
|
||||||
|
|
||||||
class VTECEventType(enum.StrEnum):
|
class VTECEventType(enum.StrEnum):
|
||||||
OPERATIONAL = 'O'
|
OPERATIONAL = 'O'
|
||||||
TEST = 'T'
|
TEST = 'T'
|
||||||
|
@ -120,9 +140,6 @@ class VTECEvent(DatabaseTable):
|
||||||
forecaster: str
|
forecaster: str
|
||||||
poly: shapely.Geometry
|
poly: shapely.Geometry
|
||||||
|
|
||||||
def parse_shape(self, coords: str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(text: str):
|
def parse(text: str):
|
||||||
event = VTECEvent()
|
event = VTECEvent()
|
||||||
|
@ -185,7 +202,7 @@ class VTECEvent(DatabaseTable):
|
||||||
match = RE_POLY.match(line)
|
match = RE_POLY.match(line)
|
||||||
|
|
||||||
if match is not None:
|
if match is not None:
|
||||||
event.parse_shape(match['coords'])
|
event.poly = parse_shape(match['coords'])
|
||||||
elif line == '$$':
|
elif line == '$$':
|
||||||
state = VTECEventParserState.FOOTER
|
state = VTECEventParserState.FOOTER
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue