Concensus is a gem for reading the United States Census Bureau's TIGER/Line Shapefiles.
It uses the georuby gem to convert the shapefiles, which leaves you with access to all of the methods in the georuby API.
gem 'concensus'
Concensus::Place.find("CA", "Berkeley")
=> #<Concensus::Place>
Concensus::Place.find_all("CA")
=> [#<Concensus::Place>, #<Concensus::Place>, etc...]
Concensus::configuration.year = 2011
=> all subsequent requests will be for 2011
Concensus::Place.find("NY", "New York")
=> 2011 Boundaries for New York City
Concensus::configuration.year = 2010
california = Concensus::State.find("CA")
california.geometry
=> #<GeoRuby::SimpleFeatures::MultiPolygon>
california.geometry.to_array
=> [[[-119.000932, 33.535895], [-119.000932, 33.535823], [-118.997845, 33.534199], [-118.994453, 33.532711], [-118.992796, 33.531849], [-118.990046, 33.530288999999996], [-118.986199, 33.527425], ...], ...]
california.geometry.to_array[0]
=> [[-119.000932, 33.535895], [-119.000932, 33.535823], ... ]
<tr>
<th>Concensus::County</th>
<td></td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::Place</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::School::Elementary</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::School::Secondary</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::School::Unified</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::State</th>
<td></td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::StateLegislative::Upper</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::StateLegislative::Lower</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Concensus::Zipcode</th>
<td></td>
<td>✓</td>
</tr>
2011 | 2010 | |
---|---|---|
Concensus::Congressional | ✓ |
http://rubydoc.info/github/adamjacobbecker/concensus/
Some of the .zip files downloaded are quite large, so this gem requires temporary storage to unzip and cache the downloaded files. By default, we store these in ~/.concensus/tmp/
.
If you're using Rails, you'll probably want to create an initializer with Concensus.configure { |c| c.tmp_dir = "#{Rails.root}/tmp/concensus/" }
. This way, you can use Concensus with the (very temporary) writable storage on Heroku.
- Add more geographic areas, we only have a small bit of what's available.
- Add support for storing downloaded and uncompressed .zips on S3. (Heroku has no persistent writable file storage.)
Support development by sending links to siiick house mixes: @AdamJacobBecker