Per the comparison to spaghetti and pysal.lib.weights, see if those are helpful. But also see scipy.spatial.KDTree directly.
The main issue is that these will not work out of the box, for point to polygon distances.
The way I would work is:
[x] If it's point to point:
[x] Merge on a dummy column (i.e., df1["_tmp"] = 1 and then df2["_tmp"] = 1), so that is available for both sides of the merge. This will give you and N × M frame.
[x] Re-merge the right-hand geometry, if it gets dropped in the merge, or handle the geometries. Calculate the distances from one geometry to the other df.distance(df.set_geometry(geo2) and return that.
[x] If it's point to polygon or otherwise:
[x] geopandas.sjoin of the origin to a buffer of the other, if there is a maximum threshold. If there isn't just do the naïve/featureless/dummy merge, above.
In other words, this function.
Per the comparison to spaghetti and pysal.lib.weights, see if those are helpful. But also see scipy.spatial.KDTree directly.
The main issue is that these will not work out of the box, for point to polygon distances.
The way I would work is:
df1["_tmp"] = 1
and thendf2["_tmp"] = 1
), so that is available for both sides of the merge. This will give you and N × M frame.df.distance(df.set_geometry(geo2)
and return that.