Created
July 18, 2012 22:44
-
-
Save ian29/3139459 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 python | |
# -*- coding: utf-8 -*- | |
import psycopg2 | |
con = psycopg2.connect("dbname=nyc3 user=postgres") # CONnect to a database | |
cur = con.cursor() | |
cur.execute('''select ctidfp00 from tracts;''') | |
results = cur.fetchall() | |
for result in results: | |
tract_id = result[0] # create a variable from the first column of the results | |
cmd = ''.join([ | |
'pgsql2shp -u postgres -f tract_', tract_id, ' nyc3 ', | |
'"select a.gid,a.the_geom,a.overlap from import_buildings a ', | |
'where st_dwithin(a.the_geom, (select b.the_geom from tracts b where cast(ctidfp00 as numeric) = ', tract_id, '), 0);"', | |
]) | |
print(cmd) | |
cur.close() | |
con.close() | |
test_tract_building.py (END) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment