I am having a problem with checking attribute condition whether the attributes match in two separate dataframes and then applying spatial join.
Little background: I have two dataframes. DF1 = digitised is with 138 rows and a common field called road_id. DF2 = buffer_dissolved which has only 4 rows and a common field called road_id.
i think it could have been done with following code if they both had same records but its not the case here.
np.where(digitised['road_id'] == buffer_dissolved['road_id'], 'True', 'False')
Now the workaround is I apply spatial join first and then check conditional comparison whether both have same road_id or not but this is not exactly what i want.
Partial working
sj = gpd.sjoin(digitised, buffer_dissolved, how='left', predicate='within', lsuffix='D', rsuffix='B')
failed attempts include: trying isin, ==. also tried converting buffer_dissolved dataframe to gpd.Series but no luck
broken code:
#sj=gpd.GeoDataFrame(crs=digitised.crs)
for row in digitised.itertuples():
if row['road_id'].isin(buffer_dissolved['road_id']):
sj = gpd.sjoin(digitised, buffer_dissolved, how='left', predicate='within', lsuffix='D', rsuffix='B')
#sj.to_file('something.shp')
p.s: dont flag it for duplicate question as its nature is different. both dataframes are having diff field names and different number of records so merge, concat etc cant be applied