# Get points within maximum distance from any point in GeoPandas

Given a set of points (with meters coordinates), I am trying to create lines between them. But I don't want to create lines of each pair of points, Iwant to create thoses lines if the distance between two points is inferior or equal to a threshold value (let's say 1000m).

And from there, I am quite lost. The `distance()` function only returns a `GeoSerie` of the points with themselves, so all my values are at `0.0`. I am also facing issues with the `buffer()` function, not knowing how to properly use the `GeoSerie` result once computed.

From what I tested so far:

• `intersection()` returns a `GeoSerie` with only one reference,
• `sjoin` does not work with `GeoSeries`
• converting the buffer `GeoSerie` to a `GeoDataFrame` results in `AttributeError: No geometry data set yet (expected in column 'geometry'`

Assuming you have one geoseries with Points (for example you want to compare Point 1 to Point 2, Point 1 to Point 3,... ):

``````import geopandas as gpd
from itertools import combinations
from shapely.geometry import LineString

series = df.geometry
max_distance = 15000

points_within = []
for i1,i2 in combinations(range(0,series.shape-1),2):  #Iterate over all pairs/combinations of indices
if 0<series[i1].distance(series[i2])<=max_distance:
points_within.append([series[i1],series[i2]])

geoms = [LineString(pointpair) for pointpair in points_within]
df2 = gpd.GeoDataFrame(geometry=gpd.GeoSeries(geoms)) 