Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions products/pluto/models/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ sources:
description: Spatial overlaps between lots and MIH areas (from miharea.sql)
- name: mih_distinct_options
description: QAQC view of all distinct MIH options found in the data (from miharea.sql)
columns:
- name: option
description: MIH option name
data_tests:
- accepted_values:
values: ['Option 1', 'Option 2', 'Option 3', 'Deep Affordability Option', 'Workforce Option']
config:
severity: error
tags: ['de_check', 'minor', 'major']
meta:
description: Only the five valid MIH options should appear in the source data. Any additional options indicate a source data issue that needs to be investigated.
next_steps: Contact GIS to investigate unexpected MIH option values in source data
- name: transit_zones_block_to_tz_ranked
description: Ranked transit zone assignments by block (from transitzone.sql)
- name: transit_zones_bbl_to_tz_ranked
Expand Down
16 changes: 7 additions & 9 deletions products/pluto/pluto_build/sql/transitzone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
-- lot-by-lot calculation when block-level assignment would be misleading.

-- Create decomposed transit zones table (break multipolygons into individual parts)
DROP TABLE IF EXISTS transit_zones_atomic_geoms;
DROP TABLE IF EXISTS transit_zones_atomic_geoms CASCADE;
CREATE TABLE transit_zones_atomic_geoms AS
WITH decomposed AS (
SELECT
Expand All @@ -52,7 +52,7 @@ CREATE INDEX idx_transit_zones_atomic_geoms_gix ON transit_zones_atomic_geoms US
-- AR Note: I tried a few approaches for this, and perhaps there's a more clever/performant
-- way to accomplish this. Unfortunately, the recommend approach of ST_ClusterDBSCAN
-- will `sometimes` accomplish this, but it errors out seemingly randomly.
DROP TABLE IF EXISTS transit_zones_tax_blocks;
DROP TABLE IF EXISTS transit_zones_tax_blocks CASCADE;
CREATE TABLE transit_zones_tax_blocks AS
WITH block_unions AS (
SELECT
Expand Down Expand Up @@ -89,7 +89,7 @@ WITH block_unions AS (
ON
np.borough = p.borough
AND np.block = p.block
AND ST_WITHIN(ST_CENTROID(p.geom), np.geom)
AND ST_WITHIN(ST_POINTONSURFACE(p.geom), np.geom)
GROUP BY np.borough, np.block, np.sub_block, np.geom
)
SELECT
Expand All @@ -104,7 +104,7 @@ CREATE INDEX idx_transit_zones_tax_blocks_geom ON transit_zones_tax_blocks USING


-- Step 1: Calculate coverage percentages for all tax blocks
DROP TABLE IF EXISTS transit_zones_block_to_tz_ranked;
DROP TABLE IF EXISTS transit_zones_block_to_tz_ranked CASCADE;
CREATE TABLE transit_zones_block_to_tz_ranked AS
WITH block_to_tz AS (
SELECT
Expand Down Expand Up @@ -140,7 +140,7 @@ ANALYZE transit_zones_block_to_tz_ranked;


-- For ambiguous blocks (those with competing transit zones), create lot-level assignments
DROP TABLE IF EXISTS transit_zones_bbl_to_tz_ranked;
DROP TABLE IF EXISTS transit_zones_bbl_to_tz_ranked CASCADE;
CREATE TABLE transit_zones_bbl_to_tz_ranked AS
WITH ambiguous_bbls AS (
SELECT
Expand Down Expand Up @@ -221,13 +221,11 @@ FROM (
AND NOT EXISTS (
SELECT 1 FROM transit_zones_block_to_tz_ranked AS ambiguous
WHERE
ambiguous.borough = block_tz.borough
AND ambiguous.block = block_tz.block
ambiguous.id = block_tz.id
AND ambiguous.tz_rank = 2
AND ambiguous.pct_covered > 10
)

UNION ALL

-- Lot-level assignments for ambiguous blocks
SELECT
bbls[1] AS bbl,
Expand Down
36 changes: 0 additions & 36 deletions products/pluto/tests/assert_only_valid_mih_options.sql

This file was deleted.

Loading