gpt4 book ai didi

r - SpatialPolygonsDataFrame R中每个多边形的边界框

转载 作者:行者123 更新时间:2023-12-02 07:21:58 27 4
gpt4 key购买 nike

如何获取 polys 中每个多边形的 bbox

pp <- cbind(coordinates(polys),as.data.frame(polys))  

只给我 lonlat,但我想为每个多边形获取 lat1lat2lon1lon2

polys=new("SpatialPolygonsDataFrame"
, data = structure(list(NAMRB_EN = structure(c(6L, 45L, 2L, 41L, 31L,
3L, 40L, 14L, 42L, 7L, 26L, 12L, 38L, 25L, 36L, 9L, 39L, 27L,
32L, 19L, 43L, 21L, 15L, 22L, 20L, 9L, 17L, 11L, 33L, 44L, 37L,
13L, 8L, 5L, 18L, 30L, 16L, 10L, 1L, 29L, 34L, 23L, 24L, 28L,
4L, 35L), .Label = c("Albany", "Arctic Ocean Seaboard", "Arnaud",
"Atlantic Ocean Seaboard", "Attawapiskat", "Back", "Baleine",
"Broadback", "Churchill", "Columbia", "Eastmain", "Feuilles",
"Fraser", "George", "Grande Baleine", "Harricanaw", "Hayes",
"Hudson Bay Seaboard", "Koksoak", "La Grande", "Little Mecatina",
"Mackenzie", "Mississippi", "Moose", "Naskaupi", "Nass", "Natashquan",
"Nelson", "Nottaway", "Pacific Ocean Seaboard", "Povungnituk",
"Romaine", "Rupert", "Saint John", "Saint Lawrence", "Seal",
"Severn", "Skeena", "St.-Augustin", "Stikine", "Taku", "Thelon",
"Wannock", "Winisk", "Yukon"), class = "factor"), NAODA_EN = structure(c(1L,
5L, 1L, 5L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, 4L, 5L, 2L, 4L, 2L, 2L,
2L, 2L, 4L, 5L, 2L, 4L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L,
4L, 4L, 5L, 4L, 5L, 4L, 4L, 2L, 3L, 4L, 4L, 2L, 2L), .Label = c("Arctic Ocean",
"Atlantic Ocean", "Gulf of Mexico", "Hudson Bay", "Pacific Ocean"
), class = "factor"), NAMRB_FR = structure(c(4L, 45L, 19L, 41L,
31L, 2L, 40L, 12L, 42L, 5L, 27L, 10L, 38L, 26L, 36L, 7L, 39L,
28L, 32L, 16L, 43L, 18L, 13L, 23L, 17L, 7L, 15L, 9L, 33L, 44L,
37L, 11L, 6L, 3L, 22L, 21L, 14L, 8L, 1L, 30L, 34L, 24L, 25L,
29L, 20L, 35L), .Label = c("Albany", "Arnaud", "Attawapiskat",
"Back", "Baleine", "Broadback", "Churchill", "Columbia", "Eastmain",
"Feuilles", "Fraser", "George", "Grande Baleine", "Harricanaw",
"Hayes", "Koksoak", "La Grande", "Little Mecatina", "Littoral de l'océan Arctique",
"Littoral de l'océan Atlantique", "Littoral de l'océan Pacifique",
"Littoral de la Baie d'Hudson", "Mackenzie", "Mississippi", "Moose",
"Naskaupi", "Nass", "Natashquan", "Nelson", "Nottaway", "Povungnituk",
"Romaine", "Rupert", "Saint-Jean", "Saint-Laurent", "Seal", "Severn",
"Skeena", "St.-Augustin", "Stikine", "Taku", "Thelon", "Wannock",
"Winisk", "Yukon"), class = "factor"), NAODA_FR = structure(c(3L,
5L, 3L, 5L, 1L, 1L, 5L, 1L, 1L, 1L, 5L, 1L, 5L, 4L, 1L, 4L, 4L,
4L, 4L, 1L, 5L, 4L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 1L,
1L, 1L, 5L, 1L, 5L, 1L, 1L, 4L, 2L, 1L, 1L, 4L, 4L), .Label = c("Baie d'Hudson",
"Golfe de Mexique", "Océan Arctique", "Océan Atlantique", "Océan Pacifique"
), class = "factor")), .Names = c("NAMRB_EN", "NAODA_EN", "NAMRB_FR",
"NAODA_FR"), row.names = 0:45, class = "data.frame")
, polygons = list(<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>,
<S4 object of class structure("Polygons", package = "sp")>)
, plotOrder = c(3L, 24L, 35L, 46L, 44L, 2L, 42L, 38L, 45L, 36L, 26L, 9L, 32L,
1L, 20L, 39L, 27L, 31L, 43L, 25L, 16L, 7L, 30L, 40L, 6L, 15L,
34L, 13L, 12L, 41L, 28L, 8L, 23L, 29L, 5L, 10L, 37L, 11L, 14L,
33L, 4L, 22L, 18L, 19L, 17L, 21L)
, bbox = structure(c(-152.812332679775, 40.3769750107632, -52.6362915039062,
83.1106262207029), .Dim = c(2L, 2L), .Dimnames = list(c("x",
"y"), c("min", "max")))
, proj4string = new("CRS"
, projargs = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
)
)

最佳答案

空间多边形数据框有几个槽。 @data 是数据框,@polygons 是多边形。你可以先试试 str(polys@polygons) 看看你得到了什么。如果它是一个多边形列表,那么 lapply 它与 sp::bbox 函数

require(sp)
lapply(polys@polygons, bbox)

关于r - SpatialPolygonsDataFrame R中每个多边形的边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43264693/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com