]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - bin/sf1blocks2sql
4 Exports geographic header records to SQL.
5 We take a geographic header file, and a table name as arguments, and then
6 parse that header file to create the necessary SQL statements. The generated
7 SQL statements refer to the table name passed as an argument.
9 The output is written to stdout; it can either be redirected to a file,
10 or piped directly in to the database.
17 # Basically, add '../src' to our path.
18 # Needed for the imports that follow.
19 site
.addsitedir(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])) + '/../src')
26 if (len(sys
.argv
) < 3):
27 print "Usage: %s <geo_file> <table_name>" % sys
.argv
[0]
28 raise SystemExit(ExitCodes
.NOT_ENOUGH_ARGS
)
30 geo_file_path
= sys
.argv
[1]
31 table_name
= sys
.argv
[2]
33 grp
= SummaryFile1
.GeoRecordParser()
34 blocks
= grp
.parse_blocks(geo_file_path
)
38 INSERT INTO %s (state,
49 VALUES ('%s', '%s', '%s', '%s', %.12f, %.12f, %.12f, '%s', %d, %.12f);
53 # Print out the INSERT statement contained in sql_query,
54 # substituting in all of the block attributes.
55 print sql_query
% (table_name
,
65 b
.population_density())