]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Added a new script, download_data, to aid in the retrieval of the census data.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 7 Oct 2009 15:06:05 +0000 (11:06 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 7 Oct 2009 15:06:05 +0000 (11:06 -0400)
Moved the 'all lines' data retrieval out of the makefile and in to the new script (currently: D.C., MD, PA only).

bin/download_data [new file with mode: 0755]
makefile

diff --git a/bin/download_data b/bin/download_data
new file mode 100755 (executable)
index 0000000..2497a79
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+
+"""
+Download any necessary data from TIGER and Summary File 1.
+"""
+
+import os
+import site
+import sys
+
+# Basically, add '../src' to our path.
+# Needed for the imports that follow.
+site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + '/../src')
+
+import Data
+from Data import State, County
+
+
+dc = State(11, 'District of Columbia')
+md = State(24, 'Maryland')
+ny = State(36, 'New York')
+pa = State(42, 'Pennsylvania')
+va = State(51, 'Virginia')
+
+# Washington D.C.
+dc.add_county(1, 'District of Columbia', True)
+
+# Maryland
+md.add_county(1, 'Allegany')
+md.add_county(3, 'Anne Arundel')
+md.add_county(5, 'Baltimore')
+md.add_county(510, 'Baltimore city', True)
+md.add_county(9, 'Calvert')
+md.add_county(11, 'Caroline')
+md.add_county(13, 'Carroll')
+md.add_county(15, 'Cecil')
+md.add_county(17, 'Charles')
+md.add_county(19, 'Dorchester')
+md.add_county(21, 'Frederick')
+md.add_county(23, 'Garrett')
+md.add_county(25, 'Harford')
+md.add_county(27, 'Howard')
+md.add_county(29, 'Kent')
+md.add_county(31, 'Montgomery')
+md.add_county(33, 'Prince Georges')
+md.add_county(35, 'Queen Annes')
+md.add_county(37, 'St Marys')
+md.add_county(39, 'Somerset')
+md.add_county(41, 'Talbot')
+md.add_county(43, 'Washington')
+md.add_county(45, 'Wicomico')
+md.add_county(47, 'Worcester')
+
+# Pennsylvania
+pa.add_county(1, 'Adams')
+pa.add_county(3, 'Allegheny')
+pa.add_county(5, 'Armstrong')
+pa.add_county(7, 'Beaver')
+pa.add_county(9, 'Bedford')
+pa.add_county(11, 'Berks')
+pa.add_county(13, 'Blair')
+pa.add_county(15, 'Bradford')
+pa.add_county(17, 'Bucks')
+pa.add_county(19, 'Butler')
+pa.add_county(21, 'Cambria')
+pa.add_county(23, 'Cameron')
+pa.add_county(25, 'Carbon')
+pa.add_county(27, 'Centre')
+pa.add_county(29, 'Chester')
+pa.add_county(31, 'Clarion')
+pa.add_county(33, 'Clearfield')
+pa.add_county(35, 'Clinton')
+pa.add_county(37, 'Columbia')
+pa.add_county(39, 'Crawford')
+pa.add_county(41, 'Cumberland')
+pa.add_county(43, 'Dauphin')
+pa.add_county(45, 'Delaware')
+pa.add_county(47, 'Elk')
+pa.add_county(49, 'Erie')
+pa.add_county(51, 'Fayette')
+pa.add_county(53, 'Forest')
+pa.add_county(55, 'Franklin')
+pa.add_county(57, 'Fulton')
+pa.add_county(59, 'Greene')
+pa.add_county(61, 'Huntingdon')
+pa.add_county(63, 'Indiana')
+pa.add_county(65, 'Jefferson')
+pa.add_county(67, 'Juniata')
+pa.add_county(69, 'Lackawanna')
+pa.add_county(71, 'Lancaster')
+pa.add_county(73, 'Lawrence')
+pa.add_county(75, 'Lebanon')
+pa.add_county(77, 'Lehigh')
+pa.add_county(79, 'Luzerne')
+pa.add_county(81, 'Lycoming')
+pa.add_county(83, 'McKean')
+pa.add_county(85, 'Mercer')
+pa.add_county(87, 'Mifflin')
+pa.add_county(89, 'Monroe')
+pa.add_county(91, 'Montgomery')
+pa.add_county(93, 'Montour')
+pa.add_county(95, 'Northampton')
+pa.add_county(97, 'Northumberland')
+pa.add_county(99, 'Perry')
+pa.add_county(101, 'Philadelphia')
+pa.add_county(103, 'Pike')
+pa.add_county(105, 'Potter')
+pa.add_county(107, 'Schuylkill')
+pa.add_county(109, 'Snyder')
+pa.add_county(111, 'Somerset')
+pa.add_county(113, 'Sullivan')
+pa.add_county(115, 'Susquehanna')
+pa.add_county(117, 'Tioga')
+pa.add_county(119, 'Union')
+pa.add_county(121, 'Venango')
+pa.add_county(123, 'Warren')
+pa.add_county(125, 'Washington')
+pa.add_county(127, 'Wayne')
+pa.add_county(129, 'Westmoreland')
+pa.add_county(131, 'Wyoming')
+pa.add_county(133, 'York')
+
+states = [dc, md, ny, pa, va]
+
+Data.download_lines(states)
index d32c27f81ef2467a6b513e4fbb4876b494c3a101..432a515ded626f70a6102692e50fdf7731e7a912 100644 (file)
--- a/makefile
+++ b/makefile
@@ -19,39 +19,6 @@ VA_BLOCKS_URL=$(VA_ROOT)/tl_2009_51_tabblock00.zip
 PA_BLOCKS_URL=$(PA_ROOT)/tl_2009_42_tabblock00.zip
 NY_BLOCKS_URL=$(NY_ROOT)/tl_2009_36_tabblock00.zip
 
