I have successfully fount nearest X,Y point in one GeoPandas data frame to the other X,Y points in the second GeoPandas data frame. My questions is on how to find the second nearest point or (third nearest point if needed). My code is below.
def get_nearest_values(row, other_gdf, point_column='geometry', value_column="geometry"):
"""Find the nearest point and return the corresponding value from specified value column."""
# Create an union of the other GeoDataFrame's geometries:
other_points = other_gdf["geometry"].unary_union
# Find the nearest points
nearest_geoms = nearest_points(row[point_column], other_points)
# Get corresponding values from the other df
nearest_data = other_gdf.loc[other_gdf["geometry"] == nearest_geoms[1]]
nearest_value = nearest_data[value_column].values[0]
return nearest_value
unary_union = df2.unary_union
df1["nearest_tlm"] = df1.apply(get_nearest_values, other_gdf=df2, point_column="geometry", value_column="language", axis=1)
df1