Merge multiple polylines, in the order that they were passed in.
    Merged polyline will have the names of their component parts joined by ';'.
    Example: merging [a,b], [c,d] and [e,f] will result in [a,b,c,d,e,f].
    However if the endpoints of two adjacent polylines are less than
    merge_point_threshold meters apart, we will only use the first endpoint in
    the merged polyline.

def MergePolys(polys, merge_point_threshold=10):
    """
    Merge multiple polylines, in the order that they were passed in.
    Merged polyline will have the names of their component parts joined by ';'.
    Example: merging [a,b], [c,d] and [e,f] will result in [a,b,c,d,e,f].
    However if the endpoints of two adjacent polylines are less than
    merge_point_threshold meters apart, we will only use the first endpoint in
    the merged polyline.
    """
    name = ";".join((p.GetName(), '')[p.GetName() is None] for p in polys)
    merged = Poly([], name)
    if polys:
      first_poly = polys[0]
      for p in first_poly.GetPoints():
        merged.AddPoint(p)
      last_point = merged._GetPointSafe(-1)
      for poly in polys[1:]:
        first_point = poly._GetPointSafe(0)
        if (last_point and first_point and
            last_point.GetDistanceMeters(first_point) <= merge_point_threshold):
          points = poly.GetPoints()[1:]
        else:
          points = poly.GetPoints()
        for p in points:
          merged.AddPoint(p)
        last_point = merged._GetPointSafe(-1)
    return merged