Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create IDOT features #620

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
acb0154
Initial test
Damonamajor Oct 9, 2024
0652b3a
Sort headings
Damonamajor Oct 9, 2024
5191e58
New test
Damonamajor Oct 10, 2024
c4807fb
local
Damonamajor Oct 10, 2024
6e2a088
surface width
Damonamajor Oct 10, 2024
ccc67fa
More tests
Damonamajor Oct 10, 2024
6a9c130
Query improvements
Damonamajor Oct 10, 2024
12b2ebf
Make all distinct_pins
Damonamajor Oct 10, 2024
a22e314
Make traffic_width unique
Damonamajor Oct 11, 2024
d835273
switch to daily_traffic
Damonamajor Oct 11, 2024
7bd08b8
Try master
Damonamajor Oct 11, 2024
ca76942
Fix master?
Damonamajor Oct 11, 2024
8ba251d
Another master test
Damonamajor Oct 11, 2024
1cf60f2
Another master test
Damonamajor Oct 11, 2024
d3ba259
Add config
Damonamajor Oct 11, 2024
e34b8c8
switch to width
Damonamajor Oct 11, 2024
4ae5554
Make year last column
Damonamajor Oct 11, 2024
d2a45fa
Merge into master
Damonamajor Oct 15, 2024
aace136
Try to remove 2014
Damonamajor Oct 15, 2024
3f070de
Remove minor_collector
Damonamajor Oct 15, 2024
b50e813
Remove parcel.year = pin.year
Damonamajor Oct 15, 2024
ebbc52e
Remove minor again
Damonamajor Oct 15, 2024
e8671f7
Remove Freeway
Damonamajor Oct 15, 2024
967114c
Start from begining
Damonamajor Oct 15, 2024
ba0b0a1
Separate freeway
Damonamajor Oct 15, 2024
aa91cf8
Add principal
Damonamajor Oct 15, 2024
639468c
Try with major
Damonamajor Oct 15, 2024
ed4ba5f
Add other
Damonamajor Oct 16, 2024
0c41137
re-add major
Damonamajor Oct 16, 2024
7cc2b22
remove year
Damonamajor Oct 16, 2024
03bdf61
Remove year from join
Damonamajor Oct 16, 2024
09ce316
Remove all pcl.year
Damonamajor Oct 16, 2024
7291c2d
remove year from joins
Damonamajor Oct 16, 2024
f0ca25f
Try a bit of refactor
Damonamajor Oct 16, 2024
205e5c5
rename data_year
Damonamajor Oct 16, 2024
33e1993
Try to add minor collector
Damonamajor Oct 16, 2024
ce34f6f
Add CTE
Damonamajor Oct 16, 2024
6469e29
Add lands and surface type
Damonamajor Oct 24, 2024
0e8dc1f
Switch to speed limit
Damonamajor Oct 24, 2024
b4351bc
Lowercase and
Damonamajor Oct 24, 2024
6bc3d82
Add dailiy_traffic
Damonamajor Oct 24, 2024
373ec21
Test local in wrong query
Damonamajor Oct 24, 2024
3ba546f
Try different join syntax
Damonamajor Oct 24, 2024
6d15e66
Add local
Damonamajor Oct 24, 2024
fdae401
Try to add other
Damonamajor Oct 24, 2024
fe8a1cc
Add minor collector
Damonamajor Oct 24, 2024
601292a
Add year to join for minor_collector
Damonamajor Oct 24, 2024
35bfcf9
Add year to join for minor_collector
Damonamajor Oct 24, 2024
ce87790
Test with only valid daily traffic for local
Damonamajor Oct 25, 2024
40ddfd7
Test macro upload
Damonamajor Oct 25, 2024
a3131c6
Test macro
Damonamajor Oct 25, 2024
364fafb
Revert to traffic not null
Damonamajor Oct 28, 2024
28cbeb2
Test nearest_local new format
Damonamajor Oct 28, 2024
387731c
Revert
Damonamajor Oct 28, 2024
e70ea40
Revert
Damonamajor Oct 28, 2024
43937d3
test
Damonamajor Oct 28, 2024
35dafbf
Remove semicolon
Damonamajor Oct 28, 2024
fe29661
Try null and all for local
Damonamajor Oct 29, 2024
1d118f4
typo
Damonamajor Oct 29, 2024
3f5f221
add road to query
Damonamajor Oct 29, 2024
f6bdb9a
Revert to working query
Damonamajor Oct 29, 2024
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
11 changes: 11 additions & 0 deletions dbt/macros/nearest_feature_aggregation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% macro nearest_feature_aggregation(base_columns, characteristics) %}
{%- for characteristic in characteristics %}
case
{%- for base in base_columns %}
when {{ base }} = least({{ base_columns | join(", ") }})
then {{ base.replace("dist_ft", characteristic) }}
{%- endfor %}
else null
end as closest_{{ characteristic }},
{%- endfor %}
{% endmacro %}
8 changes: 8 additions & 0 deletions dbt/models/proximity/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ Distance from each PIN to the nearest sports stadium.
**Primary Key**: `pin10`, `year`
{% enddocs %}

