create two points using latitude and longitutde coordinates then using st_cast draw a line connecting the two in r

# Load required packages
library(sf)

# Define the latitude and longitude coordinates for the two points
point1 <- st_point(c(-122.4194, 37.7749))  # Point 1 (Longitude, Latitude)
point2 <- st_point(c(-122.0308, 36.9729))  # Point 2 (Longitude, Latitude)

# Combine the two points into a linestring
line <- st_cast(st_sfc(c(point1, point2)), "LINESTRING")

# Plot the line connecting the two points
plot(st_sfc(line), axes = TRUE)
431 chars
13 lines

related categories

gistlibby LogSnag