TigerFetch.jl

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

julia.md (3865B)


      1 # Using TigerFetch from Julia
      2 
      3 The main entry point is the [`tigerdownload`](@ref) function.
      4 
      5 ## Installation
      6 
      7 `TigerFetch.jl` is registered in the [`loulouJL`](https://github.com/LouLouLibs/loulouJL) registry:
      8 
      9 ```julia
     10 using Pkg, LocalRegistry
     11 pkg"registry add https://github.com/LouLouLibs/loulouJL.git"
     12 Pkg.add("TigerFetch")
     13 ```
     14 
     15 Or install directly from GitHub:
     16 ```julia
     17 import Pkg; Pkg.add(url="https://github.com/louloulibs/TigerFetch.jl")
     18 ```
     19 
     20 ## Basic usage
     21 
     22 ```julia
     23 using TigerFetch
     24 
     25 # Download state boundaries (national file)
     26 tigerdownload("state")
     27 
     28 # Download county subdivisions for California
     29 tigerdownload("cousub"; state="CA")
     30 
     31 # Download census tracts for a specific state using FIPS code
     32 tigerdownload("tract"; state="27", output="/path/to/data")
     33 
     34 # Download area water for a specific county
     35 tigerdownload("areawater"; state="MN", county="Hennepin", output="tmp")
     36 
     37 # Force re-download of existing files
     38 tigerdownload("county"; output="tmp", force=true)
     39 ```
     40 
     41 ## Geography scopes
     42 
     43 Geographies are organized into three scopes that determine how files are downloaded:
     44 
     45 ### National scope
     46 A single file covers the entire US. The `state` and `county` arguments are ignored.
     47 
     48 ```julia
     49 tigerdownload("state")          # one file: tl_2024_us_state.zip
     50 tigerdownload("county")         # one file: tl_2024_us_county.zip
     51 tigerdownload("cbsa")           # Core Based Statistical Areas
     52 tigerdownload("urbanarea")      # Urban Areas
     53 tigerdownload("zipcode")        # ZIP Code Tabulation Areas
     54 tigerdownload("metrodivision")  # Metropolitan Divisions
     55 tigerdownload("primaryroads")   # Primary roads
     56 tigerdownload("rails")          # Railroads
     57 ```
     58 
     59 ### State scope
     60 One file per state. Omit `state` to download all states.
     61 
     62 ```julia
     63 tigerdownload("cousub"; state="IL")                # County subdivisions
     64 tigerdownload("tract"; state="CA")                 # Census tracts
     65 tigerdownload("place"; state="27")                 # Places (using FIPS)
     66 tigerdownload("primarysecondaryroads"; state="MN") # Primary & secondary roads
     67 tigerdownload("consolidatedcity"; state="KS")      # Consolidated cities
     68 ```
     69 
     70 ### County scope
     71 One file per county. Requires `state`; omit `county` to download all counties in the state.
     72 
     73 ```julia
     74 tigerdownload("areawater"; state="MN", county="Hennepin")  # Area hydrography
     75 tigerdownload("linearwater"; state="MI")                    # All MI counties
     76 tigerdownload("road"; state="MN", county="Hennepin")        # Roads
     77 ```
     78 
     79 ## State and county identifiers
     80 
     81 States can be specified by name, abbreviation, or FIPS code:
     82 ```julia
     83 tigerdownload("tract"; state="Minnesota")  # full name
     84 tigerdownload("tract"; state="MN")         # abbreviation
     85 tigerdownload("tract"; state="27")         # FIPS code
     86 ```
     87 
     88 Counties can be specified by name or FIPS code (common suffixes like "County" or "Parish" are stripped automatically):
     89 ```julia
     90 tigerdownload("road"; state="MN", county="Hennepin")        # name
     91 tigerdownload("road"; state="MN", county="Hennepin County")  # also works
     92 tigerdownload("road"; state="MN", county="053")              # FIPS code
     93 ```
     94 
     95 ## Options
     96 
     97 | Keyword | Type | Default | Description |
     98 |---------|------|---------|-------------|
     99 | `state` | `String` | `""` | State identifier |
    100 | `county` | `String` | `""` | County identifier (requires `state`) |
    101 | `output` | `String` | `pwd()` | Output directory |
    102 | `force` | `Bool` | `false` | Re-download existing files |
    103 | `verbose` | `Bool` | `false` | Print detailed progress |
    104 
    105 ## Working with downloaded files
    106 
    107 TigerFetch downloads ZIP archives containing shapefiles (`.shp`, `.dbf`, `.shx`, `.prj`, etc.). Use [Shapefile.jl](https://github.com/JuliaGeo/Shapefile.jl) to read them:
    108 
    109 ```julia
    110 using Shapefile, DataFrames
    111 df = Shapefile.Table("tl_2024_us_county.zip") |> DataFrame
    112 ```
    113 
    114 See the [demo](@ref "Drawing a simple map") for a complete mapping example with CairoMakie.