# dist_pin_to_traffic_daily_traffic

{% docs table_dist_pin_to_traffic_daily_traffic %}
Distance from each PIN to the valid value of daily traffic.

**Primary Key**: `pin10`, `year`
{% enddocs %}

# dist_pin_to_university

{% docs table_dist_pin_to_university %}
Expand Down
340 changes: 340 additions & 0 deletions dbt/models/proximity/proximity.dist_pin_to_traffic_master.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,340 @@
{{
config(
materialized='table',
partitioned_by=['year'],
bucketed_by=['pin10'],
bucket_count=1
)
}}

WITH traffic_minor AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Minor Arterial'
),

traffic_interstate AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Interstate'
),

traffic_freeway AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Freeway and Expressway'
),

traffic_local AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Local Road or Street'
AND daily_traffic IS NOT NULL
),

traffic_collector AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Major Collector'
OR road_type = 'Minor Collector'
),

traffic_other AS ( -- noqa: ST03
SELECT *
FROM {{ source('spatial', 'traffic') }}
WHERE road_type = 'Other Principal Arterial'
),

distinct_pins AS (
SELECT DISTINCT
x_3435,
y_3435,
pin10
FROM {{ source('spatial', 'parcel') }}
),

distinct_years AS (
SELECT DISTINCT year
FROM {{ source('spatial', 'traffic') }}
WHERE road_type IS NOT NULL
),

