(coords, tolerance, point=False)
return pygeos.linestrings([a, b])
Creates a pygeos line extrapoled in p1->p2 direction.
Creates a pygeos line extrapoled in p1->p2 direction.
Creates a pygeos line extrapoled in p1 - > p2 direction .
def _get_extrapolated_line(coords, tolerance, point=False):
    """
    Creates a pygeos line extrapoled in p1->p2 direction.
    """
    p1 = coords[:2]
    p2 = coords[2:]
    a = p2

    # defining new point based on the vector between existing points
    if p1[0] >= p2[0] and p1[1] >= p2[1]:
        b = (
            p2[0]
            - tolerance
            * math.cos(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
            p2[1]
            - tolerance
            * math.sin(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
        )
    elif p1[0] <= p2[0] and p1[1] >= p2[1]:
        b = (
            p2[0]
            + tolerance
            * math.cos(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
            p2[1]
            - tolerance
            * math.sin(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
        )
    elif p1[0] <= p2[0] and p1[1] <= p2[1]:
        b = (
            p2[0]
            + tolerance
            * math.cos(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
            p2[1]
            + tolerance
            * math.sin(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
        )
    else:
        b = (
            p2[0]
            - tolerance
            * math.cos(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
            p2[1]
            + tolerance
            * math.sin(
                math.atan(
                    math.fabs(p1[1] - p2[1] + 0.000001)
                    / math.fabs(p1[0] - p2[0] + 0.000001)
                )
            ),
        )
    if point:
        return b
    return pygeos.linestrings([a, b])
def _get_extrapolated_line ( coords , tolerance , point = False ) : p1 = coords [ : 2 ] p2 = coords [ 2 : ] a = p2 # defining new point based on the vector between existing points if p1 [ 0 ] >= p2 [ 0 ] and p1 [ 1 ] >= p2 [ 1 ] : b = ( p2 [ 0 ] - tolerance * math . cos ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , p2 [ 1 ] - tolerance * math . sin ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , ) elif p1 [ 0 ] <= p2 [ 0 ] and p1 [ 1 ] >= p2 [ 1 ] : b = ( p2 [ 0 ] + tolerance * math . cos ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , p2 [ 1 ] - tolerance * math . sin ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , ) elif p1 [ 0 ] <= p2 [ 0 ] and p1 [ 1 ] <= p2 [ 1 ] : b = ( p2 [ 0 ] + tolerance * math . cos ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , p2 [ 1 ] + tolerance * math . sin ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , ) else : b = ( p2 [ 0 ] - tolerance * math . cos ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , p2 [ 1 ] + tolerance * math . sin ( math . atan ( math . fabs ( p1 [ 1 ] - p2 [ 1 ] + 0.000001 ) / math . fabs ( p1 [ 0 ] - p2 [ 0 ] + 0.000001 ) ) ) , ) if point : return b return pygeos . linestrings ( [ a , b ] )