Skip to content

Commit

Permalink
Merge pull request #704 from akrherz/artcc
Browse files Browse the repository at this point in the history
add manual ARTCC assignment for PIREPs
  • Loading branch information
akrherz authored Feb 13, 2023
2 parents 34d4e67 + 4b06d36 commit 954aa45
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pyiem/nws/products/pirep.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,20 @@ def sql(self, txn):
continue
if report.longitude is None:
geom = "POINT EMPTY"
artcc = "null"
else:
geom = f"SRID=4326;POINT({report.longitude} {report.latitude})"
artcc = (
"(select ident from airspaces where st_dwithin(geom, "
f"ST_MakePoint({report.longitude}, {report.latitude}), 0) "
"and type_code = 'ARTCC' LIMIT 1)"
)
txn.execute(
"INSERT into pireps(valid, geom, is_urgent, "
"aircraft_type, report) VALUES (%s, "
"ST_GeographyFromText(%s), %s, %s, %s)",
f"""
INSERT into pireps(valid, geom, is_urgent, aircraft_type,
report, artcc) VALUES (%s,
ST_GeographyFromText(%s), %s, %s, %s, {artcc})
""",
(
report.valid,
geom,
Expand Down

0 comments on commit 954aa45

Please sign in to comment.