maps.chandlerswift.com/layers/census-bureau/cleanup_data.py

48 lines
2 KiB
Python

#!/usr/bin/python3
import sys
import json
with open(sys.argv[1]) as f:
data = json.load(f)
# {
# "type": "FeatureCollection",
# "name": "cb_2022_us_county_20m",
# "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
# "features": [
# {
# "type": "Feature",
# "properties": {
# "Name": "<at><openparen>Autauga<closeparen>",
# "Description": "<center><table><tr><th colspan='2' align='center'><em>Attributes</em></th></tr><tr bgcolor=\"#E3E3F3\"> <th>STATEFP</th> <td>01</td> </tr><tr bgcolor=\"\"> <th>COUNTYFP</th> <td>001</td> </tr><tr bgcolor=\"#E3E3F3\"> <th>COUNTYNS</th> <td>00161526</td> </tr><tr bgcolor=\"\"> <th>AFFGEOID</th> <td>0500000US01001</td> </tr><tr bgcolor=\"#E3E3F3\"> <th>GEOID</th> <td>01001</td> </tr><tr bgcolor=\"\"> <th>NAME</th> <td>Autauga</td> </tr><tr bgcolor=\"#E3E3F3\"> <th>NAMELSAD</th> <td>Autauga County</td> </tr><tr bgcolor=\"\"> <th>STUSPS</th> <td>AL</td> </tr><tr bgcolor=\"#E3E3F3\"> <th>STATE_NAME</th> <td>Alabama</td> </tr><tr bgcolor=\"\"> <th>LSAD</th> <td>06</td> </tr><tr bgcolor=\"#E3E3F3\"> <th>ALAND</th> <td>1539631461</td> </tr><tr bgcolor=\"\"> <th>AWATER</th> <td>25677536</td> </tr></table></center>"
# },
# "geometry": {
# "type": "Polygon",
# "coordinates": [
# [
# [
# -86.917595,
# 32.664169,
# 0.0
# ],
# ...
# ]
# ]
# }
# },
# [...]
# ]
# }
# len("<at><openparen>") == 15
# len("<closeparen>") == 12
# "<at><openparen>Autauga<closeparen>"[15:-12] == "Autauga"
for feature in data['features']:
# del feature['properties']['Description']
feature['properties']['Name'] = feature['properties']['Name'][15:-12]
with open(sys.argv[1], 'w') as f:
json.dump(data, f)