mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-29 18:40:06 +00:00
added WFOs to county database
This commit is contained in:
parent
6ef5553028
commit
412c85647c
3 changed files with 36 additions and 2 deletions
2
data
2
data
|
|
@ -1 +1 @@
|
|||
Subproject commit 1d93f4106761cabbe61e1265bb1d2b8501600177
|
||||
Subproject commit 0a4bb474dc259751c6c69fe6dc3a1a010d6d0888
|
||||
|
|
@ -388,6 +388,7 @@ set(ZONE_DBF_FILES ${SCWX_DIR}/data/db/fz05mr24.dbf
|
|||
${SCWX_DIR}/data/db/oz05mr24.dbf
|
||||
${SCWX_DIR}/data/db/z_05mr24.dbf)
|
||||
set(STATE_DBF_FILES ${SCWX_DIR}/data/db/s_05mr24.dbf)
|
||||
set(WFO_DBF_FILES ${SCWX_DIR}/data/db/w_05mr24.dbf)
|
||||
set(COUNTIES_SQLITE_DB ${scwx-qt_BINARY_DIR}/res/db/counties.db)
|
||||
|
||||
set(RESOURCE_INPUT ${scwx-qt_SOURCE_DIR}/res/scwx-qt.rc.in)
|
||||
|
|
@ -483,6 +484,7 @@ add_custom_command(OUTPUT ${COUNTIES_SQLITE_DB}
|
|||
-c ${COUNTY_DBF_FILES}
|
||||
-z ${ZONE_DBF_FILES}
|
||||
-s ${STATE_DBF_FILES}
|
||||
-w ${WFO_DBF_FILES}
|
||||
-o ${COUNTIES_SQLITE_DB}
|
||||
DEPENDS ${scwx-qt_SOURCE_DIR}/tools/generate_counties_db.py
|
||||
${COUNTY_DB_FILES}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue