Created
April 8, 2011 22:38
-
-
Save ashaw/910871 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'net/ftp' | |
def get_roads | |
`cd shapes` | |
ftp = Net::FTP.new('ftp2.census.gov') | |
ftp.login | |
files = ftp.chdir("/geo/tiger/TIGER2010/ROADS") | |
files = ftp.list.collect {|r| r.match(/tl.*$/)[0]} | |
files.each do |file| | |
ftp.getbinaryfile(file) | |
p "getting #{file}" | |
end | |
ftp.close | |
end | |
def unzip_roads | |
files = Dir.glob("shapes/*.zip") | |
files.each do |file| | |
`unzip #{file}` | |
end | |
end | |
def db_schema | |
file = "roads_init.sql" | |
`touch #{file}` | |
cmd = <<-BASH | |
echo "set search_path to postgis;" > #{file}; \ | |
cat $(PG_CONFIG --sharedir)/contrib/postgis-1.5/postgis.sql >> #{file}; \ | |
cat $(PG_CONFIG --sharedir)/contrib/postgis-1.5/spatial_ref_sys.sql >> #{file} | |
BASH | |
`#{cmd}` | |
end | |
def load_db_schema | |
`cat roads_init.sql | psql -d roads --username propublica` | |
end | |
def road_to_pg | |
files = Dir.glob("*.shp") | |
`shp2pgsql -c -D -s 4326 -I #{files[0]} > roads.sql` | |
files.shift | |
files.each do |file| | |
`shp2pgsql -a #{file}` | |
end | |
end | |
def load_shapes | |
`psql -d roads -f roads.sql` | |
end | |
to_do = ARGV[0] | |
send(to_do) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment