Read the state fields that join states with a hyphen
NPS writes MO-IL, ID-MT-WY and TN-NC, and the old split on commas and slashes dropped those places' states. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e59c152e7c
commit
c704139e5b
2 files changed
+14
-2
No files matched your search
@@ -265,12 +265,17 @@ def _geojson_groups(path, key_of):
|
||||
for k, feats in groups.items()}
|
||||
|
||||
|
||||
def state_codes(text):
|
||||
"""Two-letter state codes from a source's state field: "CA", "ID-MT-WY", "AR/OK", "FL 6/"."""
|
||||
return [c for c in re.split(r"[,/\- ]+", text or "") if len(c) == 2 and c.isalpha()]
|
||||
|
||||
|
||||
def _read_nps(path):
|
||||
groups = _geojson_groups(path, lambda p: (p.get("UNIT_CODE") or "").strip() or None)
|
||||
out = []
|
||||
for code, (p, geom) in groups.items():
|
||||
out.append(Outline("park", "nps", code, (p.get("UNIT_NAME") or code).strip(),
|
||||
[s for s in re.split(r"[,/ ]+", p.get("STATE") or "") if len(s) == 2],
|
||||
state_codes(p.get("STATE")),
|
||||
geom, path=(p.get("UNIT_TYPE") or "")))
|
||||
return out
|
||||
|
||||
@@ -347,7 +352,7 @@ def _read_wilderness(path):
|
||||
name = str(pick(row, ["Name", "WILD_NAME", "AREANAME", "AreaName"])).strip()
|
||||
wid = str(pick(row, ["WID", "ID", "AreaID", "OBJECTID"]) or name)
|
||||
state = str(pick(row, ["STATE", "State"]) or "")
|
||||
hint = [s for s in re.split(r"[,/ ]+", state) if len(s) == 2]
|
||||
hint = state_codes(state)
|
||||
if row.get("_geometry") is not None and name:
|
||||
groups.setdefault(wid, (name, hint, []))[2].append(row["_geometry"])
|
||||
return [Outline("wilderness", "wilderness-connect", wid, name, hint, _union_geoms(geoms))
|
||||
|
||||
@@ -149,6 +149,13 @@ class ProposalTest(unittest.TestCase):
|
||||
o = outline("park", "P9", "Edge Park", self.park.geometry, hint=["MT", "ID", "PR"])
|
||||
self.assertEqual(P.where_of(o), ["ID", "MT"])
|
||||
|
||||
def test_state_codes_reads_the_separators_the_sources_use(self):
|
||||
self.assertEqual(P.state_codes("ID-MT-WY"), ["ID", "MT", "WY"])
|
||||
self.assertEqual(P.state_codes("AR/OK"), ["AR", "OK"])
|
||||
self.assertEqual(P.state_codes("FL 6/"), ["FL"])
|
||||
self.assertEqual(P.state_codes("SAMOA"), [])
|
||||
self.assertEqual(P.state_codes(None), [])
|
||||
|
||||
def test_where_of_a_range_is_found_from_the_state_boxes(self):
|
||||
# wholly inside the Wyoming box, clear of every other state's box
|
||||
o = outline("range", "R5", "Wyoming Range", self.park.geometry)
|
||||
|
||||
Reference in new issue
Block a user