tyrauber / census_api

A Ruby Gem for querying the US Census Bureau API
MIT License
30 stars 9 forks source link

Allow direct access of smaller geographies through IDs #16

Closed beechnut closed 10 years ago

beechnut commented 10 years ago

Let's say I need to access data about blockgroups, and I know the full FIPS codes of the individual blockgroups. I should be able to request:

@c.find(fields: ['B17005_022M','B17005_023M'], of: { blockgroups: ['250250701012','250250701024'] })

I think that the Census API itself should be able to parse blockgroup FIPS, but it doesn't, so we can hack our way through it for now.

beechnut commented 10 years ago

If we a have multiple blockgroups across different tracts, it would make sense to batch the requests as much as possible to keep the rate down.

If I have the following blockgroup IDs:

["25 025 070101 1"
 "25 025 070101 2"
 "25 025 070102 1"
 "25 025 070102 2"
 "25 025 070102 3"]

The requests should be:

# Request 1
'for=block+group=1,2&in:state:25+county:025+tract:070101'

# Request 2
'for=block+group=1,2,3&in:state:25+county:025+tract:070102'

and return an single results object that pretends like it was one request.

tyrauber commented 10 years ago

Unless I am misunderstanding, this is already possible:

@client.where({ fields: 'B00001_001E', level: 'BG', within: 'STATE:02+COUNTY:170+TRACT:000101' })

The above will give you all blockgroups within the supplied tract. If you only want specific blockgroups, you can do the following:

@client.where({ fields: 'B00001_001E', level: 'BG:1,2,3', within: 'STATE:02+COUNTY:170+TRACT:000101' })