-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
89 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
""" | ||
from __future__ import print_function | ||
import copy | ||
import sys | ||
import os | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
from pyiem.util import get_dbconn | ||
"""Compute the county a HUC12 belongs in.""" | ||
from pyiem.util import get_dbconn, logger | ||
|
||
postgis = get_dbconn("postgis") | ||
pcursor = postgis.cursor() | ||
LOG = logger() | ||
|
||
dep = get_dbconn("idep") | ||
cursor = dep.cursor() | ||
cursor2 = dep.cursor() | ||
|
||
cursor.execute( | ||
"""with data as ( | ||
SELECT ST_Transform(ST_Centroid(geom), 4326) as geo, gid | ||
from huc12 where ugc is null) | ||
def main(): | ||
"""Go Main Go.""" | ||
postgis = get_dbconn("postgis") | ||
pcursor = postgis.cursor() | ||
|
||
SELECT ST_x(geo), ST_y(geo), gid from data | ||
""" | ||
) | ||
for row in cursor: | ||
pcursor.execute( | ||
""" | ||
select ugc from ugcs where end_ts is null and | ||
ST_Contains(geom, ST_SetSrid(ST_GeomFromText('POINT(%s %s)'), 4326)) | ||
and substr(ugc, 3, 1) = 'C' | ||
dep = get_dbconn("idep") | ||
cursor = dep.cursor() | ||
cursor2 = dep.cursor() | ||
|
||
cursor.execute( | ||
"""with data as ( | ||
SELECT ST_Transform(ST_Centroid(geom), 4326) as geo, gid, huc_12 | ||
from huc12 where ugc is null) | ||
SELECT ST_x(geo), ST_y(geo), gid, huc_12 from data | ||
""" | ||
% (row[0], row[1]) | ||
) | ||
ugc = pcursor.fetchone()[0] | ||
cursor2.execute( | ||
"""UPDATE huc12 SET ugc = %s where gid = %s | ||
""", | ||
(ugc, row[2]), | ||
) | ||
for row in cursor: | ||
pcursor.execute( | ||
""" | ||
select ugc from ugcs where end_ts is null and | ||
ST_Contains(geom, ST_SetSrid(ST_GeomFromText('POINT(%s %s)'), 4326)) | ||
and substr(ugc, 3, 1) = 'C' | ||
""" | ||
% (row[0], row[1]) | ||
) | ||
if pcursor.rowcount == 0: | ||
LOG.info("failed to find a county for HUC12: %s", row[3]) | ||
continue | ||
ugc = pcursor.fetchone()[0] | ||
cursor2.execute( | ||
"UPDATE huc12 SET ugc = %s where gid = %s", | ||
(ugc, row[2]), | ||
) | ||
|
||
cursor2.close() | ||
dep.commit() | ||
|
||
|
||
cursor2.close() | ||
dep.commit() | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.