Last active
November 2, 2020 06:13
-
-
Save databyjp/c4c8daae63081bfac7ee0c517dd04998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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