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

Fixed duplicate neighbouring names and ids #35

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Changes from all commits
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
11 changes: 9 additions & 2 deletions mile-point-approach/get_neighbouring_roads.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def group_and_aggregate(df: pd.DataFrame) -> gpd.GeoDataFrame:
Group by geometry and aggregate specified columns.

Args:
df (pd.DataFrame): Input DataFrame.
df (pd.DataFrame): Input DataFrame.

Returns:
gpd.GeoDataFrame: Grouped and aggregated GeoDataFrame.
Expand All @@ -216,10 +216,14 @@ def group_and_aggregate(df: pd.DataFrame) -> gpd.GeoDataFrame:
GroupingError: If there's an error during grouping and aggregation.
"""
try:
grouped = df.groupby(['geometry', 'created_unique_id_1_left', 'bridge_id_left']).agg({

#Spatial join sometimes gives same rows within a buffer, so drop duplicates
drop_duplicates_cols=['geometry', 'created_unique_id_1_left', 'bridge_id_left','created_unique_id_1_right','RD_NAME_right']
grouped = df[drop_duplicates_cols].drop_duplicates().groupby(['geometry', 'created_unique_id_1_left', 'bridge_id_left']).agg({
'created_unique_id_1_right': lambda x: ', '.join(x.astype(str)),
'RD_NAME_right': lambda x: ', '.join(x.astype(str)),
}).reset_index()

return gpd.GeoDataFrame(grouped, geometry='geometry', crs=df.crs)
except KeyError as e:
logger.error(f"Grouping error: missing column {str(e)}")
Expand Down Expand Up @@ -284,6 +288,9 @@ def load_and_transform_data() -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]:
osm_road_points = read_geopackage(FilePath.OSM_ROAD_POINTS.value)
state_road = read_geopackage(FilePath.STATE_ROAD.value)

#Change 'NAME' to column name that contains road names from state_road dataset, if its RD_NAME then no need to change
# state_road.rename(columns={'NAME':'RD_NAME'}, inplace=True)

logger.info(f"OSM Road Points CRS: {osm_road_points.crs}")
logger.info(f"State Road CRS: {state_road.crs}")

Expand Down