Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created May 30, 2020 20:16
Show Gist options
  • Save mhweber/b3d44434daae64a520932b4181279ebc to your computer and use it in GitHub Desktop.
Save mhweber/b3d44434daae64a520932b4181279ebc to your computer and use it in GitHub Desktop.
Derive endpoints for spatial lines in sf
#Create linestring
line <- st_as_sfc(c("LINESTRING(0 0 , 0.5 1 , 1 1 , 1 0.3)")) %>%
st_sf(ID = "poly1")
#Convert each vertex to point
pt <- st_cast(line, "POINT")
# Grab start or end point:
start <- pt[1,]
end <- pt[nrow(pt),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment