Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add counties #21

Open
wants to merge 4 commits into
base: counties
Choose a base branch
from
Open

Add counties #21

wants to merge 4 commits into from

Conversation

owenam
Copy link
Contributor

@owenam owenam commented Mar 27, 2017

This adds name and FIPS data for US counties (and county equivalents like parishes), and associates them with the appropriate states. County data is pulled from the Census' 2010 TIGER data, http://www2.census.gov/geo/tiger/TIGER2010/COUNTY/2010/tl_2010_us_county10.zip.

My motivation was to have this data available to support "within county" calls to the Census API for smaller geographies like tracts and block groups. I expect that the most common use case will be to get the list of county FIPS codes for all counties in a given state.

County data is linked to states and can be accessed in a few different ways:

us.counties.COUNTIES  # All US counties
us.states.MN.counties  # Counties in Minnesota
us.counties.lookup('27')  # Lookup by state FIPS code
us.counties.lookup('27053')  # Lookup by combined state+county FIPS code
us.counties.lookup('Hennepin')  # Lookup by short name

Note that all county lookups return a list.

len(us.counties.lookup('Washington'))  # 31 states have a county named Washington
len(us.counties.lookup('Hennepin'))  #  1 state has a county named Hennepin
len(us.counties.lookup('27053'))  # Returns 1-element list for consistency
us.counties.lookup('27053')[0].state  # Counties are linked back to states

I've left in some bits that might not be necessary, such as the code in load_county_data.py and county_schema.sql for loading the county data into sqlite.

Finally there may be better ways to handle the lookups and linking to states, I'm happy to discuss!

@jcarbaugh
Copy link
Member

@owenam I was quite hesitant to add counties when previously proposed, but this looks really, really great. Based on a quick look, I think the API makes a lot of sense. Give me a couple days to play around with it and see if I have any feedback. Ping me if you don't hear anything by the end of the week 🙂

Thanks!

@jcarbaugh jcarbaugh self-assigned this Mar 27, 2017
@jcarbaugh jcarbaugh changed the base branch from master to counties March 27, 2017 21:52
@owenam
Copy link
Contributor Author

owenam commented Mar 28, 2017

I was on the fence as well, since its quite a bit more data! But this felt like a better alternative than repeatedly hitting the SF1 API just to get county codes, or repeatedly fetching and reading the TIGER shapefiles.

The part I feel the least certain about is probably the handling of the state<->county linking in __init__.py — I haven't had a reason to do anything like that before so I'm not sure if there are better approaches.

@owenam
Copy link
Contributor Author

owenam commented Apr 3, 2017

@jcarbaugh just checking in — what are your thoughts on this?

@jbrockmendel
Copy link

This feature would be great. A few comments and questions.

Counties/Parishes/Boroughs change more often than states. And Virginia FIPS codes... How does this stay up to date? Should there be point-in-time lookup?

How to define __repr__ isn't entirely obvious. "<County: Autuga>" or "<County: Autauga, AL>"? "<County: Denali Borough>" or "<Borough: Denali>". That said, the way it is defined now looks perfectly workable.

Should counties.lookup support counties.lookup("DeKalb, GA")?

In states.lookup, passing bytes raises TypeError: expected unicode, got str. As long as the input is ascii, it would be nice to just convert it on the front-end.

There are going to be a lot of corner cases with fuzzy matching. How robustly should those be supported? Will jellyfish.metaphone match "St Francis, AR" with "St. Francis, AR"? Hyphenation may also be a sticking point.

To reiterate, this is a great feature and I'll be happy to help with any of the above.

@sglyon
Copy link

sglyon commented Dec 5, 2017

County support would be fantastic. Anything an "outsider" can do to help move this along?

@eedduuar
Copy link

+1

@marcin-osowski
Copy link

Hi, any chance to include this?

I'm up for fixing whatever needs more work in this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants