added WFOs to county database

This commit is contained in:
AdenKoperczak 2024-08-29 13:41:25 -04:00
parent 6ef5553028
commit 412c85647c
3 changed files with 36 additions and 2 deletions

View file

@ -34,6 +34,14 @@ def ParseArguments():
nargs = "+",
default = [],
type = pathlib.Path)
parser.add_argument("-w", "--wfo_dbf",
metavar = "filename",
help = "input wfo database",
dest = "inputWfoDbs_",
action = "extend",
nargs = "+",
default = [],
type = pathlib.Path)
parser.add_argument("-o", "--output_db",
metavar = "filename",
help = "output sqlite database",
@ -49,7 +57,7 @@ def Prepare(dbInfo, outputDb):
# Establish SQLite database connection
dbInfo.sqlConnection_ = sqlite3.connect(outputDb)
# Set row factory for name-based access to columns
dbInfo.sqlConnection_.row_factory = sqlite3.Row
@ -62,6 +70,11 @@ def Prepare(dbInfo, outputDb):
dbInfo.sqlCursor_.execute("""CREATE TABLE states(
state TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL)""")
dbInfo.sqlCursor_.execute("""CREATE TABLE wfos(
id TEXT NOT NULL PRIMARY KEY,
city TEXT NOT NULL,
state TEXT NOT NULL,
city_state TEXT NOT NULL)""")
def ProcessCountiesDbf(dbInfo, dbfFilename):
# County area type
@ -130,6 +143,22 @@ def ProcessZoneDbf(dbInfo, dbfFilename):
if resultRow["name"] != row.NAME:
print("Skipping duplicate zone:", fipsId, row.NAME)
def ProcessWfoDbf(dbInfo, dbfFilename):
print("Processing WFO file:", dbfFilename)
# Read dataframe
dbfTable = gpd.read_file(filename = dbfFilename,
columns = ["FULLSTAID", "CITY", "STATE", "CITYSTATE"],
ignore_geometry = True)
dbfTable.drop_duplicates(inplace = True)
for row in dbfTable.itertuples():
try:
dbInfo.sqlCursor_.execute("INSERT INTO wfos VALUES (?, ?, ?, ?)",
(row.FULLSTAID, row.CITY, row.STATE, row.CITYSTATE))
except:
print("Error inserting WFO:", row.FULLSTAID, row.CITYSTATE)
def PostProcess(dbInfo):
# Commit changes and close database
dbInfo.sqlConnection_.commit()
@ -148,4 +177,7 @@ for zoneDb in args.inputZoneDbs_:
for stateDb in args.inputStateDbs_:
ProcessStateDbf(dbInfo, stateDb)
for wfoDb in args.inputWfoDbs_:
ProcessWfoDbf(dbInfo, wfoDb)
PostProcess(dbInfo)