Skip to content

Commit

Permalink
Merge pull request #37 from OCHA-DAP/admin-lookup-adjust
Browse files Browse the repository at this point in the history
Revert back to all admin levels
  • Loading branch information
hannahker authored Jan 6, 2025
2 parents 4929412 + 6708c65 commit 5bc3947
Showing 1 changed file with 20 additions and 17 deletions.
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"] = admin_level

# 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

0 comments on commit 5bc3947

Please sign in to comment.