TigerFetch.jl

Download TIGER/Line shapefiles from the US Census Bureau
Log | Files | Refs | README | LICENSE

commit eb8e584506279dec478e92109c89fad68971d137
parent d72848a3cf0ae7bf19bfe7ee16d22ba1ace3dad5
Author: Erik Loualiche <eloualic@umn.edu>
Date:   Thu, 27 Feb 2025 22:12:10 -0600

added some types.

Diffstat:
MREADME.md | 8++++++--
Msrc/geotypes.jl | 37+++++++++++++++++++++++++++++++++++++
Msrc/main.jl | 6++++++
Mtest/UnitTests/downloads.jl | 52++++++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -2,12 +2,14 @@ This package downloads TIGER/Line shapefiles from the US Census Bureau FTP server. - This was written for personal use and to learn about julia's capabilities to generate cli tools. Thus the package is fairly lean and does not convert shapefiles into dataframes or GeoJSON. The package has only been tested for the 2024 files, but could be extended to accomodate other vintages. For serious use, you'd probably be better off using [tigris](https://github.com/walkerke/tigris) +What the package does is provide a convenient interface to pull file from the Census. +You can always check what is directly available on the [ftp server.](https://www2.census.gov/geo/tiger) + ## Installation @@ -55,7 +57,9 @@ You can use it #### Julia package -Look at the test suite (specifically `UnitTests/downloads.jl`) for now +Look at the [doc](https://eloualiche.github.io/TigerFetch.jl/dev/) or at the test suite (specifically `UnitTests/downloads.jl`). + +This [issue](#4) tracks which geographies have been implemented thus far. diff --git a/src/geotypes.jl b/src/geotypes.jl @@ -37,11 +37,21 @@ struct PrimaryRoads <: NationalGeography end const PRIMARYROADS_META = (tiger_name = "PRIMARYROADS", description = "Primary Roads") +struct Rails <: NationalGeography + year::Int +end +const RAILS_META = (tiger_name = "RAILS", description = "Rails") + struct CBSA <: NationalGeography year::Int end const CBSA_META = (tiger_name = "CBSA", description = "Core Based Statistical Area") +struct CSA <: NationalGeography + year::Int +end +const CSA_META = (tiger_name = "CSA", description = "Combined Statistical Area") + struct METDIV <: NationalGeography year::Int end @@ -60,10 +70,27 @@ struct Tract <: StateGeography end const TRACT_META = (tiger_name = "TRACT", description = "Census Tract") +struct Place <: StateGeography + year::Int +end +const PLACE_META = (tiger_name = "PLACE", description = "Place") + struct PrimarySecondaryRoads <: StateGeography year::Int end const PSROADS_META = (tiger_name = "PRISECROADS", description = "Primary and Secondary Roads") + +struct ConCity <: StateGeography + year::Int +end +const CONCITY_META = (tiger_name = "CONCITY", description = "Consolidated City") + +struct UNSD <: StateGeography + year::Int +end +const UNSD_META = (tiger_name = "UNSD", description = "Unified School District") + + # -------------------------------------------------------------------------------------------------- @@ -93,11 +120,16 @@ tiger_name(::Type{County}) = COUNTY_META.tiger_name tiger_name(::Type{ZipCode}) = ZIP_META.tiger_name tiger_name(::Type{UrbanArea}) = URBANAREA_META.tiger_name tiger_name(::Type{PrimaryRoads}) = PRIMARYROADS_META.tiger_name +tiger_name(::Type{Rails}) = RAILS_META.tiger_name tiger_name(::Type{CBSA}) = CBSA_META.tiger_name +tiger_name(::Type{CSA}) = CSA_META.tiger_name tiger_name(::Type{METDIV}) = METDIV_META.tiger_name tiger_name(::Type{CountySubdivision}) = COUSUB_META.tiger_name tiger_name(::Type{Tract}) = TRACT_META.tiger_name +tiger_name(::Type{Place}) = PLACE_META.tiger_name +tiger_name(::Type{ConCity}) = CONCITY_META.tiger_name +tiger_name(::Type{UNSD}) = UNSD_META.tiger_name tiger_name(::Type{PrimarySecondaryRoads}) = PSROADS_META.tiger_name tiger_name(::Type{AreaWater}) = AREAWATER_META.tiger_name @@ -112,11 +144,16 @@ description(::Type{County}) = COUNTY_META.description description(::Type{ZipCode}) = ZIP_META.description description(::Type{UrbanArea}) = URBANAREA_META.description description(::Type{PrimaryRoads}) = PRIMARYROADS_META.description +description(::Type{Rails}) = RAILS_META.description description(::Type{CBSA}) = CBSA_META.description +description(::Type{CSA}) = CSA_META.description description(::Type{METDIV}) = METDIV_META.description description(::Type{CountySubdivision}) = COUSUB_META.description description(::Type{Tract}) = TRACT_META.description +description(::Type{Place}) = PLACE_META.description +description(::Type{ConCity}) = CONCITY_META.description +description(::Type{UNSD}) = UNSD_META.description description(::Type{PrimarySecondaryRoads}) = PSROADS_META.description description(::Type{AreaWater}) = AREAWATER_META.description diff --git a/src/main.jl b/src/main.jl @@ -5,9 +5,15 @@ const GEOGRAPHY_TYPES = Dict( "zipcode" => ZipCode, "urbanarea" => UrbanArea, "primaryroads" => PrimaryRoads, + "cbsa" => CBSA, + "csa" => CSA, + "metrodivision" => METDIV, + "rails" => Rails, "cousub" => CountySubdivision, "tract" => Tract, + "place" => Place, + "consolidatedcity" => ConCity, "primarysecondaryroads" => PrimarySecondaryRoads, "areawater" => AreaWater, diff --git a/test/UnitTests/downloads.jl b/test/UnitTests/downloads.jl @@ -19,8 +19,42 @@ @test bytes2hex(SHA.sha256(read(county_file_download))) == "a344b72be48f2448df1ae1757098d94571b96556d3b9253cf9d6ee77bce8a0b4" - # -- still to test zcta520, urban area, cbsa - + tigerdownload("cbsa", 2024; output=test_dir, force=true) + cbsa_file_download = joinpath(test_dir, "tl_2024_us_cbsa.zip") + round(stat(cbsa_file_download).size / 1024, digits=2) # 34mb + @test bytes2hex(SHA.sha256(read(cbsa_file_download))) == + "7bd2cef06f0cd6cccc1aeeb10105095d543515c9535b8a89c9e8e7470615c8fa" + + tigerdownload("urbanarea", 2024; output=test_dir, force=true) + urbanarea_file_download = joinpath(test_dir, "tl_2024_us_uac20.zip") + round(stat(urbanarea_file_download).size / 1024, digits=2) # 72mb + @test bytes2hex(SHA.sha256(read(urbanarea_file_download))) == + "13f2f86cd31935387fa458022b73ad0433c39333c36ffb6efa8185694eba9d18" + + tigerdownload("zipcode", 2024; output=test_dir, force=true) + zipcode_file_download = joinpath(test_dir, "tl_2024_us_zcta520.zip") + round(stat(zipcode_file_download).size / 1024, digits=2) # 516mb + @test bytes2hex(SHA.sha256(read(zipcode_file_download))) == + "7331f68ada3d8eec3a87478c2a6ca68b7434762aa9d5a6cf2369d6ad90b3e03d" + + tigerdownload("metrodivision", 2024; output=test_dir, force=true) + metrodivision_file_download = joinpath(test_dir, "tl_2024_us_metdiv.zip") + round(stat(metrodivision_file_download).size / 1024, digits=2) # 516mb + @test bytes2hex(SHA.sha256(read(metrodivision_file_download))) == + "c7deea8ce439d3671a565e2e629bf23e1b6df5c714be3f9f72555728de3ab975" + + # -- rails + tigerdownload("rails", 2024; output=test_dir, force=true) + rails_file_download = joinpath(test_dir, "tl_2024_us_rails.zip") + round(stat(rails_file_download).size / 1024, digits=2) # 516mb + @test bytes2hex(SHA.sha256(read(rails_file_download))) == + "b0c19b22b1ee293062dba5dc05f57c2b6290c3df916aab8de62ff9344ebe9658" + + tigerdownload("primaryroads", 2024; output=test_dir, force=true) + primaryroads_file_download = joinpath(test_dir, "tl_2024_us_primaryroads.zip") + round(stat(primaryroads_file_download).size / 1024, digits=2) # 516mb + @test bytes2hex(SHA.sha256(read(primaryroads_file_download))) == + "d4f1b1cd981f440aee9980fdf991d4312a0bd03e7b2b2ae609a266bfc59ae786" end # -------------------------------------------------------------------------------------------------- @@ -58,6 +92,20 @@ @test bytes2hex(SHA.sha256(read(tract_file_download))) == "83f784b2042d0af55723baaac37b2b29840d1485ac233b3bb73d6af4ec7246eb" + # -- place + tigerdownload("place", 2024; state="27", county="", output=test_dir, force=true) + tract_file_download = joinpath(test_dir, "tl_2024_27_place.zip") + round(stat(tract_file_download).size / 1024, digits=2) + @test bytes2hex(SHA.sha256(read(tract_file_download))) == + "f03383a2522009c63daae5b73164ac565fc37470539d1fc79c057ed5dc31c9c3" + + # -- concity ... not all states are available + tigerdownload("consolidatedcity", 2024; state="20", county="", output=test_dir, force=true) + consolidatedcity_file_download = joinpath(test_dir, "tl_2024_20_concity.zip") + round(stat(consolidatedcity_file_download).size / 1024, digits=2) + @test bytes2hex(SHA.sha256(read(consolidatedcity_file_download))) == + "510ee4a9d1e2bcf0dc8b87fc3c97f66e7afafbd5e4f1c2996d024c14c2eb7ab4" + # -- roads tigerdownload("primarysecondaryroads", 2024; state="27", county="", output=test_dir, force=true) road_file_download = joinpath(test_dir, "tl_2024_27_prisecroads.zip")