Skip to content

Commit 900e184

Browse files
committed
saf_s
1 parent 23470f0 commit 900e184

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

products/cscl/design_doc.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,5 +633,35 @@ Notes on house numbers: in processing in `int__address_points`, all house number
633633
- for `hyphen_type` = 'N', 'Q', 'U', AddressPoint cleaned/formatted `house_number_suffix` field
634634
- for `hyphen_type` = 'R', 'X', AddressPoint field `house_number_range_suffix`
635635

636+
#### S Records
637+
S records are suffixed house number(s) occurring at an intersection.
638+
639+
They are generated from all address point records with `special_condition` = 'S'.
640+
641+
Starting from `int__saf_segments`, S records are joined to
642+
- address points (`int__address_points`) to lookup primary tabular data for the saf record
643+
- `stg__facecode_and_featurename` is joined by actual b7sc. Unlike type V records, vanity b7sc is not used at all
644+
- address point lgc table (`int__lgc_address_point`), a lookup table of address points to lgcs based on `addresspointid`
645+
646+
| FIC | Field | CSCL Source of Data |
647+
| - | - | - |
648+
| SAFS1 | Street Name | Obtained from FeatureName table, in sort format |
649+
| SAFS2 | Borough Code | AddressPoint field `boroughcode` |
650+
| SAFS3 | Face Code | Obtained from FeatureName table |
651+
| SAFS4 | Sequence Number | Segment `segment_seqnum` |
652+
| SAFS5 | SOS Indicator | AddressPoint field `sosindicator`, mapped `1` -> `L`, `2` -> `R` |
653+
| SAFS6 | B5SC | First 6 bytes of AddressPoint field `b7sc_actual` |
654+
| SAFS7 | HN Basic | 7 | 50 | 56 | RJSF | AddressPoint field `house_number` |
655+
| SAFS8 | House Number Suffix | 8 | 58 | 65 | LJSF, blanks if null | AddressPoint field `house_number_suffix` |
656+
| SAF85 | High Alpha House number suffix | 1 | 75 | 75 | AddressPoint field `house_number_RANGE_suffix` |
657+
| SAFS9 | SAF Record Type Code | 1 | 86 | 86 | AddressPoint field `special_condition` |
658+
| SAFS10 | LGC1 | Segment `lgc1` |
659+
| SAFS11 | LGC2 | Segment `lgc2` |
660+
| SAFS12 | LGC3 | Segment `lgc3` |
661+
| SAFS13 | LGC4 | Segment `lgc4` |
662+
| SAFS14 | Pointer to BOE Preferred LGC | Segment `boe_lgc_pointer` |
663+
| SAFS15 | Segment Type Code | Segment `segment_type` |
664+
| SAFS16 | Segment ID | Segment `segment_id` |
665+
636666
# Infrastructure
637667
[stub]

