Skip to content

Is there a function to reverse the order of nodes of "LINESTRING" ?  #1246

@artidataio

Description

@artidataio

Supposed that I have a line with multiple nodes, i.e.:

> line1 <- st_linestring(rbind(c(0,0),c(1,1),c(1,0)))
> line1
LINESTRING (0 0, 1 1, 1 0)

Is there a function to reverse the order of the line's nodes (st_line_reverse)? such that:

> line1Reverse <- st_line_reverse(line1) #hypothetical
> line1Reverse
LINESTRING (1 0, 1 1, 0 0)

Currently my solution is to recalculate the coordinates, and reverse the matrix:

> st_linestring(st_coordinates(line1)[dim(line1)[1]:1,1:2])
LINESTRING (1 0, 1 1, 0 0)

Best Wishes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions