|
15 | 15 | # =============================================================================== |
16 | 16 | import json |
17 | 17 | import os |
18 | | -from pprint import pprint |
19 | 18 |
|
20 | 19 | import click |
21 | 20 | import httpx |
22 | | -from shapely import Polygon, box |
23 | 21 | from shapely.geometry import shape |
24 | 22 |
|
25 | 23 | from backend.geo_utils import transform_srid, SRID_WGS84, SRID_UTM_ZONE_13N |
26 | 24 |
|
27 | 25 |
|
28 | | -# polygon retrivial functions |
29 | | -# multiple polygons |
30 | | -def get_congressional_district_boundaries(state, district): |
31 | | - pass |
32 | | - |
33 | | - |
34 | | -def get_tribal_boundaries(state=None): |
35 | | - state, statefp = _get_statefp(state) |
36 | | - |
37 | | - # use the processes service to get all tribal boundaries that intersect the state |
38 | | - def func(): |
39 | | - payload = { |
40 | | - "inputs": { |
41 | | - "collection": f"aiannh", |
42 | | - "url": f"https://geoconnex.us/ref/states/{statefp}", |
43 | | - } |
44 | | - } |
45 | | - resp = httpx.post( |
46 | | - "https://reference.geoconnex.us/processes/intersector/execution", |
47 | | - json=payload, |
48 | | - ) |
49 | | - return resp.json() |
50 | | - |
51 | | - obj = _get_cached_object(f"{state}.aiannh", f"{state} AIANNH", func) |
52 | | - |
53 | | - return obj |
54 | | - |
55 | | - |
56 | | -def get_state_hucs_boundaries(state=None, level=8): |
57 | | - state, statefp = _get_statefp(state) |
58 | | - |
59 | | - # use the processes service to get all hucs from this level that intersect the state of NM |
60 | | - def func(): |
61 | | - payload = { |
62 | | - "inputs": { |
63 | | - "collection": f"hu{level:02n}", |
64 | | - "url": f"https://geoconnex.us/ref/states/{statefp}", |
65 | | - } |
66 | | - } |
67 | | - resp = httpx.post( |
68 | | - "https://reference.geoconnex.us/processes/intersector/execution", |
69 | | - json=payload, |
70 | | - ) |
71 | | - return resp.json() |
72 | | - |
73 | | - obj = _get_cached_object(f"{state}.hucs.{level}", f"{state} HU{level:02n}", func) |
74 | | - |
75 | | - return obj |
76 | | - |
77 | | - |
78 | | -def get_state_pwss_boundaries(state=None): |
79 | | - state, statefp = _get_statefp(state) |
80 | | - obj = _get_cached_object( |
81 | | - f"{state}.pws", |
82 | | - f"{state} PWSs", |
83 | | - f"https://reference.geoconnex.us/collections/pws/items?f=json&state_code={state}", |
84 | | - ) |
85 | | - |
86 | | - return obj |
87 | | - |
88 | | - |
89 | | -# single polygons |
90 | | - |
91 | | - |
92 | | -def get_pws_polygon(pwsid, as_wkt=True): |
93 | | - obj = _get_cached_object( |
94 | | - pwsid, |
95 | | - pwsid, |
96 | | - f"https://reference.geoconnex.us/collections/pws/items/{pwsid}?f=json", |
97 | | - ) |
98 | | - return _make_shape(obj, as_wkt) |
99 | | - |
100 | | - |
101 | | -def get_huc_polygon(huc, as_wkt=True): |
102 | | - if len(huc) == 2: |
103 | | - collection = "hu02" |
104 | | - elif len(huc) == 4: |
105 | | - collection = "hu04" |
106 | | - elif len(huc) == 6: |
107 | | - collection = "hu06" |
108 | | - elif len(huc) == 8: |
109 | | - collection = "hu08" |
110 | | - elif len(huc) == 10: |
111 | | - collection = "hu10" |
112 | | - else: |
113 | | - _warning(f"Invalid HUC {huc}. length must be 2, 4, 6, 8, or 10") |
114 | | - return |
115 | | - |
116 | | - obj = _get_cached_object( |
117 | | - huc, |
118 | | - huc, |
119 | | - f"https://reference.geoconnex.us/collections/{collection}/items/{huc}?f=json", |
120 | | - ) |
121 | | - |
122 | | - return _make_shape(obj, as_wkt) |
123 | | - |
124 | | - |
125 | 26 | def get_county_polygon(name, as_wkt=True): |
126 | 27 | if ":" in name: |
127 | 28 | state, county = name.split(":") |
|
0 commit comments