(line, splitter)
Split a LineString with another (Multi)LineString or (Multi)Polygon
Split a LineString with another (Multi)LineString or (Multi)Polygon
Split a LineString with another ( Multi ) LineString or ( Multi ) Polygon
def _split_line_with_line(line, splitter):
        """Split a LineString with another (Multi)LineString or (Multi)Polygon"""

        # if splitter is a polygon, pick it's boundary
        if splitter.type in ('Polygon', 'MultiPolygon'):
            splitter = splitter.boundary

        assert(isinstance(line, LineString))
        assert(isinstance(splitter, LineString) or isinstance(splitter, MultiLineString))

        if splitter.crosses(line):
            # The lines cross --> return multilinestring from the split
            return line.difference(splitter)
        elif splitter.relate_pattern(line, '1********'):
            # The lines overlap at some segment (linear intersection of interiors)
            raise ValueError('Input geometry segment overlaps with the splitter.')
        else:
            # The lines do not cross --> return collection with identity line
            return [line]
def _split_line_with_line ( line , splitter ) : # if splitter is a polygon, pick it's boundary if splitter . type in ( 'Polygon' , 'MultiPolygon' ) : splitter = splitter . boundary assert ( isinstance ( line , LineString ) ) assert ( isinstance ( splitter , LineString ) or isinstance ( splitter , MultiLineString ) ) if splitter . crosses ( line ) : # The lines cross --> return multilinestring from the split return line . difference ( splitter ) elif splitter . relate_pattern ( line , '1********' ) : # The lines overlap at some segment (linear intersection of interiors) raise ValueError ( 'Input geometry segment overlaps with the splitter.' ) else : # The lines do not cross --> return collection with identity line return [ line ]