Skip to content

Commit

Permalink
Rename "District of Columbia" to "Washington DC" (#95)
Browse files Browse the repository at this point in the history
* [create-pull-request] update data submodule

* update and rerun `create_survey_geojson.py`

---------

Co-authored-by: alyssadai <65699389+alyssadai@users.noreply.github.com>
  • Loading branch information
michellewang and alyssadai authored Sep 23, 2024
1 parent 80cbefd commit 6771c1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions code/assets/survey_states.json
Original file line number Diff line number Diff line change
Expand Up @@ -13731,9 +13731,9 @@
},
{
"type": "Feature",
"id": "Delaware, District of Columbia, Maryland (Cluster C)",
"id": "Delaware, Washington DC, Maryland (Cluster C)",
"properties": {
"name": "Delaware, District of Columbia, Maryland (Cluster C)"
"name": "Delaware, Washington DC, Maryland (Cluster C)"
},
"geometry": {
"type": "MultiPolygon",
Expand Down
12 changes: 12 additions & 0 deletions code/create_survey_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
# path to generic US states GeoJSON file
FPATH_STATES_JSON_DEFAULT = DPATH_ASSETS / "us_states.json"

# for overriding state names in generic US states GeoJSON file
CUSTOM_STATE_NAME_MAP_DEFAULT = {
"District of Columbia": "Washington DC",
}

# path to output GeoJSON file
FPATH_OUT_DEFAULT = DPATH_ASSETS / "survey_states.json"


def create_survey_geojson(
survey_states_and_clusters: Iterable[str],
fpath_states_json: Path | str = FPATH_STATES_JSON_DEFAULT,
custom_state_name_map: Optional[dict] = CUSTOM_STATE_NAME_MAP_DEFAULT,
fpath_out: Optional[Path | str] = FPATH_OUT_DEFAULT,
) -> dict:
"""Create a GeoJSON file for the states and state clusters used in the survey.
Expand All @@ -35,6 +41,8 @@ def create_survey_geojson(
Path to GeoJSON file with standard US states.
By default, will use the one that was
downloaded from https://github.com/PublicaMundi/MappingAPI/blob/master/data/geojson/us-states.json.
custom_state_name_map : dict, optional
Mapping of state names in the original GeoJSON file to state names in survey_states_and_clusters.
fpath_out : Path | str, optional
Path to output GeoJSON file.
Expand Down Expand Up @@ -65,6 +73,10 @@ def create_survey_geojson(
info["properties"]["name"]: info for info in states_json["features"]
}

# apply custom renaming map
for old_state_name, new_state_name in custom_state_name_map.items():
state_info_map[new_state_name] = state_info_map.pop(old_state_name)

# split into clusters and states
survey_clusters = [
state for state in survey_states_and_clusters if "Cluster" in state
Expand Down
2 changes: 1 addition & 1 deletion data
Submodule data updated from 28bc72 to 32bb92

0 comments on commit 6771c1a

Please sign in to comment.