Skip to content

Instantly share code, notes, and snippets.

@databyjp
Last active November 2, 2020 06:13
Show Gist options
  • Save databyjp/c4c8daae63081bfac7ee0c517dd04998 to your computer and use it in GitHub Desktop.
Save databyjp/c4c8daae63081bfac7ee0c517dd04998 to your computer and use it in GitHub Desktop.
county_data_list = list()
for tmp in counties["features"]:
tmp_fips = tmp["id"]
if tmp["geometry"]["type"] == 'Polygon':
tmp_crds = tmp["geometry"]["coordinates"][0]
elif tmp["geometry"]["type"] == 'MultiPolygon':
tmp_crds = tmp["geometry"]["coordinates"][0][0]
else:
logger.warning("Check geometry type")
x_crds = [i[0] for i in tmp_crds]
y_crds = [i[1] for i in tmp_crds]
center_crds = [(min(x_crds)+max(x_crds))/2, (min(y_crds)+max(y_crds))/2]
data_dict = {"fips": tmp_fips, "lon": center_crds[0], "lat": center_crds[1]}
county_data_list.append(data_dict)
county_df = pd.DataFrame(county_data_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment