docstr: Merges all connected lines from a source
  
  The source may be a MultiLineString, a sequence of LineString objects,
  or a sequence of objects than can be adapted to LineStrings.  Returns a
  LineString or MultiLineString when lines are not contiguous.
docstr_tok: ["Merges","all","connected","lines","from","a","source","The","source","may","be","a","MultiLineString",",","a","sequence","of","LineString","objects",",","or","a","sequence","of","objects","than","can","be","adapted","to","LineStrings",".","Returns","a","LineString","or","MultiLineString","when","lines","are","not","contiguous","."]
code: def linemerge(self, lines, directed=False):
      """Merges all connected lines from a source
  
      The source may be a MultiLineString, a sequence of LineString objects,
      or a sequence of objects than can be adapted to LineStrings.  Returns a
      LineString or MultiLineString when lines are not contiguous.
      """
      source = None
      if getattr(lines, "geom_type", None) == "MultiLineString":
          source = lines
      elif hasattr(lines, "geoms"):
          # other Multi geometries
          source = MultiLineString([ls.coords for ls in lines.geoms])
      elif hasattr(lines, "__iter__"):
          try:
              source = MultiLineString([ls.coords for ls in lines])
          except AttributeError:
              source = MultiLineString(lines)
      if source is None:
          raise ValueError(f"Cannot linemerge {lines}")
      return shapely.line_merge(source, directed=directed)
  
imports: from warnings import warn
  import shapely
  from shapely.algorithms.polylabel import polylabel
  from shapely.errors import GeometryTypeError, ShapelyDeprecationWarning
  from shapely.geometry import GeometryCollection, LineString, MultiLineString, MultiPoint, Point, Polygon, shape
  from shapely.geometry.base import BaseGeometry, BaseMultipartGeometry
  from shapely.geometry.polygon import orient
  from shapely.prepared import prep
label_desc: Use image node_id 4 for calling the CollectionOperator obj's underlying member method code with example usage: obj.linemerge(lines, directed) and returns: shapely