I have a layer with 7000 LineStrings, all represent bus routes: Bus routes

It seems that all the bus routes are contiguous, but I'm not sure of it. I'm trying to use python shapely to dissolve all those LineStrings but I get the following errors:

TopologyException: found non-noded intersection between LINESTRING (193929 -48233.6, 193930 -48234) and LINESTRING (193930 -48233.8, 193930 -48234) at 193929.98210726795 -48233.983282576017 ... ValueError: No Shapely geometry can be created from null value

This is my code:

with fiona.open(src, 'r') as ds_in:
    crs = ds_in.crs
    drv = ds_in.driver

    #combine lines into multiString
    lines = []
    for feature  in ds_in:
        geom = geometry.shape(feature['geometry'])
        if geom is not None and geom.is_valid:

    dissolved = ops.unary_union(lines

I'm trying to understand whether the TopologyException is critical and why I get the error after that. When printing the geometries, I don't see Nulls or missing data.

Other posts deal with polygons, but with linestring a buffer isn't an applicable solution.

  • 1
    This is actually a GEOS issue to do with coordinates having spurious precision. Look at the snap function for a possible solution. – John Powell Apr 18 at 14:30
  • I don't really understand how the snap function can help here. It can help with attaching points to lines, but how can it be a part of the dissolve process of thousands of lines? – Shakedk Apr 21 at 7:14
  • Because merging lines together involves finding intersections. The error TopologyException: found non-noded intersection between typically occurs during intersection routines. Snap reduces the precision of coordinates, which often (but, not always) solves this problem. The data set is small enough that I would think you could try this out quite easily. The coordinate 193929.98210726795 is enough to locate an atom at the Bersheeba bus stop, so I think you will probably be safe loosing a few decimal places :-) – John Powell Apr 21 at 13:15

Your Answer

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

Browse other questions tagged or ask your own question.