Skip to content

Commit dfcca94

Browse files
author
Moped View Bot
committed
🤖 Export view for update-project-distribution-by-districts-view
1 parent fa9395f commit dfcca94

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

moped-database/views/council_district_project_distribution_analytics.sql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
-- Most recent migration: moped-database/migrations/default/1755539630397_add-project-district-analysis-m-views/up.sql
1+
-- Most recent migration: moped-database/migrations/default/1758551918596_adjust-projects-per-district-view/up.sql
22

33
CREATE OR REPLACE VIEW council_district_project_distribution_analytics AS WITH area_project_buffers AS (
44
SELECT
55
projects.project_id,
6-
st_buffer(st_transform(projects.geography::geometry, 2277), 33::double precision) AS buffer_geom
6+
st_buffer(st_transform(projects.geography::geometry, 2277), 100::double precision) AS buffer_geom
77
FROM project_geography projects
8-
WHERE st_geometrytype(projects.geography::geometry) = any(ARRAY['ST_MultiPoint'::text, 'ST_MultiLineString'::text])
8+
JOIN moped_project mp ON projects.project_id = mp.project_id
9+
WHERE mp.is_deleted = false AND (st_geometrytype(projects.geography::geometry) = any(ARRAY['ST_MultiPoint'::text, 'ST_MultiLineString'::text]))
10+
),
11+
12+
dissolved_project_buffers AS (
13+
SELECT
14+
area_project_buffers.project_id,
15+
st_unaryunion(st_collect(area_project_buffers.buffer_geom)) AS dissolved_buffer_geom
16+
FROM area_project_buffers
17+
GROUP BY area_project_buffers.project_id
918
),
1019

1120
area_district_aggregates AS (
1221
SELECT
1322
project_buffers.project_id,
1423
districts.council_district AS council_district_id,
15-
sum(st_area(st_intersection(project_buffers.buffer_geom, st_transform(districts.geography::geometry, 2277)))) AS total_area_in_district_sq_ft
16-
FROM area_project_buffers project_buffers
17-
JOIN layer_council_district districts ON st_intersects(project_buffers.buffer_geom, st_transform(districts.geography::geometry, 2277))
24+
sum(st_area(st_intersection(project_buffers.dissolved_buffer_geom, st_transform(districts.geography::geometry, 2277)))) AS total_area_in_district_sq_ft
25+
FROM dissolved_project_buffers project_buffers
26+
JOIN layer_council_district districts ON st_intersects(project_buffers.dissolved_buffer_geom, st_transform(districts.geography::geometry, 2277))
1827
GROUP BY project_buffers.project_id, districts.council_district
1928
),
2029

0 commit comments

Comments
 (0)