簡體   English   中英

如何從 R 中的 x 和 y 點計算多邊形的面積?

[英]How do I calculate area in polygon from x and y points in R?

我正在尋找從一組 x 和 y 點(下面的示例 1 坐標)計算不同形狀的面積。

x_coordinates_1 <- c(786.0, 712.3, 717.7, 804.9, 866.1, 877.5, 866.0, 823.2, 765.5, 791.8, 830.3, 846.9, 937.1, 941.1, 983.2, 1020.5, 997.1, 996.9, 921.5, 921.2, 850.6, 850.6, 786.0)

y_coordinates_1 <- c(139.8, 245.3, 291.7, 335.6, 352.7, 402.4, 492.9, 560.1, 603.6, 631.7, 617.8, 618.1, 538.5, 476.4, 443.0, 338.4, 232.7, 232.7, 145.0, 145.0, 121.0, 120.7, 139.8)

我在使用 rgeos 時有一個 go 但卡住了。 還有另一種方法可以做到這一點嗎?

非常感謝

您可以使用sf package 來計算多邊形的面積。 首先,您必須將 x 和 y 坐標列表轉換為多邊形,然后計算其面積。

library(sf)

x_coordinates_1<-c(786.0,712.3,717.7,804.9,866.1,877.5,866.0,823.2,765.5,791.8,830.3,846.9,937.1,941.1,983.2,1020.5,997.1,996.9,921.5,921.2,850.6,850.6,786.0)

y_coordinates_1<-c(139.8,245.3,291.7,335.6,352.7,402.4,492.9,560.1,603.6,631.7,617.8,618.1,538.5,476.4,443.0,338.4,232.7,232.7,145.0,145.0,121.0,120.7,139.8)

# Transform your list of points to a polygon, create a simple feature from them and set its crs according to its EPSG code (here I set it to UTM 15 N)
polygon <- st_sfc(st_polygon(list(cbind(x_coordinates_1,y_coordinates_1)))) %>%
  st_set_crs(32615)

# Plot the polygon to check if geoemtry is the expected
plot(polygon,axes = TRUE)

# Calculate area of the polygon
st_area(multipoint)
# 78579.21

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM