|
| 1 | +WITH commonplace AS ( |
| 2 | + SELECT * FROM {{ source("recipe_sources", "dcp_cscl_commonplace_gdb") }} |
| 3 | +), |
| 4 | +centerline AS ( |
| 5 | + SELECT * FROM {{ ref('stg__centerline') }} |
| 6 | +), |
| 7 | +proto AS ( |
| 8 | + SELECT * FROM {{ ref('stg__altsegmentdata_proto') }} |
| 9 | +), |
| 10 | +shoreline AS ( |
| 11 | + SELECT * FROM {{ ref('stg__shoreline') }} |
| 12 | +), |
| 13 | +address_points AS ( |
| 14 | + SELECT * FROM {{ ref('int__address_point_house_numbers') }} |
| 15 | +), |
| 16 | +feature_names AS ( |
| 17 | + SELECT * FROM {{ ref('stg__facecode_and_featurename') }} |
| 18 | +) |
| 19 | +SELECT |
| 20 | + -- TODO "warning" issued if featurename instead of streetname |
| 21 | + -- TODO error when null |
| 22 | + -- TODO needs handling see 7.2 note 1.f |
| 23 | + feature_name.lookup_key AS place_name |
| 24 | + commonplace.boroughcode, |
| 25 | + '' AS face_code, |
| 26 | + '' AS segment_seqnum, |
| 27 | + CASE |
| 28 | + WHEN commonplace.sosindicator = '1' THEN 'L' |
| 29 | + WHEN commonplace.sosindicator = '2' THEN 'R' |
| 30 | + END AS sos_indicator, |
| 31 | + commonplace.b5sc, |
| 32 | + -- TODO there's a note about some text-processing when hyphen_type = 'R' and there's a hyphen in this field |
| 33 | + -- However, that does not match a single record. It seems like the docs are outdated and this is handled in cscl |
| 34 | + CASE WHEN commonplace.sosindicator = '1' THEN address_points.house_number END AS l_high_hn, |
| 35 | + CASE WHEN commonplace.sosindicator = '2' THEN address_points.house_number END AS r_high_hn, |
| 36 | + commonplace.saftype, |
| 37 | + RIGHT(commonplace.b7sc, 2) AS nap_lgc1, |
| 38 | + 1 AS boe_lgc_pointer, |
| 39 | + CASE |
| 40 | + WHEN shoreline.segmentid IS NOT NULL THEN 'U' |
| 41 | + ELSE centerline.segment_type -- todo weirdness about roadbed vs generic |
| 42 | + END AS segment_type, |
| 43 | + saf.segmentid, -- todo note 8 |
| 44 | + ROUND(ST_X(commonplace.geom))::INT AS x_coord, |
| 45 | + ROUND(ST_Y(commonplace.geom))::INT AS y_coord, |
| 46 | + -- TODO have no idea what's up with these |
| 47 | + NULL AS side_borough_code, |
| 48 | + NULL AS side_ct2010, |
| 49 | + NULL AS side_ap |
| 50 | +FROM commonplace |
| 51 | +LEFT JOIN segments ON saf.segmentid = segments.segmentid -- this is actually quite complicated |
| 52 | +LEFT JOIN address_points ON commonplace.primaryaddresspointid = address_points.addresspointid |
| 53 | +LEFT JOIN feature_names |
| 54 | + ON (saf.b5sc || saf.lgc1) = feature_names.b7sc |
| 55 | +WHERE saf.saftype IN ('A', 'B', 'C', 'E', 'P') |
0 commit comments