Compare commits
3 commits
4f0c11cfca
...
0fdfc1172c
Author | SHA1 | Date | |
---|---|---|---|
0fdfc1172c | |||
d382b9809c | |||
c64a437fb2 |
3 changed files with 70 additions and 2 deletions
|
@ -95,7 +95,7 @@ create table xmet_igra_station (
|
||||||
year_start INTEGER NOT NULL,
|
year_start INTEGER NOT NULL,
|
||||||
year_end INTEGER NOT NULL,
|
year_end INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
us_state TEXT NOT NULL,
|
state TEXT NOT NULL,
|
||||||
elevation FLOAT NOT NULL
|
elevation FLOAT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ class AFOSMessage(DatabaseTable):
|
||||||
'location': 'ST_AsText(location) as location'
|
'location': 'ST_AsText(location) as location'
|
||||||
}
|
}
|
||||||
|
|
||||||
__values_write__ = {
|
__values_read__ = {
|
||||||
'poly': shapely.from_wkt,
|
'poly': shapely.from_wkt,
|
||||||
'location': shapely.from_wkt
|
'location': shapely.from_wkt
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ import re
|
||||||
import datetime
|
import datetime
|
||||||
import shapely
|
import shapely
|
||||||
|
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
|
from xmet.db import DatabaseTable
|
||||||
from xmet.coord import COORD_SYSTEM
|
from xmet.coord import COORD_SYSTEM
|
||||||
from xmet.sounding import Sounding, SoundingSample
|
from xmet.sounding import Sounding, SoundingSample
|
||||||
|
|
||||||
|
@ -146,3 +149,68 @@ class IGRAReader():
|
||||||
count -= 1
|
count -= 1
|
||||||
|
|
||||||
return sounding
|
return sounding
|
||||||
|
|
||||||
|
def cols(text: str, start: int, end: int):
|
||||||
|
a = start - 1
|
||||||
|
b = end
|
||||||
|
|
||||||
|
return text[a:b]
|
||||||
|
|
||||||
|
class IGRAStation(DatabaseTable):
|
||||||
|
__table__ = 'xmet_igra-station'
|
||||||
|
__key__ = 'code'
|
||||||
|
|
||||||
|
__columns__ = (
|
||||||
|
'code', 'year_start', 'year_end', 'name', 'state', 'elevation',
|
||||||
|
'location'
|
||||||
|
)
|
||||||
|
|
||||||
|
__columns_read__ = {
|
||||||
|
'location': 'ST_AsText(location) as location'
|
||||||
|
}
|
||||||
|
|
||||||
|
__values_read__ = {
|
||||||
|
'location': shapely.from_wkt
|
||||||
|
}
|
||||||
|
|
||||||
|
__columns_write__ = {
|
||||||
|
'location': 'ST_GeomFromText(:location, {crs})'.format(crs=COORD_SYSTEM)
|
||||||
|
}
|
||||||
|
|
||||||
|
__values_write__ = {
|
||||||
|
'location': lambda v: {'location': shapely.to_wkt(v)}
|
||||||
|
}
|
||||||
|
|
||||||
|
code: str
|
||||||
|
year_start: int
|
||||||
|
year_end: int
|
||||||
|
name: str
|
||||||
|
state: str
|
||||||
|
elevation: float
|
||||||
|
location: shapely.Point
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.code = None
|
||||||
|
self.year_start = None
|
||||||
|
self.year_end = None
|
||||||
|
self.name = None
|
||||||
|
self.state = None
|
||||||
|
self.elevation = None
|
||||||
|
self.location = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse_station(line: str) -> Self:
|
||||||
|
lat = float(cols(line, 13, 20))
|
||||||
|
lon = float(cols(line, 22, 30))
|
||||||
|
|
||||||
|
station = IGRAStation()
|
||||||
|
station.code = cols(line, 1, 11)
|
||||||
|
station.year_start = int(cols(line, 73, 76))
|
||||||
|
station.year_end = int(cols(line, 78, 81))
|
||||||
|
station.name = cols(line, 42, 71)
|
||||||
|
station.state = cols(line, 39, 40)
|
||||||
|
station.elevation = float(cols(line, 32, 37))
|
||||||
|
station.location = shapely.Point(lon, lat)
|
||||||
|
|
||||||
|
return station
|
||||||
|
|
Loading…
Add table
Reference in a new issue