Skip to content

Commit b3420a3

Browse files
committed
Agent/MB first light: test.html
- test.html: - add hello model - add view - add features info to patches - add World.bbox transform - add geo coords to patches - add turtle's current hover feature - animate - tools.js: moved utils from test.html into separate file - bin/addFeatureID: use state + county fips rather than index - bin/addPopulation: new, merge population data into nmcounties.json - bin/redfish2pop: new, convert steve's csv to json - data/nmpopulation.json: json file made from redfish2pop - data/nmcounties.json: add population from above, use fips id - data/uscounties.json: use fips id
1 parent a24bd7a commit b3420a3

File tree

10 files changed

+3677
-3283
lines changed

10 files changed

+3677
-3283
lines changed

bin/addFeatureID

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ process.stdin.on('end', () => {
1616
function processData(data) {
1717
const json = JSON.parse(data)
1818
json.features.forEach((feature, i) => {
19-
feature.id = i
19+
feature.id = feature.properties.STATE + feature.properties.COUNTY
2020
})
2121
return JSON.stringify(json, null, 2)
2222
}

bin/addPopulation

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
const shell = require('shelljs')
4+
5+
// shell.cp('data/nmcounties.json', 'data0/')
6+
const geojsonFile = 'data/nmcounties.json'
7+
8+
// bkup:
9+
// shell.cp(geojsonFile, '/tmp')
10+
11+
const population = JSON.parse(shell.cat('data/nmpopulation.json'))
12+
const geojson = JSON.parse(shell.cat(geojsonFile))
13+
const features = geojson.features
14+
15+
const numPopulation = Object.keys(population).length
16+
const numFeatures = features.length
17+
if (numPopulation != numFeatures) {
18+
console.log(
19+
Object.keys(population),
20+
features.map(c => c.id)
21+
)
22+
throw `size mismatch: ${numPopulation} ${numFeatures}`
23+
}
24+
25+
features.forEach(feature => {
26+
const id = feature.id
27+
if (!population[id]) console.log('id', id, 'not in population.')
28+
feature.properties.population = population[feature.id].population
29+
})
30+
31+
shell.echo(JSON.stringify(geojson, null, 2))

bin/redfish2pop

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
const process = require('process')
4+
5+
let data = ''
6+
process.stdin.on('readable', () => {
7+
while ((chunk = process.stdin.read()) !== null) {
8+
data += chunk
9+
}
10+
})
11+
12+
process.stdin.on('end', () => {
13+
process.stdout.write(processData(data))
14+
})
15+
16+
function processData(data) {
17+
const json = JSON.parse(data)
18+
19+
// ================
20+
const obj = {}
21+
json.forEach(o => {
22+
const fips = '35' + o['cowntee_CO']
23+
obj[fips] = {
24+
fips: fips,
25+
county: o['cowntee_NA'],
26+
population: o['popul_byco'],
27+
}
28+
})
29+
// ================
30+
31+
return JSON.stringify(obj, null, 2)
32+
}
33+
34+
// {
35+
// "fips_code": "02016",
36+
// "State": "AK",
37+
// "County Name": "Aleutians West",
38+
// "Staffed All Beds": 0,
39+
// "Staffed ICU Beds": 0,
40+
// "Licensed All Beds": 0,
41+
// "All Bed Occupancy Rate": "",
42+
// "ICU Bed Occupancy Rate": "",
43+
// "Population": 5723,

data/nmcounties.json

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

data/nmpopulation.json

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"35001": {
3+
"fips": "35001",
4+
"county": "Bernalillo",
5+
"population": 677692
6+
},
7+
"35003": {
8+
"fips": "35003",
9+
"county": "Catron",
10+
"population": 3539
11+
},
12+
"35005": {
13+
"fips": "35005",
14+
"county": "Chaves",
15+
"population": 65459
16+
},
17+
"35006": {
18+
"fips": "35006",
19+
"county": "Cibola",
20+
"population": 26978
21+
},
22+
"35007": {
23+
"fips": "35007",
24+
"county": "Colfax",
25+
"population": 12353
26+
},
27+
"35009": {
28+
"fips": "35009",
29+
"county": "Curry",
30+
"population": 50199
31+
},
32+
"35011": {
33+
"fips": "35011",
34+
"county": "De Baca",
35+
"population": 2060
36+
},
37+
"35013": {
38+
"fips": "35013",
39+
"county": "Dona Ana",
40+
"population": 215338
41+
},
42+
"35015": {
43+
"fips": "35015",
44+
"county": "Eddy",
45+
"population": 57437
46+
},
47+
"35017": {
48+
"fips": "35017",
49+
"county": "Grant",
50+
"population": 28061
51+
},
52+
"35019": {
53+
"fips": "35019",
54+
"county": "Guadalupe",
55+
"population": 4382
56+
},
57+
"35021": {
58+
"fips": "35021",
59+
"county": "Harding",
60+
"population": 459
61+
},
62+
"35023": {
63+
"fips": "35023",
64+
"county": "Hidalgo",
65+
"population": 4371
66+
},
67+
"35025": {
68+
"fips": "35025",
69+
"county": "Lea",
70+
"population": 70126
71+
},
72+
"35027": {
73+
"fips": "35027",
74+
"county": "Lincoln",
75+
"population": 19482
76+
},
77+
"35028": {
78+
"fips": "35028",
79+
"county": "Los Alamos",
80+
"population": 18356
81+
},
82+
"35029": {
83+
"fips": "35029",
84+
"county": "Luna",
85+
"population": 24264
86+
},
87+
"35031": {
88+
"fips": "35031",
89+
"county": "McKinley",
90+
"population": 72849
91+
},
92+
"35033": {
93+
"fips": "35033",
94+
"county": "Mora",
95+
"population": 4563
96+
},
97+
"35035": {
98+
"fips": "35035",
99+
"county": "Otero",
100+
"population": 65745
101+
},
102+
"35037": {
103+
"fips": "35037",
104+
"county": "Quay",
105+
"population": 8373
106+
},
107+
"35039": {
108+
"fips": "35039",
109+
"county": "Rio Arriba",
110+
"population": 39307
111+
},
112+
"35041": {
113+
"fips": "35041",
114+
"county": "Roosevelt",
115+
"population": 19117
116+
},
117+
"35043": {
118+
"fips": "35043",
119+
"county": "Sandoval",
120+
"population": 140769
121+
},
122+
"35045": {
123+
"fips": "35045",
124+
"county": "San Juan",
125+
"population": 127455
126+
},
127+
"35047": {
128+
"fips": "35047",
129+
"county": "San Miguel",
130+
"population": 28034
131+
},
132+
"35049": {
133+
"fips": "35049",
134+
"county": "Santa Fe",
135+
"population": 148917
136+
},
137+
"35051": {
138+
"fips": "35051",
139+
"county": "Sierra",
140+
"population": 11135
141+
},
142+
"35053": {
143+
"fips": "35053",
144+
"county": "Socorro",
145+
"population": 17000
146+
},
147+
"35055": {
148+
"fips": "35055",
149+
"county": "Taos",
150+
"population": 32888
151+
},
152+
"35057": {
153+
"fips": "35057",
154+
"county": "Torrance",
155+
"population": 15595
156+
},
157+
"35059": {
158+
"fips": "35059",
159+
"county": "Union",
160+
"population": 4175
161+
},
162+
"35061": {
163+
"fips": "35061",
164+
"county": "Valencia",
165+
"population": 75956
166+
}
167+
}

data/uscounties.json

Lines changed: 3221 additions & 3221 deletions
Large diffs are not rendered by default.

notes.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Commits:
44
......................................................................
55
......................................................................
66
......................................................................
7+
turf.distance([west,north], [east, south])
8+
test rel to gis module
9+
710
......................................................................
811
is geojson fetchable from mb layers?
912
Canvas BBox: Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the image. The coordinates start at the top left corner of the image and proceed in clockwise order. They do not have to represent a rectangle.
@@ -16,6 +19,8 @@ Canvas BBox: Four geographical coordinates, represented as arrays of longitude a
1619

1720
......................................................................
1821
todo
22+
- solve async problem w/ node stdin/out
23+
- update addPopulation to use stdin/out, po
1924
- states: finer detail
2025
- usstates.geojson 87K, us_040_00_20m.json 1.4MB, 5m 2.4MB?
2126
- counties: featureState seems backwards!
@@ -93,13 +98,35 @@ https://catalog.data.gov/dataset
9398
https://simplemaps.com/data
9499
https://simplemaps.com/data/us-cities
95100
https://eric.clst.org/tech/usgeojson/
101+
https://data.census.gov/cedsci/
96102
https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html
97103
https://github.com/mapbox/mapboxgl-jupyter
98104
https://github.com/mapbox/mapboxgl-jupyter/blob/master/examples/data/us-states.geojson
99105
https://github.com/plotly/datasets
100106
https://mygeodata.cloud/
101107

108+
Oops:
109+
- 3193 entries in co-est2019-alldata.csv, 51 are states!
110+
grep 'COUNTY": "000"' data0/co-est2019-alldata.json| wc -l
111+
51
112+
- 3221 in uscounties.json. Multi-poly states?
113+
- id may not be unique now?
114+
- nope: this produces 3221
115+
grep '"id"' data/uscounties.json | \
116+
sed 's/^.*"id"://;s/^"//;s/".*//' | \
117+
sort | uniq | wc
118+
no states, this produces no output:
119+
grep '"id"' data/uscounties.json |
120+
sed 's/^.*"id"://;s/^"//;s/".*//' |
121+
sort | uniq | grep '..000'
122+
population check:
123+
grep population data/nmpopulation.json | sed 's/^.*://;s/$/,/'
124+
pop = [677692, 3539, 65459, 26978, 12353, 50199, 2060, 215338, 57437, 28061, 4382, 459, 4371, 70126, 19482, 18356, 24264, 72849, 4563, 65745, 8373, 39307, 19117, 140769, 127455, 28034, 148917, 11135, 17000, 32888, 15595, 4175, 75956]
125+
util.arraySum(pop) => 2092434
126+
127+
102128
http://census.ire.org/data/bulkdata.html
129+
https://wiki.openstreetmap.org/wiki/United_States/American_Indian_reservations
103130

104131
bbox spec: https://tools.ietf.org/html/rfc7946
105132

@@ -139,6 +166,11 @@ usstates.geojson uscounties.json:
139166
https://eric.clst.org/tech/usgeojson/
140167
states:
141168
agentscript/bin/minifyjson
169+
population covid19-healthsystemcapacity/data/published/us_healthcare_capacity-county-CovidCareMap.csv
170+
https://github.com/mapbox/csv2geojson for csv => geojson
171+
https://csvjson.com/ csv to json, not geojson. Useful!
172+
co-est2019-alldata.csv -> .json
173+
nm pop, from https://github.com/RedfishGroup/GISData/blob/master/popul_byco2018_fromDBF.csv
142174

143175
Sociall Vulnerability Index
144176
https://svi.cdc.gov/data-and-tools-download.html
@@ -187,6 +219,20 @@ gitcommit
187219

188220
//////////
189221

222+
Agent/MB first light: test.html
223+
test.html:
224+
- add hello model
225+
- bin/addFeatureID: use state + county fips rather than index
226+
- bin/addPopulation: new, merge population data into nmcounties.json
227+
- bin/redfish2pop: new, convert steve's csv to json
228+
229+
230+
231+
New: test.html: NM counties & MB CanvasSource
232+
- bin/tools: async: mapLoadPromise(map)
233+
- async.html: test of above
234+
- bin/featureFilter (nmcounties etc from uscounties etc)
235+
190236
New: counties.html popup while hovering counties
191237
- counties.html: add popup for county names
192238
- data0/: gitignored dir of original data before modified for MB use

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
"cities": "npm-run-all citiesjson citiesjson",
1818
"states": "agentscript/bin/minifyjson < data0/gz_2010_us_040_00_20m.json > data/usstates.geojson",
1919
"fips": "bin/fips2json < data/fips.txt > data/fips.json",
20+
"countyIDs": "bin/addFeatureID < data/uscounties.json > /tmp/foo.json; agentscript/bin/minifyjson < /tmp/foo.json > data/uscounties.json",
2021
"nmcounties": "bin/featureFilter STATE:35 < data/uscounties.json | agentscript/bin/minifyjson > data/nmcounties.json",
22+
"nmPopulation": "bin/redfish2pop < data0/popul_byco2018_fromDBF.json > data/nmpopulation.json",
23+
"addPopulation": "bin/addPopulation | agentscript/bin/minifyjson > /tmp/nmcounties.json; cp /tmp/nmcounties.json data",
24+
"pop": "bin/addPopulation | agentscript/bin/minifyjson > /tmp/nmcounties.json",
2125
"foo": "mapshaper -h"
2226
},
2327
"dependencies": {

0 commit comments

Comments
 (0)