-# URLs for the DC county all-lines shapefiles.
-# D.C. just has one Census county.
-DC_LINES_URL=$(DC_ROOT)/11001_District_of_Columbia/tl_2009_11001_edges.zip
-
-# This is where it gets ugly.
-#
-# URLs for the MD county all-lines shapefiles.
-ALLEGANY_LINES_URL=$(MD_ROOT)/24001_Allegany_County/tl_2009_24001_edges.zip
-ANNE_ARUNDEL_LINES_URL=$(MD_ROOT)/24003_Anne_Arundel_County/tl_2009_24003_edges.zip
-BALTIMORE_CO_LINES_URL=$(MD_ROOT)/24005_Baltimore_County/tl_2009_24005_edges.zip
-BALTIMORE_CI_LINES_URL=$(MD_ROOT)/24510_Baltimore_city/tl_2009_24510_edges.zip
-CALVERT_LINES_URL=$(MD_ROOT)/24009_Calvert_County/tl_2009_24009_edges.zip
-CAROLINE_LINES_URL=$(MD_ROOT)/24011_Caroline_County/tl_2009_24011_edges.zip
-CARROLL_LINES_URL=$(MD_ROOT)/24013_Carroll_County/tl_2009_24013_edges.zip
-CECIL_LINES_URL=$(MD_ROOT)/24015_Cecil_County/tl_2009_24015_edges.zip
-CHARLES_LINES_URL=$(MD_ROOT)/24017_Charles_County/tl_2009_24017_edges.zip
-DORCHESTER_LINES_URL=$(MD_ROOT)/24019_Dorchester_County/tl_2009_24019_edges.zip
-FREDERICK_LINES_URL=$(MD_ROOT)/24021_Frederick_County/tl_2009_24021_edges.zip
-GARRETT_LINES_URL=$(MD_ROOT)/24023_Garrett_County/tl_2009_24023_edges.zip
-HARFORD_LINES_URL=$(MD_ROOT)/24025_Harford_County/tl_2009_24025_edges.zip
-HOWARD_LINES_URL=$(MD_ROOT)/24027_Howard_County/tl_2009_24027_edges.zip
-KENT_LINES_URL=$(MD_ROOT)/24029_Kent_County/tl_2009_24029_edges.zip
-MONTGOMERY_LINES_URL=$(MD_ROOT)/24031_Montgomery_County/tl_2009_24031_edges.zip
-PRINCE_GEORGES_LINES_URL=$(MD_ROOT)/24033_Prince_Georges_County/tl_2009_24033_edges.zip
-QUEEN_ANNES_LINES_URL=$(MD_ROOT)/24035_Queen_Annes_County/tl_2009_24035_edges.zip
-ST_MARYS_LINES_URL=$(MD_ROOT)/24037_St_Marys_County/tl_2009_24037_edges.zip
-SOMERSET_LINES_URL=$(MD_ROOT)/24039_Somerset_County/tl_2009_24039_edges.zip
-TALBOT_LINES_URL=$(MD_ROOT)/24041_Talbot_County/tl_2009_24041_edges.zip
-WASHINGTON_LINES_URL=$(MD_ROOT)/24043_Washington_County/tl_2009_24043_edges.zip
-WICOMICO_LINES_URL=$(MD_ROOT)/24045_Wicomico_County/tl_2009_24045_edges.zip
-WORCESTER_LINES_URL=$(MD_ROOT)/24047_Worcester_County/tl_2009_24047_edges.zip
-
-
 # Starting with PostGIS 1.4.0, these paths are calculated at install
 # time using the pg_config utility. Rather than try to guess where
 # PostGIS will wind up installed, we can just check the output of
