Skip to content

Commit

Permalink
Logic to ensure we get latest (2023) GENZ national boundary files
Browse files Browse the repository at this point in the history
  • Loading branch information
jessemortenson committed Jan 30, 2025
1 parent 86d21c6 commit b39eb74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configs/settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BOUNDARY_YEAR: "2022"
BOUNDARY_YEAR: "2024"

SKIPPED_GEOIDS: []
# cd-6098: American Samoa
Expand Down
21 changes: 20 additions & 1 deletion utils/tiger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,30 @@ def download_boundary_file(boundary_year: str):
if os.path.exists(output):
print("Boundary file exists. Skipping download.")
return
# 2024 boundary year files do not exist as of 1/27/25
# so try changing to last known good year
original_boundary_year = boundary_year
if int(boundary_year) > 2023:
boundary_year = "2023"
url = f"{TIGER_ROOT}/GENZ{boundary_year}/shp/cb_{boundary_year}_us_nation_5m.zip"
print(f"Downloading national boundary from {url}")
_ = urllib.request.urlretrieve(url, output)
directory = f"{ROOTDIR}/data/boundary/"
with zipfile.ZipFile(output, "r") as zf:
zf.extractall(f"{ROOTDIR}/data/boundary/")
zf.extractall(directory)
# Rename all files replace boundary_year with intended/original boundary year
# this is done so later code doesn't break (expecting boundary_year in filename)
for filename in os.listdir(directory):
if '2023' in filename:
# Create the new filename by replacing '2023' with intended boundary year
new_filename = filename.replace('2023', original_boundary_year)

# Define the full file paths
old_file = os.path.join(directory, filename)
new_file = os.path.join(directory, new_filename)

# Rename the file
os.rename(old_file, new_file)


def _download_and_extract(url: str, filename: str):
Expand Down

0 comments on commit b39eb74

Please sign in to comment.