diff --git a/transform/macros/map_class_fp.sql b/transform/macros/map_class_fp.sql new file mode 100644 index 00000000..7ab371dc --- /dev/null +++ b/transform/macros/map_class_fp.sql @@ -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 %} diff --git a/transform/models/marts/geo_reference/_geo_reference__models.yml b/transform/models/marts/geo_reference/_geo_reference__models.yml new file mode 100644 index 00000000..12d82798 --- /dev/null +++ b/transform/models/marts/geo_reference/_geo_reference__models.yml @@ -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 diff --git a/transform/models/marts/geo_reference/geo_reference__building_footprints_with_blocks.sql b/transform/models/marts/geo_reference/geo_reference__building_footprints_with_blocks.sql new file mode 100644 index 00000000..c90dfc40 --- /dev/null +++ b/transform/models/marts/geo_reference/geo_reference__building_footprints_with_blocks.sql @@ -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 diff --git a/transform/models/marts/geo_reference/geo_reference__building_footprints_with_places.sql b/transform/models/marts/geo_reference/geo_reference__building_footprints_with_places.sql new file mode 100644 index 00000000..6bb559d0 --- /dev/null +++ b/transform/models/marts/geo_reference/geo_reference__building_footprints_with_places.sql @@ -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