Это несколько запутанно, поскольку ваши точки не в правильном порядке для создания многоугольника, но это работает. Вероятно, есть более простой ответ, который я пропускаю.
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(tidyverse)
# Your data
my_df <- data.frame(
Plot = c("A", "A", "A", "A", "A", "B", "B", "B", "B", "B"),
Corner = c("SW", "NW", "NE", "SE", "SW2", "SW", "NW", "NE", "SE", "SW2"),
Easting = c(511830, 512230, 512230, 511830, 511830, 511730, 512130, 512130, 511730, 511730),
Northing = c(7550903, 7550903, 7550503, 7550503, 7550903, 7550803, 7550803, 7550403, 7550403, 7550803))
## Create an sf object from your data,
## grouped by 'Plot' column summarise() combines the geomtries by group,
## st_convex_hull() since the points are out of order for a polygon
my_df_sf <- st_as_sf(my_df,
coords = c('Easting', 'Northing')) %>%
st_set_crs(26918) %>%
group_by(Plot) %>%
summarise() %>%
ungroup() %>% # Just in case
st_convex_hull()
## A look at the data as an sf object
my_df_sf
#> Simple feature collection with 2 features and 1 field
#> geometry type: POLYGON
#> dimension: XY
#> bbox: xmin: 511730 ymin: 7550403 xmax: 512230 ymax: 7550903
#> CRS: EPSG:26918
#> # A tibble: 2 x 2
#> Plot geometry
#> <fct> <POLYGON [m]>
#> 1 A ((511830 7550503, 511830 7550903, 512230 7550903, 512230 7550503, 51183…
#> 2 B ((511730 7550403, 511730 7550803, 512130 7550803, 512130 7550403, 51173…
## ggplot2 plot, colored by 'Plot' column
ggplot(my_df_sf) +
geom_sf(aes(color = Plot), fill = NA)
Создано в 2020-04-14 с помощью пакета prex (v0.3.0)