TigerFetch.jl

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

commit 44e6e588a4b1b1596b8aec38d2e3dda6032132ed
parent b4f0d3fe2688761fbce881deaf361b724b946dd5
Author: Erik Loualiche <eloualic@umn.edu>
Date:   Sun, 23 Feb 2025 09:47:01 -0600

We have something working...

so the downloads are ok inside and outside of julia

Diffstat:
MProject.toml | 10+++++++++-
Adeps/build.jl | 2++
Msrc/cli.jl | 17+++++++++++------
Msrc/reference.jl | 23+++++++++++++++++++----
4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/Project.toml b/Project.toml @@ -1,9 +1,17 @@ name = "TigerFetch" uuid = "59408d0a-a903-460e-b817-a5586a16527e" authors = ["Erik Loualiche"] -version = "1.0.0-DEV" +version = "0.1.0" + +[deps] +Comonicon = "863f3e99-da2a-4334-8734-de3dacbe5542" +Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [compat] +Comonicon = "1.0.8" +Downloads = "1.6.0" +Pkg = "1.11.0" julia = "1.6.7" [extras] diff --git a/deps/build.jl b/deps/build.jl @@ -0,0 +1,2 @@ +# build.jl +using TigerFetch; TigerFetch.comonicon_install() diff --git a/src/cli.jl b/src/cli.jl @@ -8,9 +8,15 @@ const GEOGRAPHY_TYPES = Dict( ) """ -Download TIGER/Line shapefiles. + tigerfetch(type, year) -# Arguments +Download shapefiles for US geography from the Census Tiger ftp server. + +# Intro + + + +# Args - `type`: Geography type (state, county, cousub, tract) - `year`: Data year (default: 2024) @@ -23,10 +29,9 @@ Download TIGER/Line shapefiles. - `--force`: Override existing files # Examples -tigerfetch state 2024 -tigerfetch cousub 2024 --state CA -tigerfetch tract 2024 --state "New York" - +tigerfetch state +tigerfetch cousub --state IL +tigerfetch areawater --state "Minnesota" # 10,000 lakes """ @main function tigerfetch( type::String, year::Int=2024; diff --git a/src/reference.jl b/src/reference.jl @@ -49,7 +49,7 @@ function get_county_list(state=nothing)::Vector{Vector{AbstractString}} return county_list elseif !isnothing(tryparse(Int, state)) # then its the fips return unique(filter(l -> l[2] == state, county_list)) - else # then its the abbreviation state name + else # then its the abbreviation state name return unique(filter(l -> l[1] == state, county_list)) end @@ -75,12 +75,27 @@ end function find_county(identifier::String, state_fips::String)::Union{Vector{String}, Nothing} + counties = get_county_list(state_fips) - # Try to match based on any identifier in the county vector - matched_county = findfirst(county -> - any(uppercase(id) == uppercase(identifier) for id in county), + COUNTY_SUFFIXES = ["COUNTY", "MUNICIPIO", "BOROUGH", "PARISH", "MUNICIPALITY", "CENSUS AREA"] + clean_county_name(name::String) = replace(uppercase(strip(name)), + Regex("\\s+(" * join(COUNTY_SUFFIXES, "|") * ")\$") => "") + clean_identifier = clean_county_name(uppercase(identifier)) + + # Try to match based on any identifier in the county vector only on fips and name to avoid false positive + matched_county = findfirst( + county -> any(clean_county_name(id) == clean_identifier for id in county[[3,4]]), counties) return isnothing(matched_county) ? nothing : counties[matched_county] end + + + + + + + + +