Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- query 1. intersects nuke site with mun
- query 2. buffers query 1 table
- query 3. creates a table of the aggregate receptors that fall within each nuke buffer
- def noury(buffer_table,buff_d,buffer_report):
- import os
- import sys
- import psycopg2
- conn = psycopg2.connect("dbname='nuclearingestion' user='postgres' host='localhost' password='sgsdg'") #connecting to DB
- cur = conn.cursor() #setting up connection cursor
- cur.execute("create table nukesite as select site_name,county,mun,nuke.geom from nuke,mun where ST_INTERSECTS(nuke.geom,mun.geom);")
- cur.execute('''create table %s as
- select site_name,county,mun, ST_UNION(ST_BUFFER(geom,%s)) as geom from nukesite group by site_name,county,mun;'''),(buffer_table,buff_d)
- cur.execute('''create table %s as
- select n.site_name::text,n.county::text as county,n.mun::text as mun,coalesce(q1.schools,'0') as schools,coalesce(q2.childcares,'0') as childcares,coalesce(q3.hospitals,'0') as hospitals,
- coalesce(q4.nursinghomes,'0') as nursinghom,coalesce(q5.infra,'0')as infra,coalesce(q6.streams,'0') as streams,coalesce(q7.streamsw,'0') as streamsw,coalesce(q8.rez,'0') as rez,n.geom as geom
- from (select site_name,county,mun,geom from %s) as n
- left join(select count(type_)::int::text as schools,site_name from %s,pr where st_intersects(%s.geom,pr.geom) and type_ = 'School' group by site_name) as q1
- on n.site_name = q1.site_name
- left join(select count(type_)::int::text as childcares,site_name from %s,pr where st_intersects(%s.geom,pr.geom) and type_ = 'Childcare' group by site_name) as q2
- on n.site_name = q2.site_name
- left join(select count(type_)::int::text as hospitals,site_name from %s,pr where st_intersects(%s.geom,pr.geom) and type_ = 'Hospital' group by site_name) as q3
- on n.site_name = q3.site_name
- left join(select count(type_)::int::text as nursinghomes,site_name from %s,pr where st_intersects(%s.geom,pr.geom) and type_ = 'Nursinghome' group by site_name) as q4
- on n.site_name = q4.site_name
- left join(select count(type_)::int::text as infra,site_name from %s,pr where st_intersects(%s.geom,pr.geom) and type_ = 'CriticalInfrastructure' group by site_name) as q5
- on n.site_name = q5.site_name
- left join(select round(sum(st_length(streams.geom))/5280)::float::text as streams,site_name from %s,streams where st_intersects(%s.geom,streams.geom) group by site_name) as q6
- on n.site_name = q6.site_name
- left join(select round(sum(st_length(streamsw.geom))/5280)::float::text as streamsw,site_name from %s,streamsw where st_intersects(%s.geom,streamsw.geom) group by site_name) as q7
- on n.site_name = q7.site_name
- left join(select round(sum(popest*((ST_Area(rez.geom)/43560)/acresnew)))::int::text as rez,site_name from %s,rez where st_intersects(%s.geom,rez.geom) group by site_name) as q8
- on n.site_name = q8.site_name'''),(buffer_report,buffer_table)
- conn.commit()
- print noury("nuke10",52800,"nuke10report")
- Traceback (most recent call last):
- File "C:UsersrzaghaDesktopNukeIngestion.py", line 33, in <module>
- print noury("nuke10",52800,"nuke10report")
- File "C:UsersrzaghaDesktopNukeIngestion.py", line 9, in noury
- cur.execute('''create table %s as select site_name,county,mun, ST_UNION(ST_BUFFER(geom,%s)) as geom from nukesite group by site_name,county,mun;'''),(buffer_table,buff_d)
- ProgrammingError: syntax error at or near "%"
- LINE 1: create table %s as select site_name,county,mun, ST_UNION(ST_...
- ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement