Once you have line and polygon geometries, intersection using Shapely is very straight forward. What I did after that is to integrate all the looped 'intersected' geometries into a MultiLineString.

Now my query is, while mapping the MultiLineString using Fiona, the output is a single geometry, with a single attribute. If I could add individual attributes to each intersection geometry result, my MultiLineString would consist of multiple geometries.

How do I add a property or attribute to a LineString once the geometry is ready???

This problem is with reference to previous issues.

Step One - Vertical Lines in a Polygon Shapefile

Step Two - Clipping Line shapefiles to within the Extent of Polygon

The reason why I am doing this is because once I have the geometries of all the clipped lines, I need to extract the Node coordinates of each of them.

1 Answer 1


Shapely geometries are python classes, so you can simply set a new property in the object.

For my use-cases this has worked, though it may be worth checking for unintended side-effects depending on your scenario.

from shapely import geometry

p = geometry.Point(0, 0)
p.uid = 'unique point'
print(p.uid)  # prints: 'unique point'
  • 4
    This answer should be updated sometime because this will no longer work in Shapely 2.0. See discussion here. One method is to use the id of the shapely object in an auxiliary dictionary as explained in the Note section here. Oct 18, 2021 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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