I have 2 GeoDataFrames 100 records each, and want to calculate distances between respective geometries (Points, of course).
I can't see how to make it other than write a cycle to iterate rows directly. (It seems that something changed since summer, when GeoPandas 0.4 was realeased.)
Here are the ways I used to do it:
Option 1: I assign another column. Now it sometimes turns all
main_df['geometry_other'] = other_df['geometry'] main_df['dist'] = main_df.apply(lambda r: r['geometry'].distance(r['geometry_other']), axis=1) main_df.drop('geometry_other', axis=1, inplace=True)
Option 2: I join the 2 geodataframes and do the same. Same way, it turns
main_df = main_df.join(other_df, rsuffix='_other') # then same as before
Option 3: Here's what I came up with now, after posting the question. I still don't like the repetitive
.tolist() on both sides.
main_df['match_distance'] = [a.distance(b) for a, b in zip(main_df['geometry'].tolist(), other_df['geometry'].tolist())]
What are the options now to do this?