title: Geopandas - split lines at intersection with polygons, retain polygon ID in new link attributes
body: <p>I have two geodataframes: one containing many Linestrings, and another containing many Polygons. These lines and polygons intersect each other. The output I am trying to achieve is a new geodataframe containing links which have been split at any location that they intersect a polygon. </p>
  
  <p>Simplified test code is as follows:</p>
  
  <pre><code>import geopandas
  from shapely.geometry import Polygon, LineString
  
  #Create geodataframe containing 2 links:
  linkID = ['1','2']
  link_geom = [LineString([(0, 0), (10, 10)]),LineString([(10, 10), (20, 10)])]
  a = {'linkID':linkID,'geometry':link_geom}
  gdf_links = geopandas.GeoDataFrame(a)
  
  #Create geodataframe containing 2 polygons:
  polyID = ['100','200']
  poly_geom = [Polygon([(2, 1), (2, 3), (4, 3), (4, 1)]),Polygon([(15, 7), (15, 13), (18, 13), (18, 7)])]
  b = {'polyID':polyID,'geometry':poly_geom}
  gdf_poly = geopandas.GeoDataFrame(b)
  </code></pre>
  
  <p>You can see that the lines intersect the polygons by running the following code:</p>
  
  <pre><code>links = gdf_links.unary_union
  polys = gdf_poly.unary_union
  geopandas.GeoSeries([links,polys]).plot(cmap='tab10')
  </code></pre>
  
  <p>Which generates the following figure (annotation added in red/green to show the various elements involved):</p>
  
  <p><a href="https://i.stack.imgur.com/5Jam2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Jam2.jpg" alt="enter image description here"></a></p>
  
  <p>Splitting the two lines wherever they intersect a polgyon will results in 6 segments (as labelled in green in the figure above).</p>
  
  <p>Ideally, the output I would like to achieve is something like shown below, with a 'poly_intersect' column listing the ID of the polygon at which the split has occurred. Note that items 2 and 5 list two polygon ID's, because they intersect the polygon twice. </p>
  
  <p><a href="https://i.stack.imgur.com/loJwr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/loJwr.jpg" alt="enter image description here"></a></p>