Skip to content

Commit

Permalink
use pd.merge on GIDs to map between gpkg and geojson dfs (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Jan 3, 2025
2 parents 15ff8f0 + 44f8c8c commit fa0894b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pygadm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,14 @@ def _items(self, name: str = "", admin: str = "", content_level: int = -1) -> gp
for i in range(int(content_level) + 1):
level_gdf.loc[:, f"NAME_{i}"] = complete_df[f"NAME_{i}"].values

gdf = level_gdf[level_gdf[column.format(level)].str.fullmatch(id, case=False)]
df_list = [Names(admin=iso, content_level=content_level, complete=True) for iso in isos]
complete_df = pd.concat(df_list)
# GID columns to merge on; they (should) match exactly
shared_cols = [f"GID_{i}" for i in range(int(content_level) + 1)]
# Camel-case columns to drop
drop_cols = [f"NAME_{i}" for i in range(int(content_level) + 1)]
gdf = pd.merge(level_gdf.drop(drop_cols, axis=1), complete_df,
how='inner', on=shared_cols)

return gdf

Expand Down

0 comments on commit fa0894b

Please sign in to comment.