-- Calculate nearest Minor Arterial road per pin
nearest_minor AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_minor_road_name,
ARBITRARY(xy.dist_ft) AS nearest_minor_road_dist_ft,
ARBITRARY(xy.year) AS nearest_minor_road_data_year,
ARBITRARY(xy.daily_traffic) AS nearest_minor_road_daily_traffic,
ARBITRARY(xy.speed_limit) AS nearest_minor_road_speed_limit,
ARBITRARY(xy.surface_type) AS nearest_minor_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_minor_road_lanes
FROM distinct_pins AS pcl
INNER JOIN ( {{ dist_to_nearest_geometry('traffic_minor') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

-- Calculate nearest Interstate road per pin
nearest_interstate AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_interstate_road_name,
ARBITRARY(xy.dist_ft) AS nearest_interstate_road_dist_ft,
ARBITRARY(xy.year) AS nearest_interstate_road_data_year,
ARBITRARY(xy.daily_traffic) AS nearest_interstate_road_daily_traffic,
ARBITRARY(xy.speed_limit) AS nearest_interstate_road_speed_limit,
ARBITRARY(xy.surface_type) AS nearest_interstate_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_interstate_road_lanes
FROM distinct_pins AS pcl
INNER JOIN ( {{ dist_to_nearest_geometry('traffic_interstate') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

-- Calculate nearest Freeway or Expressway road per pin
nearest_freeway AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_freeway_road_name,
ARBITRARY(xy.dist_ft) AS nearest_freeway_road_dist_ft,
ARBITRARY(xy.year) AS nearest_freeway_road_data_year,
ARBITRARY(xy.daily_traffic) AS nearest_freeway_road_daily_traffic,
ARBITRARY(xy.speed_limit) AS nearest_freeway_road_speed_limit,
ARBITRARY(xy.surface_type) AS nearest_freeway_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_freeway_road_lanes
FROM distinct_pins AS pcl
INNER JOIN ( {{ dist_to_nearest_geometry('traffic_freeway') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

nearest_local AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_local_road_name,
ARBITRARY(xy.dist_ft) AS nearest_local_road_dist_ft,
ARBITRARY(xy.year) AS nearest_local_road_data_year,
ARBITRARY(xy.daily_traffic) AS nearest_local_road_daily_traffic,
ARBITRARY(xy.speed_limit) AS nearest_local_road_speed_limit,
ARBITRARY(xy.surface_type) AS nearest_local_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_local_road_lanes
FROM distinct_pins AS pcl
INNER JOIN ( {{ dist_to_nearest_geometry('traffic_local') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

-- Calculate nearest Major Collector road per pin
nearest_collector AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_collector_road_name,
ARBITRARY(xy.dist_ft) AS nearest_collector_road_dist_ft,
ARBITRARY(xy.year) AS nearest_collector_road_data_year,
ARBITRARY(xy.speed_limit)
AS nearest_collector_road_speed_limit,
ARBITRARY(xy.daily_traffic) AS nearest_collector_road_daily_traffic,
ARBITRARY(xy.surface_type) AS nearest_collector_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_collector_road_lanes
FROM distinct_pins AS pcl
INNER JOIN
( {{ dist_to_nearest_geometry('traffic_collector') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

-- Calculate nearest Other Principal Arterial road per pin
nearest_other AS (
SELECT
pcl.pin10,
xy.year,
ARBITRARY(xy.road_name) AS nearest_other_road_name,
ARBITRARY(xy.dist_ft) AS nearest_other_road_dist_ft,
ARBITRARY(xy.year) AS nearest_other_road_data_year,
ARBITRARY(xy.daily_traffic) AS nearest_other_road_daily_traffic,
ARBITRARY(xy.speed_limit) AS nearest_other_road_speed_limit,
ARBITRARY(xy.surface_type) AS nearest_other_road_surface_type,
ARBITRARY(xy.lanes) AS nearest_other_road_lanes
FROM distinct_pins AS pcl
INNER JOIN ( {{ dist_to_nearest_geometry('traffic_other') }} ) AS xy
ON pcl.x_3435 = xy.x_3435
AND pcl.y_3435 = xy.y_3435
GROUP BY pcl.pin10, xy.year
),

-- Join all nearest roads by pin10 and year
final_aggregation AS (
SELECT
COALESCE(
minor.pin10, interstate.pin10, freeway.pin10,
local_road.pin10, collector.pin10
) AS pin10,
minor.nearest_minor_road_name,
minor.nearest_minor_road_dist_ft,
minor.nearest_minor_road_data_year,
minor.nearest_minor_road_daily_traffic,
minor.nearest_minor_road_speed_limit,
minor.nearest_minor_road_surface_type,
minor.nearest_minor_road_lanes,
interstate.nearest_interstate_road_name,
interstate.nearest_interstate_road_dist_ft,
interstate.nearest_interstate_road_data_year,
interstate.nearest_interstate_road_daily_traffic,
interstate.nearest_interstate_road_speed_limit,
interstate.nearest_interstate_road_surface_type,
interstate.nearest_interstate_road_lanes,
freeway.nearest_freeway_road_name,
freeway.nearest_freeway_road_dist_ft,
freeway.nearest_freeway_road_data_year,
freeway.nearest_freeway_road_daily_traffic,
freeway.nearest_freeway_road_speed_limit,
freeway.nearest_freeway_road_surface_type,
freeway.nearest_freeway_road_lanes,
local_road.nearest_local_road_name,
local_road.nearest_local_road_dist_ft,
local_road.nearest_local_road_data_year,
local_road.nearest_local_road_daily_traffic,
local_road.nearest_local_road_speed_limit,
local_road.nearest_local_road_surface_type,
local_road.nearest_local_road_lanes,
collector.nearest_collector_road_name,
collector.nearest_collector_road_dist_ft,
collector.nearest_collector_road_data_year,
collector.nearest_collector_road_daily_traffic,
collector.nearest_collector_road_speed_limit,
collector.nearest_collector_road_surface_type,
collector.nearest_collector_road_lanes,
other.nearest_other_road_name,
other.nearest_other_road_dist_ft,
other.nearest_other_road_data_year,
other.nearest_other_road_daily_traffic,
other.nearest_other_road_speed_limit,
other.nearest_other_road_surface_type,
other.nearest_other_road_lanes,
COALESCE(
minor.year, interstate.year, freeway.year,
local_road.year, collector.year, other.year)
AS year
FROM nearest_minor AS minor
FULL OUTER JOIN nearest_interstate AS interstate
ON minor.pin10 = interstate.pin10
AND minor.year = interstate.year
FULL OUTER JOIN nearest_freeway AS freeway
ON COALESCE(minor.pin10, interstate.pin10) = freeway.pin10
AND COALESCE(minor.year, interstate.year) = freeway.year
FULL OUTER JOIN nearest_local AS local_road
ON COALESCE(minor.pin10, interstate.pin10, freeway.pin10)
= local_road.pin10
AND COALESCE(minor.year, interstate.year, freeway.year)
= local_road.year
FULL OUTER JOIN nearest_collector AS collector
ON COALESCE(
minor.pin10, interstate.pin10,
freeway.pin10, local_road.pin10
)
= collector.pin10
AND COALESCE(minor.year, interstate.year, freeway.year, local_road.year)
= collector.year
FULL OUTER JOIN nearest_other AS other
ON COALESCE(
minor.pin10,
interstate.pin10,
freeway.pin10,
local_road.pin10,
collector.pin10
)
= other.pin10
AND COALESCE(
minor.year,
interstate.year,
freeway.year,
local_road.year,
collector.year
)
= other.year
WHERE COALESCE(
minor.year, interstate.year, freeway.year,
local_road.year, collector.year,
other.year
)
>= (SELECT MIN(year) FROM distinct_years)
)


SELECT
pin10,
nearest_minor_road_name,
nearest_minor_road_dist_ft,
nearest_minor_road_data_year,
nearest_minor_road_daily_traffic,
nearest_minor_road_speed_limit,
nearest_minor_road_surface_type,
nearest_minor_road_lanes,
nearest_interstate_road_name,
nearest_interstate_road_dist_ft,
nearest_interstate_road_data_year,
nearest_interstate_road_daily_traffic,
nearest_interstate_road_speed_limit,
nearest_interstate_road_surface_type,
nearest_interstate_road_lanes,
nearest_freeway_road_name,
nearest_freeway_road_dist_ft,
nearest_freeway_road_data_year,
nearest_freeway_road_daily_traffic,
nearest_freeway_road_speed_limit,
nearest_freeway_road_surface_type,
nearest_freeway_road_lanes,
nearest_local_road_name,
nearest_local_road_dist_ft,
nearest_local_road_data_year,
nearest_local_road_daily_traffic,
nearest_local_road_speed_limit,
nearest_local_road_surface_type,
nearest_local_road_lanes,
nearest_collector_road_name,
nearest_collector_road_dist_ft,
nearest_collector_road_data_year,
nearest_collector_road_daily_traffic,
nearest_collector_road_speed_limit,
nearest_collector_road_surface_type,
nearest_collector_road_lanes,
nearest_other_road_name,
nearest_other_road_dist_ft,
nearest_other_road_data_year,
nearest_other_road_daily_traffic,
nearest_other_road_speed_limit,
nearest_other_road_surface_type,
nearest_other_road_lanes,
{{ nearest_feature_aggregation(
[
"nearest_minor_road_dist_ft",
"nearest_interstate_road_dist_ft",
"nearest_other_road_dist_ft",
"nearest_freeway_road_dist_ft",
"nearest_local_road_dist_ft",
"nearest_collector_road_dist_ft"
],
[
"name",
"dist_ft",
"data_year",
"daily_traffic",
"speed_limit",
"surface_type",
"lanes"
]
) }}
year
FROM final_aggregation
8 changes: 8 additions & 0 deletions dbt/models/spatial/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ Includes townships within the City of Chicago, which are technically defunct.
**Geometry:** `MULTIPOLYGON`
{% enddocs %}

# traffic

{% docs table_traffic %}
Traffic data derived from Illinois Department of Transportation

**Geometry:** `MULTILINESTRING`
{% enddocs %}

# transit_dict

{% docs table_transit_dict %}
Expand Down
3 changes: 3 additions & 0 deletions dbt/models/spatial/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ sources:
- name: township
description: '{{ doc("table_township") }}'

- name: traffic
description: '{{ doc("table_traffic") }}'

- name: transit_dict
description: '{{ doc("table_transit_dict") }}'

Expand Down
Loading