Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R和GIS:将sf对象内的多个GPS坐标列表转换为多边形_R_List_Gis_Polygon_Sf - Fatal编程技术网

R和GIS:将sf对象内的多个GPS坐标列表转换为多边形

R和GIS:将sf对象内的多个GPS坐标列表转换为多边形,r,list,gis,polygon,sf,R,List,Gis,Polygon,Sf,我有一个sf对象,如下所示: structure(list(Value = c(0.0224448168716316, 0.0232573334948221, 0.0227533509931156, 0.0214526198514539, 0.0202076447577734, 0.0198987318707359 ), geometry = structure(list(structure(c(0.866271, 51.288072), class = c("XY",

我有一个sf对象,如下所示:

structure(list(Value = c(0.0224448168716316, 0.0232573334948221, 
0.0227533509931156, 0.0214526198514539, 0.0202076447577734, 0.0198987318707359
), geometry = structure(list(structure(c(0.866271, 51.288072), class = c("XY", 
"POINT", "sfg")), structure(c(0.866264, 51.288062), class = c("XY", 
"POINT", "sfg")), structure(c(0.866258, 51.288052), class = c("XY", 
"POINT", "sfg")), structure(c(0.866252, 51.288042), class = c("XY", 
"POINT", "sfg")), structure(c(0.866245, 51.288032), class = c("XY", 
"POINT", "sfg")), structure(c(0.866239, 51.288022), class = c("XY", 
"POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(xmin = 0.866239, 
ymin = 51.288022, xmax = 0.866271, ymax = 51.288072), class = "bbox"), crs = structure(list(
    epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), class = "crs"), n_empty = 0L), 
    lon = c(`1` = 0.866271, `2` = 0.866264, `3` = 0.866258, `4` = 0.866252, 
    `5` = 0.866245, `6` = 0.866239), lat = c(`1` = 51.288072, 
    `2` = 51.288062, `3` = 51.288052, `4` = 51.288042, `5` = 51.288032, 
    `6` = 51.288022), bearing = c(203.698481252083, 200.617925511915, 
    200.617929623639, 203.698495141445, 200.617937896147, 200.617942031876
    ), p1 = structure(c(0.86626754319351, 0.866260971412482, 
    0.866254971412566, 0.866248543193856, 0.866241971412719, 
    0.866235971412793, 51.2880670617056, 51.2880569523547, 51.2880469523549, 
    51.2880370617061, 51.2880269523551, 51.2880169523552), .Dim = c(6L, 
    2L), .Dimnames = list(NULL, c("lon", "lat"))), p2 = structure(c(0.866291169366694, 
    0.866285120745778, 0.866279120739972, 0.866272169349123, 
    0.866266120728323, 0.866260120722494, 51.2880605588926, 51.2880512550893, 
    51.2880412550884, 51.2880305588895, 51.2880212550864, 51.2880112550854
    ), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lon", "lat"
    ))), p3 = structure(c(0.866298082980183, 0.866291177921382, 
    0.866285177915419, 0.86627908296192, 0.866272177903464, 0.866266177897481, 
    51.2880704354811, 51.2880613503796, 51.2880513503784, 51.288040435477, 
    51.2880313503759, 51.2880213503747), .Dim = c(6L, 2L), .Dimnames = list(
        NULL, c("lon", "lat"))), p4 = structure(c(0.86625083061034, 
    0.866242879232234, 0.866236879238075, 0.866231830627904, 
    0.866223879249719, 0.866217879255536, 51.2880834410928, 51.2880727448954, 
    51.2880627448964, 51.2880534410959, 51.2880427448984, 51.2880327448994
    ), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lon", "lat"
    ))), p5 = structure(c(0.866243916996385, 0.866236822056449, 
    0.866230822062455, 0.866224917014635, 0.866217822074403, 
    0.866211822080377, 51.2880735645039, 51.2880626496048, 51.2880526496061, 
    51.288043564508, 51.2880326496086, 51.2880226496098), .Dim = c(6L, 
    2L), .Dimnames = list(NULL, c("lon", "lat"))), p6 = structure(c(0.866291169342742, 
    0.866285120723053, 0.866279120717266, 0.866272169325172, 
    0.866266120705609, 0.866260120699783, 51.2880605588731, 51.288051255069, 
    51.2880412550681, 51.28803055887, 51.2880212550662, 51.2880112550652
    ), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lon", "lat"
    )))), sf_column = "geometry", agr = structure(c(Value = NA_integer_, 
lon = NA_integer_, lat = NA_integer_, bearing = NA_integer_, 
p1 = NA_integer_, p2 = NA_integer_, p3 = NA_integer_, p4 = NA_integer_, 
p5 = NA_integer_, p6 = NA_integer_), .Label = c("constant", "aggregate", 
"identity"), class = "factor"), row.names = c(NA, 6L), class = c("sf", 
"data.frame"))
我试图让所有点lon和lat(例如p1.lon、p1.lat、p2.lon、p2.lat、p3.lon、p3.lat等)在df1的每一行上形成一个多边形

我试过把圣母大学当作科学基金

df1 %>% select(c("p1","p2","p3","p4","p5","p6")) %>% 
  st_as_sf(coords = c('lon', 'lat'))

df1 %>% select(c("p1","p2","p3","p4","p5","p6")) %>% 
  mutate(st_as_sf(coords = c('lon', 'lat')))

df1  %>%  select(c("p1","p2","p3","p4","p5","p6")) %>%
  as.data.frame() %>% 
  st_as_sf( coords = c("lon", "lat"), crs = 4326 ) 

尝试将p.lon和p.lat值转换为st_多边形的列表有很多变化

我应该如何引用df1中的p1、p2、p3等值,以及如何显示st_polygon这些值来创建多边形? 我是否需要以某种方式改变df1的结构


你的
df1
的结构似乎有点奇怪,所以我想问一下这是怎么做的,是否可以简化


但是,使用您当前的结构,再进行一些重塑(使用
data.table
,因为这对我来说更容易使用),我们可以将数据设置为“长”形式,然后使用
sfheaders
从data.frame生成多边形


##添加一个“id”,以便我们知道哪些点进入哪些多边形
df1$id