Shapely intersection TopologyException

Hi all,

I have a problem with shapely function “intersection” between polygons.
Many times I obtain the error: “TopologyException: Input geom 0 is invalid: Self-intersection at or near point…” and I would like to pass it without stopping code

I try with try Except but it doesn’t work. I read online about:

from shapely.geos import TopologicalError
try:
    #code
except TopologicalError:
    print("exception")
    pass

I would like print the topological/topology error and pass away if it occurs

Thank you very much
Best Regards

I am late to the party, but for anyone else this may help - I ran into the same issue and resolved it with:

from shapely import errors as se

try:
    #code
except (se.TopologicalError, se.GEOSException, se.ShapelyError, se.DimensionError, se.GeometryTypeError) as error:
    print(error)

Remove the exceptions you do not need. In my case, an error like “GEOSException: TopologyException: Input geom 0 is invalid: Self-intersection at …” is caught with GEOSException and not TopologicalError.

Best Regards