Created
December 6, 2012 17:20
-
-
Save thejefflarson/4226247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'simpler_tiles' | |
breaks = [0.05, 0.15, 0.30, 0.45, 0.60] | |
cbreaks = [0.40, 0.50, 0.60, 0.70, 0.80] | |
colors = [[236, 231, 242], [166, 189, 219], [116, 169, 207], [54, 144, 192], [5, 112, 176], [3, 78, 123]] | |
def color(color) | |
sprintf("#%2x%2x%2x", *color).gsub(" ", "0") | |
end | |
map = SimplerTiles::Map.new do |m| | |
m.srs = "EPSG:102003" | |
m.set_bounds -2356113.743199, -1337508.077280, 2258243.997100, 1565781.660000 | |
m.width = 630 | |
m.height = 400 | |
m.layer '10m-ocean/10m_ocean.shp' do |l| | |
l.query 'select * from "10m_ocean"' do |q| | |
q.styles 'fill' => '#eaeaea', | |
'seamless' => 'true', | |
"line-join" => 'round' | |
end | |
end | |
m.layer 'us.shp' do |l| | |
l.query 'select * from "us"' do |q| | |
q.styles 'stroke' => '#888888', | |
'line-join' => 'round', | |
'weight' => '0.2' | |
end | |
end | |
m.layer '10m-lakes/ne_10m_lakes.shp' do |l| | |
l.query 'select * from "ne_10m_lakes"' do |q| | |
q.styles 'fill' => '#eaeaea', | |
'seamless' => 'true', | |
"line-join" => 'round' | |
end | |
end | |
end | |
File.open("images/background.png", 'w+') {|f| f.write map.to_png } | |
(1890..2010).step(10).each do |epoch| | |
p epoch | |
map = SimplerTiles::Map.new do |m| | |
m.srs = "EPSG:102003" | |
m.set_bounds -2356113.743199, -1337508.077280, 2258243.997100, 1565781.660000 | |
m.width = 630 | |
m.height = 400 | |
m.layer 'PG:dbname=migration' do |l| | |
breaks.each_with_index do |brk, i| | |
l.query "SELECT * FROM counties where black::float / total > #{brk} and total > 100 and epoch = #{epoch}" do |q| | |
q.styles "seamless" => 'true', | |
"fill" => color(colors[i]), | |
"line-join" => 'round' | |
end | |
end | |
end | |
end | |
File.open("images/#{epoch}.png", 'w+') {|f| f.write map.to_png } | |
p epoch | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment