Skip to content

Instantly share code, notes, and snippets.

@jatorre
Created November 27, 2012 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jatorre/4154502 to your computer and use it in GitHub Desktop.
Save jatorre/4154502 to your computer and use it in GitHub Desktop.
Combine multiple Census files into single shpefile using PostGIS
mkdir tmpfolder;
cd tmpfolder;
wget "http://www2.census.gov/geo/tiger/TIGER2012/TRACT/tl_2012_01_tract.zip";
unzip tl_2012_01_tract.zip;
shp2pgsql -s4326 -p tl_2012_01_tract.shp census | psql -hlocalhost -Upostgres -dcensus;
rm -rf tl_2012_01_tract.*;
for i in {1..9} :;
do
wget "http://www2.census.gov/geo/tiger/TIGER2012/TRACT/tl_2012_0${i}_tract.zip";
unzip tl_2012_0${i}_tract.zip
shp2pgsql -s4326 -a tl_2012_0${i}_tract.shp census | psql -hlocalhost -Upostgres -dcensus;
sleep 1;
done;
for i in {10..78} :;
do
wget "http://www2.census.gov/geo/tiger/TIGER2012/TRACT/tl_2012_${i}_tract.zip";
unzip tl_2012_${i}_tract.zip
shp2pgsql -s4326 -a tl_2012_${i}_tract.shp census | psql -hlocalhost -Upostgres -dcensus;
sleep 1;
done;
cd ..;
rm -rf tmpfolder;
pgsql2shp -ftl_2012 -hlocalhost -upostgres census census;
tl_2012.zip tl_2012.*;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment