I have a list of shapely LineString,

[<shapely.geometry.linestring.LineString object at 0x000001614D750CC0>, <shapely.geometry.linestring.LineString object at 0x000001614D750D68>, <shapely.geometry.linestring.LineString object at 0x000001614D750D30>]

and List of point geometry which are the mid-points of the Linestrings;

[<shapely.geometry.point.Point object at 0x000001614DC0D518>, <shapely.geometry.point.Point object at 0x000001614DC0D4E0>, <shapely.geometry.point.Point object at 0x000001614DCF9CC0>]

How to return Linestring on selecting its midpoint from the second list?


if your linestring are not crossing each other on the mid points you can simply use intersects method from shapely

for line in lines:
     for point in points:
          if line.intersects(point):
                # you have a match

if the do intersect you can get first the mid points from the linestrings using shapely's method interpolate

mid_point = line.interpolate(0.5, normalized = True)

then you use intersects , note that these methods require that your points are exactly the mid points of your lines, if you're not sure about it you can use a buffer with a tolerance distance ( also available in shapely )

  • I created midpoints of each LineString using interpolate so these midpoints must be within the lineStrings, but intersects returns False.. though in Qgis midpoints are exactly on the line.. What could be possible wrong here? – FJ_Abbasi Aug 21 '17 at 10:38
  • @FJ_Abbasi have you tried the buffer ? if line.intersects(point.buffer(some_value)) – Hicham Zouarhi Aug 21 '17 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.