Skip to content

Commit

Permalink
updating sql for 2015
Browse files Browse the repository at this point in the history
  • Loading branch information
jspeis committed Nov 21, 2016
1 parent 4460114 commit 95b9852
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sql/university_geos.sql
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
-- First run:
-- pg_dump -t attrs.ztest_university datausa -h postgres.datawheel.us -U postgres -W > /tmp/universities.sql
-- insert into attrs.university (select * from attrs.ztest_university where id not in (select id from attrs.university))
-- CREATE LOOKUP for each univ
-- 1. pg_dump -t attrs.ztest_university datausa --no-privileges -h postgres.datawheel.us -U postgres -W > /tmp/universities.sql
-- 2. psql < universities.sql
-- 3. Generate university_geo lookup table
CREATE TABLE university_geo AS
SELECT u.id as university, '04000US' || state.geoid as geo
FROM tiger2013.state state, university u
FROM tiger2015.state state, attrs.university u
WHERE ST_Intersects(state.geom, ST_SetSRID(ST_Point(u.lng, u.lat),4326))
UNION
(SELECT u.id as university, '05000US' || county.geoid as geo
FROM tiger2013.county county, university u
FROM tiger2015.county county, attrs.university u
WHERE ST_Intersects(county.geom, ST_SetSRID(ST_Point(u.lng, u.lat),4326)))
UNION
(SELECT u.id as university, '31000US' || cbsa.geoid as geo
FROM tiger2013.cbsa cbsa, university u
FROM tiger2015.cbsa cbsa, attrs.university u
WHERE ST_Intersects(cbsa.geom, ST_SetSRID(ST_Point(u.lng, u.lat),4326)))
UNION
(SELECT u.id as university, '16000US' || place.geoid as geo
FROM tiger2013.place place, university u
FROM tiger2015.place place, attrs.university u
WHERE ST_Intersects(place.geom, ST_SetSRID(ST_Point(u.lng, u.lat),4326)))
UNION
(SELECT u.id as university, '79500US' || puma.geoid10 as geo
FROM tiger2013.puma puma, university u
FROM tiger2015.puma puma, attrs.university u
WHERE ST_Intersects(puma.geom, ST_SetSRID(ST_Point(u.lng, u.lat),4326)))

0 comments on commit 95b9852

Please sign in to comment.