@@ -133,234 +100,8 @@ ny_blocks:
        fi;
 
 
-tiger_lines: dc_lines md_lines
-
-dc_lines:
-       mkdir -p data/census2000/dc/lines
-       if [ ! -f data/census2000/dc/lines/tl_2009_11001_edges.shp ];   \
-       then                                                            \
-               wget -O dclines.zip $(DC_LINES_URL);                    \
-               unzip dclines.zip -d ./data/census2000/dc/lines;        \
-               rm dclines.zip;                                         \
-       fi;
-
-md_lines: allegany_lines anne_arundel_lines baltimore_co_lines baltimore_ci_lines calvert_lines caroline_lines carroll_lines cecil_lines charles_lines dorchester_lines frederick_lines garrett_lines harford_lines howard_lines kent_lines montgomery_lines prince_georges_lines queen_annes_lines st_marys_lines somerset_lines talbot_lines washington_lines wicomico_lines worcester_lines
-
-allegany_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24001_edges.shp ];  \
-       then                                                                 \
-               wget -O alleganylines.zip $(ALLEGANY_LINES_URL);             \
-               unzip alleganylines.zip -d ./data/census2000/maryland/lines; \
-               rm alleganylines.zip;                                        \
-       fi;
-
-anne_arundel_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24003_edges.shp ];  \
-       then                                                                 \
-               wget -O aalines.zip $(ANNE_ARUNDEL_LINES_URL);               \
-               unzip aalines.zip -d ./data/census2000/maryland/lines;       \
-               rm aalines.zip;                                              \
-       fi;
-
-baltimore_co_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24005_edges.shp ];  \
-       then                                                                 \
-               wget -O bcolines.zip $(BALTIMORE_CO_LINES_URL);              \
-               unzip bcolines.zip -d ./data/census2000/maryland/lines;      \
-               rm bcolines.zip;                                             \
-       fi;
-
-baltimore_ci_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24510_edges.shp ];  \
-       then                                                                 \
-               wget -O bcilines.zip $(BALTIMORE_CI_LINES_URL);              \
-               unzip bcilines.zip -d ./data/census2000/maryland/lines;      \
-               rm bcilines.zip;                                             \
-       fi;
-
-calvert_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24009_edges.shp ];  \
-       then                                                                 \
-               wget -O calvertlines.zip $(CALVERT_LINES_URL);               \
-               unzip calvertlines.zip -d ./data/census2000/maryland/lines;  \
-               rm calvertlines.zip;                                         \
-       fi;
-
-caroline_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24011_edges.shp ];  \
-       then                                                                 \
-               wget -O carolinelines.zip $(CAROLINE_LINES_URL);             \
-               unzip carolinelines.zip -d ./data/census2000/maryland/lines; \
-               rm carolinelines.zip;                                        \
-       fi;
-
-carroll_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24013_edges.shp ];  \
-       then                                                                 \
-               wget -O carrolllines.zip $(CARROLL_LINES_URL);               \
-               unzip carrolllines.zip -d ./data/census2000/maryland/lines;  \
-               rm carrolllines.zip;                                         \
-       fi;
-
-cecil_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24015_edges.shp ];  \
-       then                                                                 \
-               wget -O cecillines.zip $(CECIL_LINES_URL);                   \
-               unzip cecillines.zip -d ./data/census2000/maryland/lines;    \
-               rm cecillines.zip;                                           \
-       fi;
-
-charles_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24017_edges.shp ];  \
-       then                                                                 \
-               wget -O charleslines.zip $(CHARLES_LINES_URL);               \
-               unzip charleslines.zip -d ./data/census2000/maryland/lines;  \
-               rm charleslines.zip;                                         \
-       fi;
-
-dorchester_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24019_edges.shp ];    \
-       then                                                                   \
-               wget -O dorchesterlines.zip $(DORCHESTER_LINES_URL);           \
-               unzip dorchesterlines.zip -d ./data/census2000/maryland/lines; \
-               rm dorchesterlines.zip;                                        \
-       fi;
-
-frederick_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24021_edges.shp ];   \
-       then                                                                  \
-               wget -O fredericklines.zip $(FREDERICK_LINES_URL);            \
-               unzip fredericklines.zip -d ./data/census2000/maryland/lines; \
-               rm fredericklines.zip;                                        \
-       fi;
-
-garrett_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24023_edges.shp ]; \
-       then                                                                \
-               wget -O garrettlines.zip $(GARRETT_LINES_URL);              \
-               unzip garrettlines.zip -d ./data/census2000/maryland/lines; \
-               rm garrettlines.zip;                                        \
-       fi;
-
-harford_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24025_edges.shp ]; \
-       then                                                                \
-               wget -O harfordlines.zip $(HARFORD_LINES_URL);              \
-               unzip harfordlines.zip -d ./data/census2000/maryland/lines; \
-               rm harfordlines.zip;                                        \
-       fi;
-
-howard_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24027_edges.shp ]; \
-       then                                                                \
-               wget -O howardlines.zip $(HOWARD_LINES_URL);                \
-               unzip howardlines.zip -d ./data/census2000/maryland/lines;  \
-               rm howardlines.zip;                                         \
-       fi;
-
-kent_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24029_edges.shp ]; \
-       then                                                                \
-               wget -O kentlines.zip $(KENT_LINES_URL);                    \
-               unzip kentlines.zip -d ./data/census2000/maryland/lines;    \
-               rm kentlines.zip;                                           \
-       fi;
-
-montgomery_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24031_edges.shp ];    \
-       then                                                                   \
-               wget -O montgomerylines.zip $(MONTGOMERY_LINES_URL);           \
-               unzip montgomerylines.zip -d ./data/census2000/maryland/lines; \
-               rm montgomerylines.zip;                                        \
-       fi;
-
-prince_georges_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24033_edges.shp ]; \
-       then                                                                \
-               wget -O pglines.zip $(PRINCE_GEORGES_LINES_URL);            \
-               unzip pglines.zip -d ./data/census2000/maryland/lines;      \
-               rm pglines.zip;                                             \
-       fi;
-
-queen_annes_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24035_edges.shp ]; \
-       then                                                                \
-               wget -O qalines.zip $(QUEEN_ANNES_LINES_URL);               \
-               unzip qalines.zip -d ./data/census2000/maryland/lines;      \
-               rm qalines.zip;                                             \
-       fi;
-
-st_marys_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24037_edges.shp ]; \
-       then                                                                \
-               wget -O smlines.zip $(ST_MARYS_LINES_URL);                  \
-               unzip smlines.zip -d ./data/census2000/maryland/lines;      \
-               rm smlines.zip;                                             \
-       fi;
-
-somerset_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24039_edges.shp ];  \
-       then                                                                 \
-               wget -O somersetlines.zip $(SOMERSET_LINES_URL);             \
-               unzip somersetlines.zip -d ./data/census2000/maryland/lines; \
-               rm somersetlines.zip;                                        \
-       fi;
-
-talbot_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24041_edges.shp ]; \
-       then                                                                \
-               wget -O talbotlines.zip $(TALBOT_LINES_URL);                \
-               unzip talbotlines.zip -d ./data/census2000/maryland/lines;  \
-               rm talbotlines.zip;                                         \
-       fi;
-
-washington_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24043_edges.shp ];    \
-       then                                                                   \
-               wget -O washingtonlines.zip $(WASHINGTON_LINES_URL);           \
-               unzip washingtonlines.zip -d ./data/census2000/maryland/lines; \
-               rm washingtonlines.zip;                                        \
-       fi;
-
-wicomico_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24045_edges.shp ];  \
-       then                                                                 \
-               wget -O wicomicolines.zip $(WICOMICO_LINES_URL);             \
-               unzip wicomicolines.zip -d ./data/census2000/maryland/lines; \
-               rm wicomicolines.zip;                                        \
-       fi;
-
-worcester_lines:
-       mkdir -p data/census2000/maryland/lines
-       if [ ! -f data/census2000/maryland/lines/tl_2009_24047_edges.shp ];   \
-       then                                                                  \
-               wget -O worcesterlines.zip $(WORCESTER_LINES_URL);            \
-               unzip worcesterlines.zip -d ./data/census2000/maryland/lines; \
-               rm worcesterlines.zip;                                        \
-       fi;
+tiger_lines:
+       bin/download_data
 
 
 # This imports the Tiger data using shp2pgsql. The shapefiles