forked from llooker/datablocks-acs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowflake.geo_map.view.lkml
204 lines (182 loc) · 5.33 KB
/
snowflake.geo_map.view.lkml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
view: sf_logrecno_bg_map {
label: "Geography"
derived_table: {
sql:
SELECT
UPPER(stusab) as stusab,
logrecno,
CONCAT(UPPER(stusab), CAST(logrecno AS STRING)) as row_id,
sumlevel,
state as state_fips_code,
county as county_fips_code,
tract,
blkgrp,
SUBSTR(geo.geoid, 8, 11) as geoid11,
geo.geoid,
trim(CASE
WHEN sumlevel = '140'
THEN SPLIT_PART(name, ',', 3)
WHEN sumlevel = '150'
THEN SPLIT_PART(name, ',', 4)
END) as state_name,
trim(CASE
WHEN sumlevel = '140'
THEN SPLIT_PART(name, ',', 2)
WHEN sumlevel = '150'
THEN SPLIT_PART(name, ',', 3)
END) as county_name,
trim(CASE
WHEN sumlevel = '140'
THEN SPLIT_PART(name, ',', 1)
WHEN sumlevel = '150'
THEN SPLIT_PART(name, ',', 2)
END) as tract_name,
trim(CASE
WHEN sumlevel = '150'
THEN SPLIT_PART(name, ',', 1)
END) as block_group_name,
CASE WHEN geo.SUMLEVEL = '150' THEN bg.INTPTLAT END as latitude,
CASE WHEN geo.SUMLEVEL = '150' THEN bg.INTPTLON END as longitude,
SUM(COALESCE(bg.ALAND, tr.ALAND) * 0.000000386102159) AS square_miles_land,
SUM(COALESCE(bg.AWATER, tr.AWATER) * .000000386102159) AS square_miles_water
FROM
ACS.GEO2015 as geo
LEFT JOIN ACS.BLOCK_GROUP_ATTRIBS as bg on (SUBSTR(geo.GEOID, 8, 12) = bg.geoid AND geo.SUMLEVEL = '150')
LEFT JOIN ACS.BLOCK_GROUP_ATTRIBS as tr on (SUBSTR(geo.GEOID, 8, 11) = SUBSTR(tr.geoid, 1, 11) AND geo.SUMLEVEL = '140')
WHERE
sumlevel in ('140', '150')
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ;;
persist_for: "10000 hours"
}
dimension: row_id {sql: ${TABLE}.row_id;;
primary_key:yes
hidden: yes
}
dimension: geoid11 {hidden:yes}
dimension: logrecno {hidden:yes}
dimension: blkgrp {hidden:yes}
dimension: sumlevel {hidden:yes sql: ${TABLE}.sumlevel;;}
# State
dimension: stusab {
label: "State Abbreviation"
group_label: "State"
link: {
url: "https://maps.google.com?q={{value}}"
label: "Google Maps"
}
suggest_persist_for: "120 hours"
}
dimension: state_name {
group_label: "State"
map_layer_name: us_states
sql: ${TABLE}.state_name;;
link: {
url: "https://maps.google.com?q={{value}}"
label: "Google Maps"
}
suggest_persist_for: "120 hours"
drill_fields: [county, tract]
}
dimension: state {
group_label: "State"
label: "State FIPS Code"
sql: ${TABLE}.state_fips_code;;
suggest_persist_for: "120 hours"
}
# measure: count_state {
# type: count_distinct
# sql: ${state_name} ;;
# drill_fields: [state_name, data.default_drills*, count_county, count_tract, count_block]
# }
# County
dimension: county {
group_label: "County"
label: "County FIPS Code"
sql: CONCAT(${state}, ${TABLE}.county_fips_code);;
map_layer_name: us_counties_fips
drill_fields: [tract, block_group]
suggest_persist_for: "120 hours"
}
dimension: county_name {
group_label: "County"
sql: CONCAT(${TABLE}.county_name, CONCAT(', ', ${state_name}));;
link: {
url: "https://maps.google.com?q={{value}}"
label: "Google Maps"
}
suggest_persist_for: "120 hours"
}
# measure: count_county {
# type: count_distinct
# sql: ${county_name} ;;
# drill_fields: [county_name, data.default_drills*, count_tract, count_block,]
# }
# Tract
dimension: tract {
label: "Tract Geo Code"
group_label: "Tract"
sql: ${TABLE}.geoid11 ;;
map_layer_name: tract
suggest_persist_for: "120 hours"
}
dimension: tract_name {
sql: CONCAT(${TABLE}.tract_name, CONCAT(', ', ${county_name}));;
group_label: "Tract"
link: {
url: "https://google.com?q={{value}}"
label: "Google"
}
suggest_persist_for: "120 hours"
}
# measure: count_tract {
# type: count_distinct
# sql: ${tract_name} ;;
# drill_fields: [tract_name, data.default_drills*, count_block]
# }
# Block Group
dimension: block_group {
sql: SUBSTR(${TABLE}.geoid, 8, 12);;
group_label: "Block Group"
label: "Block Group Geo Code"
map_layer_name: block_group
link: {
url: "https://google.com?q={{value}}"
label: "Google"
}
suggest_persist_for: "120 hours"
}
dimension: block_group_name {
sql: CONCAT(${TABLE}.block_group_name, CONCAT(', ', ${tract_name})) ;;
group_label: "Block Group"
suggest_persist_for: "120 hours"
}
dimension: block_group_centroid {
type: location
sql_latitude: ${TABLE}.latitude ;;
sql_longitude: ${TABLE}.longitude ;;
group_label: "Block Group"
suggest_persist_for: "120 hours"
}
measure: sq_miles_land {
sql: ${TABLE}.square_miles_land ;;
label: "Square Miles of Land"
type: sum
value_format_name: decimal_2
}
measure: sq_miles_water {
sql: ${TABLE}.square_miles_water ;;
label: "Square Miles of Water"
type: sum
value_format_name: decimal_2
}
# measure: count_block {
# type: count_distinct
# sql: ${block_group} ;;
# drill_fields: [tract_name, data.default_drills*]
# }
#
#
# set: geo_drills {
# fields: [count_state, count_county, count_tract, block_group]
# }
}