Create sf object from two-column matrix

You can use the sfheaders library on matrices directly

sfheaders::sf_point(m)

# Simple feature collection with 5 features and 0 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: 0.2875775 ymin: 0.0455565 xmax: 0.9404673 ymax: 0.892419
# epsg (SRID):    NA
# proj4string:    NA
# geometry
# 1 POINT (0.2875775 0.0455565)
# 2 POINT (0.7883051 0.5281055)
# 3  POINT (0.4089769 0.892419)
# 4  POINT (0.8830174 0.551435)
# 5 POINT (0.9404673 0.4566147)

As per the sf docs

m %>% 
  as.data.frame %>% 
  sf::st_as_sf(coords = c(1,2))

Tags:

R

Sf