-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from cagov/staging_footprint_census_models
5 models of building footprints data joined with Tiger Data
- Loading branch information
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% macro map_class_fips(class_fips, k, v) -%} | ||
|
||
{# | ||
Class Codes source: https://www.census.gov/library/reference/code-lists/class-codes.html | ||
#} | ||
|
||
{% set class_fips_dict = { | ||
"M2" : "A military or other defense installation entirely within a place", | ||
"C1" : "An active incorporated place that does not serve as a county subdivision equivalent", | ||
"U1" : "A census designated place with an official federally recognized name", | ||
"U2" : "A census designated place without an official federally recognized name" | ||
} -%} | ||
|
||
case | ||
{% for k, v in class_fips_dict.items() %} | ||
when "{{ class_fips }}" = '{{ k }}' | ||
then '{{ v }}' | ||
{% endfor %} | ||
end | ||
|
||
{%- endmacro %} |
70 changes: 70 additions & 0 deletions
70
transform/models/marts/geo_reference/_geo_reference__models.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: building_footprints | ||
database: "{{ env_var('DBT_RAW_DB', 'RAW_DEV') }}" | ||
schema: geo_reference | ||
tables: | ||
- name: california_building_footprints | ||
- name: tiger_2022 | ||
database: "{{ env_var('DBT_RAW_DB', 'RAW_DEV') }}" | ||
schema: tiger_2022 | ||
tables: | ||
- name: blocks | ||
- name: places | ||
|
||
models: | ||
- name: geo_reference__building_footprints_with_blocks | ||
description: | | ||
This data table is a join of the TIGER shapefile, Blocks, | ||
with the Microsoft Building Footprints data for the state of CA. | ||
columns: | ||
- name: release | ||
description: The version of the data | ||
- name: capture_dates_range | ||
description: Each building footprint has a capture date tag from 2019-2020 | ||
- name: county_fips | ||
description: 2020 Census county FIPS code | ||
- name: tract | ||
description: 2020 Census tract code | ||
- name: block | ||
description: 2020 Census tabulation block number | ||
- name: geoid | ||
description: > | ||
Census block identifier; a concatenation of 2020 Census state FIPS code, 2020 | ||
Census county FIPS code, 2020 Census tract code, and 2020 Census block number | ||
- name: name | ||
description: > | ||
2020 Census tabulation block name; a concatenation of 'Block' | ||
and the tabulation block number | ||
- name: geometry | ||
description: The spatial component of geographic features | ||
- name: geo_reference__building_footprints_with_places | ||
description: | | ||
This data table is a join of the TIGER shapefile | ||
, Places, with the Microsoft Building Footprints | ||
data for the state of CA. | ||
columns: | ||
- name: release | ||
description: The version of the data | ||
- name: capture_dates_range | ||
description: > | ||
Each building footprint has a capture date tag associated from 2019-2020 | ||
- name: place_fp | ||
description: Current place FIPS code | ||
- name: place_ns | ||
description: Current place GNIS code | ||
- name: geoid | ||
description: > | ||
Place identifier; a concatenation of the current state | ||
FIPS code and place FIPS code | ||
- name: name | ||
description: > | ||
Current name and the translated legal/statistical | ||
area description for place | ||
- name: class_fips_code | ||
description: Current FIPS class code | ||
- name: class_fips | ||
description: Current FIPS class definition | ||
- name: geometry | ||
description: The spatial component of geographic features |
32 changes: 32 additions & 0 deletions
32
transform/models/marts/geo_reference/geo_reference__building_footprints_with_blocks.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
with footprints as ( | ||
select | ||
"release", | ||
"capture_dates_range", | ||
"geometry" | ||
from {{ source('building_footprints', 'california_building_footprints') }} | ||
), | ||
|
||
blocks_source as ( | ||
select * from {{ source('tiger_2022', 'blocks') }} | ||
), | ||
|
||
blocks as ( | ||
select | ||
"COUNTYFP20" as "county_fips", | ||
"TRACTCE20" as "tract", | ||
"BLOCKCE20" as "block", | ||
"GEOID20" as "geoid", | ||
"NAME20" as "name", | ||
"geometry" | ||
from blocks_source | ||
), | ||
|
||
footprints_and_blocks_joined as ( | ||
select | ||
footprints.*, | ||
blocks.* exclude "geometry" | ||
from footprints | ||
left join blocks on st_intersects(footprints."geometry", blocks."geometry") | ||
) | ||
|
||
select * from footprints_and_blocks_joined |
33 changes: 33 additions & 0 deletions
33
transform/models/marts/geo_reference/geo_reference__building_footprints_with_places.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
with footprints as ( | ||
select | ||
"release", | ||
"capture_dates_range", | ||
"geometry" | ||
from {{ source('building_footprints', 'california_building_footprints') }} | ||
), | ||
|
||
places_source as ( | ||
select * from {{ source('tiger_2022', 'places') }} | ||
), | ||
|
||
places as ( | ||
select | ||
"PLACEFP" as "place_fp", | ||
"PLACENS" as "place_ns", | ||
"GEOID" as "geoid", | ||
"NAME" as "name", | ||
"CLASSFP" as "class_fips_code", | ||
{{ map_class_fips("CLASSFP") }} as "class_fips", | ||
"geometry" | ||
from places_source | ||
), | ||
|
||
footprints_and_places_joined as ( | ||
select | ||
footprints.*, | ||
places.* exclude "geometry" | ||
from footprints | ||
left join places on st_intersects(footprints."geometry", places."geometry") | ||
) | ||
|
||
select * from footprints_and_places_joined |