products/cscl/models/intermediate/saf/int__address_points.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ street_names AS (
1414
)
1515
SELECT
1616
address_points.addresspointid,
17+
address_points.segmentid,
1718
address_points.b7sc_vanity,
1819
address_points.b7sc_actual,
1920
address_points.sosindicator,
@@ -30,9 +31,8 @@ SELECT
3031
ELSE address_points.house_number
3132
END AS house_number,
3233
CASE
33-
WHEN street_names.snd_feature_type IN ('E', 'F') THEN NULL
34-
WHEN address_points.hyphen_type = 'R'
35-
THEN TRIM(SPLIT_PART(address_points.house_number, '-', 2))
34+
WHEN street_names.snd_feature_type IN ('E', 'F')
35+
THEN TRIM(SPLIT_PART(address_points.house_number_suffix, '-', 1))
3636
ELSE address_points.house_number_suffix
3737
END AS house_number_suffix,
3838
address_points.house_number AS plain_house_number,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
WITH saf AS (
2+
SELECT * FROM {{ ref('int__saf_segments') }}
3+
),
4+
address_points AS (
5+
SELECT * FROM {{ ref('int__address_points') }}
6+
),
7+
feature_names AS (
8+
SELECT * FROM {{ ref('stg__facecode_and_featurename') }}
9+
),
10+
lgc AS (
11+
SELECT * FROM {{ ref('int__streetcode_and_facecode') }}
12+
)
13+
SELECT
14+
feature_names.saf_place_name AS place_name,
15+
saf.boroughcode,
16+
COALESCE(feature_names.face_code, SUBSTRING(saf.segment_lionkey, 2, 4)) AS face_code,
17+
SUBSTRING(saf.segment_lionkey, 6, 5) AS segment_seqnum, -- TODO is this fine for generic/roadbed?
18+
CASE
19+
WHEN address_points.sosindicator = '1' THEN 'L'
20+
WHEN address_points.sosindicator = '2' THEN 'R'
21+
END AS sos_indicator,
22+
LEFT(address_points.b7sc_actual, 6) AS b5sc,
23+
address_points.house_number AS hn,
24+
address_points.house_number_suffix AS hn_suffix,
25+
address_points.house_number_range_suffix AS high_alpha_hn_suffix,
26+
saf.saftype,
27+
lgc.lgc1,
28+
lgc.lgc2,
29+
lgc.lgc3,
30+
lgc.lgc4,
31+
lgc.boe_lgc_pointer,
32+
saf.segment_type,
33+
saf.segmentid,
34+
saf.generic,
35+
saf.roadbed,
36+
address_points.addresspointid,
37+
feature_names.b7sc IS NOT NULL AS _joined_to_feature_name, -- for error report
38+
address_points.snd_feature_type
39+
FROM saf
40+
LEFT JOIN address_points ON saf.saf_globalid = address_points.globalid
41+
LEFT JOIN feature_names -- TODO error when not joined
42+
ON address_points.b7sc_actual = feature_names.b7sc AND feature_names.feature_type = 'street'
43+
LEFT JOIN lgc ON saf.segmentid = lgc.segmentid
44+
WHERE saf.saftype = 'S'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
{{ apply_text_formatting_from_seed('text_formatting__saf_s') }}
3+
FROM {{ ref("int__saf_s" ) }}
4+
WHERE generic
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
{{ apply_text_formatting_from_seed('text_formatting__saf_s') }}
3+
FROM {{ ref("int__saf_s" ) }}
4+
WHERE roadbed

products/cscl/recipe.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ exports:
107107
filename: RoadbedOV.txt
108108
format: dat
109109
custom: { formatting: saf_v }
110+
- name: saf_s_generic
111+
filename: GenericS.txt
112+
format: dat
113+
custom: { formatting: saf_s }
114+
- name: saf_s_roadbed
115+
filename: RoadbedS.txt
116+
format: dat
117+
custom: { formatting: saf_s }
110118

111119
# SEDAT
112120
- name: sedat
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
fic,field_name,field_label,field_length,start_index,end_index,justify_and_fill,blank_if_none
2+
SAFS1,place_name,Street Name,32,1,32,LJSF,FALSE
3+
SAFS2,boroughcode,Borough Code,1,33,33,RJSF,FALSE
4+
SAFS3,face_code,Face Code,4,34,37,RJZF,FALSE
5+
SAFS4,segment_seqnum,Sequence Number,5,38,42,RJZF,FALSE
6+
SAFS5,sos_indicator,SOS Indicator,1,43,43,RJSF,FALSE
7+
SAFS6,b5sc,B5SC,6,44,49,RJSF,FALSE
8+
SAFS7,hn,HN Basic,7,50,56,RJSF,FALSE
9+
,filler_safs7,Filler,1,57,57,RJSF,TRUE
10+
SAFS8,hn_suffix,House Number Suffix,8,58,65,LJSF,TRUE
11+
,filler_safs8,Filler,9,66,74,RJSF,FALSE
12+
SAF85,high_alpha_hn_suffix,High Alpha House number suffix,1,75,75,RJSF,FALSE
13+
,filler_saf85,Filler,10,76,85,RJSF,FALSE
14+
SAFS9,saftype,SAF Record Type Code,1,86,86,RJSF,FALSE
15+
,filler_safs9,Filler,2,87,88,RJSF,FALSE
16+
SAFS10,lgc1,LGC1,2,89,90,RJZF,FALSE
17+
SAFS11,lgc2,LGC2,2,91,92,RJZF,TRUE
18+
SAFS12,lgc3,LGC3,2,93,94,RJZF,TRUE
19+
SAFS13,lgc4,LGC4,2,95,96,RJZF,TRUE
20+
SAFS14,boe_lgc_pointer,Pointer to BOE Preferred LGC,1,97,97,RJSF,FALSE
21+
SAFS15,segment_type,Segment Type Code,1,98,98,RJSF,FALSE
22+
SAFS16,segmentid,Segment ID,7,99,105,RJZF,FALSE

0 commit comments

Comments
 (0)