Skip to content Skip to sidebar Skip to footer

Calculate All Distances Between Two Geodataframe (of Points) In Geopandas

This is quite simple case, but I did not find any easy way to do it so far. The idea is to get a set of distances between all the points defined in a GeoDataFrame and the ones defi

Solution 1:

You have to apply over each geometry in first gdf to get distance to all geometric in second gdf.

import geopandas as gpd
import pandas as pd

# random coordinates
gdf_1 = gpd.GeoDataFrame(geometry=gpd.points_from_xy([0, 0, 0], [0, 90, 120]))
gdf_2 = gpd.GeoDataFrame(geometry=gpd.points_from_xy([0, 0], [0, -90]))

gdf_1.geometry.apply(lambda g: gdf_2.distance(g))
      0      1
0    0.0   90.0
1   90.0  180.0
2  120.0  210.0

Post a Comment for "Calculate All Distances Between Two Geodataframe (of Points) In Geopandas"