Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back to all admin levels #37

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions exploration/admin_lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,26 @@ with tempfile.TemporaryDirectory() as temp_dir:
iso3 = row["iso3"]
max_adm_level = row["max_adm_level"]
load_shp_from_azure(iso3, temp_dir, MODE)
gdf = gpd.read_file(f"{temp_dir}/{iso3.lower()}_adm{max_adm_level}.shp")

# Get name column and its language code
name_column = select_name_column(gdf, max_adm_level)
language_code = name_column[-2:]
name_columns = [f"ADM{i}_{language_code}" for i in range(0, max_adm_level + 1)]

# Standardize column names and add language info
new_columns = [x.replace(f"_{language_code}", "_NAME") for x in name_columns]
gdf = gdf.rename(columns=dict(zip(name_columns, new_columns)))
gdf["NAME_LANGUAGE"] = language_code
gdf["ISO3"] = iso3
gdf["ADM_LEVEL"] = max_adm_level

# Keep only relevant columns
matching_cols = [col for col in gdf.columns if col in DEFAULT_COLS]
dfs.append(gdf[matching_cols])

name_columns = []
for admin_level in range(max_adm_level + 1):
gdf = gpd.read_file(f"{temp_dir}/{iso3.lower()}_adm{admin_level}.shp")

# Get name column and its language code
name_column = select_name_column(gdf, admin_level)
language_code = name_column[-2:]
name_columns.append(name_column)

# Standardize column names and add language info
new_columns = [x.replace(f"_{language_code}", "_NAME") for x in name_columns]
gdf = gdf.rename(columns=dict(zip(name_columns, new_columns)))
gdf["NAME_LANGUAGE"] = language_code
gdf["ISO3"] = iso3
gdf["ADM_LEVEL"] = max_adm_level
hannahker marked this conversation as resolved.
Show resolved Hide resolved

# Keep only relevant columns
matching_cols = [col for col in gdf.columns if col in DEFAULT_COLS]
dfs.append(gdf[matching_cols])

df_all = pd.concat(dfs, ignore_index=True)
```
Expand Down
Loading