Skip to content

Instantly share code, notes, and snippets.

@gravitymonkey
Created October 11, 2011 17:05
Show Gist options
  • Save gravitymonkey/1278688 to your computer and use it in GitHub Desktop.
Save gravitymonkey/1278688 to your computer and use it in GitHub Desktop.
download all the 2010 Census Tracts, extract from shapefiles to WKT
#requires ogr2ogr installed on local system
states=( 01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56 )
for state in ${states[@]}
do
#grab the file from the census server, use curlies cuz the underscores mess us up
curl http://www2.census.gov/geo/tiger/TIGER2010/TRACT/2010/tl_2010_${state}_tract10.zip > $state.zip
done
for state in ${states[@]}
do
mkdir $state
#unzip it, delete the source zip
unzip -d $state $state.zip
rm $state.zip
#convert it to a WKT file and a summary file. the WKT will have all the poly points, summary will have a central lat/lon (useful!)
ogr2ogr -f "CSV" "$state.wkt.csv" $state/tl_2010_${state}_tract10.shp -lco "GEOMETRY=AS_WKT" -lco "LINEFORMAT=CRLF" -lco "SEPARATOR=SEMICOLON"
ogr2ogr -f "CSV" "$state.summary.csv" $state/tl_2010_${state}_tract10.shp
#cleanup
rm -rf $state
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment