TigerFetch.jl

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

downloads.jl (6735B)


      1 # ABOUTME: Download tests for all TIGER/Line geography types (national, state, county)
      2 # ABOUTME: Uses hybrid validation (size/structure checks) to verify downloaded Census shapefiles
      3 
      4 # Include validation utilities
      5 include("../TestRoutines/validation.jl")
      6 
      7 @testset "Download Tests" begin
      8 
      9 
     10 # --------------------------------------------------------------------------------------------------
     11     @testset "National Level Downloads" begin
     12 
     13     test_dir = mktempdir()
     14     
     15     # Download the states shapefiles
     16     tigerdownload("state", 2024; state="MN", county="", output=test_dir, force=true)
     17     state_file_download = joinpath(test_dir, "tl_2024_us_state.zip")
     18     
     19     @test validate_census_file_integrity(state_file_download, "state", TOLERANCE_PARAMS["state"])
     20 
     21     tigerdownload("county", 2024; state="MN", county="Hennepin", output=test_dir, force=true)
     22     county_file_download = joinpath(test_dir, "tl_2024_us_county.zip")
     23     
     24     @test validate_census_file_integrity(county_file_download, "county", TOLERANCE_PARAMS["county"])
     25 
     26     tigerdownload("cbsa", 2024; output=test_dir, force=true)
     27     cbsa_file_download = joinpath(test_dir, "tl_2024_us_cbsa.zip")
     28     
     29     @test validate_census_file_integrity(cbsa_file_download, "cbsa", TOLERANCE_PARAMS["cbsa"])
     30 
     31     tigerdownload("urbanarea", 2024; output=test_dir, force=true)
     32     urbanarea_file_download = joinpath(test_dir, "tl_2024_us_uac20.zip")
     33     
     34     @test validate_census_file_integrity(urbanarea_file_download, "urbanarea", TOLERANCE_PARAMS["urbanarea"])
     35 
     36     tigerdownload("zipcode", 2024; output=test_dir, force=true)
     37     zipcode_file_download = joinpath(test_dir, "tl_2024_us_zcta520.zip")
     38     
     39     @test validate_census_file_integrity(zipcode_file_download, "zipcode", TOLERANCE_PARAMS["zipcode"])
     40 
     41     tigerdownload("metrodivision", 2024; output=test_dir, force=true)
     42     metrodivision_file_download = joinpath(test_dir, "tl_2024_us_metdiv.zip")
     43     
     44     @test validate_census_file_integrity(metrodivision_file_download, "metrodivision", TOLERANCE_PARAMS["metrodivision"])
     45 
     46     # -- rails
     47     tigerdownload("rails", 2024; output=test_dir, force=true)
     48     rails_file_download = joinpath(test_dir, "tl_2024_us_rails.zip")
     49     
     50     @test validate_census_file_integrity(rails_file_download, "rails", TOLERANCE_PARAMS["rails"])
     51 
     52     tigerdownload("primaryroads", 2024; output=test_dir, force=true)
     53     primaryroads_file_download = joinpath(test_dir, "tl_2024_us_primaryroads.zip")
     54     
     55     @test validate_census_file_integrity(primaryroads_file_download, "primaryroads", TOLERANCE_PARAMS["primaryroads"])
     56 
     57     end
     58 # --------------------------------------------------------------------------------------------------
     59 
     60 
     61 # --------------------------------------------------------------------------------------------------
     62     @testset "State Level Downloads" begin
     63 
     64     test_dir = mktempdir()
     65     
     66     # Download the county subdivisions shapefiles
     67     tigerdownload("cousub", 2024; state="MN", county="", output=test_dir, force=true)
     68     cousub_file_download = joinpath(test_dir, "tl_2024_27_cousub.zip")
     69     
     70     @test validate_census_file_integrity(cousub_file_download, "cousub", TOLERANCE_PARAMS["cousub"])
     71 
     72     # for all the states ... 
     73     tigerdownload("cousub", 2024; output=test_dir, force=false)
     74     cousub_file_list = [ "tl_2024_$(x[2])_cousub.zip" 
     75         for x in TigerFetch.get_state_list() ]
     76     cousub_file_list = joinpath.(test_dir, cousub_file_list)
     77     @test !all(isfile.(cousub_file_list)) # there should be one missing file
     78     @test all(.!isfile.(filter(contains("tl_2024_74_cousub.zip"), cousub_file_list))) # there should be one missing file
     79 
     80     cousub_file_download = filter(contains("tl_2024_28_cousub.zip"), cousub_file_list)[1]
     81     
     82     @test validate_census_file_integrity(cousub_file_download, "cousub", TOLERANCE_PARAMS["cousub"])
     83 
     84     # -- tracts
     85     tigerdownload("tract", 2024; state="27", county="", output=test_dir, force=true)
     86     tract_file_download = joinpath(test_dir, "tl_2024_27_tract.zip")
     87     
     88     @test validate_census_file_integrity(tract_file_download, "tract", TOLERANCE_PARAMS["tract"])
     89 
     90     # -- place
     91     tigerdownload("place", 2024; state="27", county="", output=test_dir, force=true)
     92     place_file_download = joinpath(test_dir, "tl_2024_27_place.zip")
     93     
     94     @test validate_census_file_integrity(place_file_download, "place", TOLERANCE_PARAMS["place"])
     95 
     96     # -- concity ... not all states are available
     97     tigerdownload("consolidatedcity", 2024; state="20", county="", output=test_dir, force=true)
     98     consolidatedcity_file_download = joinpath(test_dir, "tl_2024_20_concity.zip")
     99     
    100     @test validate_census_file_integrity(consolidatedcity_file_download, "consolidatedcity", TOLERANCE_PARAMS["consolidatedcity"])
    101 
    102     # -- roads
    103     tigerdownload("primarysecondaryroads", 2024; state="27", county="", output=test_dir, force=true)
    104     road_file_download = joinpath(test_dir, "tl_2024_27_prisecroads.zip")
    105     
    106     @test validate_census_file_integrity(road_file_download, "primarysecondaryroads", TOLERANCE_PARAMS["primarysecondaryroads"])
    107 
    108 
    109 
    110     end
    111 # --------------------------------------------------------------------------------------------------
    112 
    113 
    114 # --------------------------------------------------------------------------------------------------
    115     @testset "County Level Downloads" begin
    116 
    117     test_dir = mktempdir()
    118     
    119     # Download the areawater shapefiles
    120     tigerdownload("areawater", 2024; state="MN", county="Hennepin", output=test_dir, force=true)
    121     areawater_file_download = joinpath(test_dir, "tl_2024_27053_areawater.zip")
    122     
    123     @test validate_census_file_integrity(areawater_file_download, "areawater", TOLERANCE_PARAMS["areawater"])
    124 
    125     # Download the linear water  shapefiles for all of Michigan
    126     tigerdownload("linearwater", 2024; state="MI", output=test_dir, force=true)
    127     linearwater_file_list = [ "tl_2024_$(x[2])$(x[3])_linearwater.zip" 
    128         for x in TigerFetch.get_county_list("MI") ]
    129     linearwater_file_list = joinpath.(test_dir, linearwater_file_list)
    130     @test all(isfile.(linearwater_file_list)) # test that all the files are there
    131 
    132     linearwater_file_download = filter(contains("tl_2024_26089_linearwater.zip"), linearwater_file_list)[1]
    133     
    134     @test validate_census_file_integrity(linearwater_file_download, "linearwater", TOLERANCE_PARAMS["linearwater"])
    135 
    136     # roads
    137     tigerdownload("road", 2024; state="MN", county="Hennepin", output=test_dir, force=true)
    138     roads_file_download = joinpath(test_dir, "tl_2024_27053_roads.zip")
    139     
    140     @test validate_census_file_integrity(roads_file_download, "road", TOLERANCE_PARAMS["road"])
    141 
    142 
    143 
    144     end
    145 # --------------------------------------------------------------------------------------------------
    146 
    147 
    148 end