[英]Calculate area of SpatialPoints object r
I am having trouble calculating the area that my SpatialPoints object spans.我无法计算我的 SpatialPoints object 跨越的区域。 I need the area in m^2.
我需要 m^2 的面积。 The code for my object is below.
我的 object 的代码如下。 I can't seem to find the answer online.
我似乎无法在网上找到答案。 Any help would be appreciated, thanks in advance!
任何帮助将不胜感激,在此先感谢!
new("SpatialPoints", coords = structure(c(365901.718425453, 365840.735248348,
365658.787059115, 365358.861441992, 364945.883167318, 364426.633326947,
363809.637988903, 363105.028199579, 362324.373632234, 361480.492613283,
360587.241645727, 359659.287885757, 358711.868308457, 357760.539517095,
356820.922304122, 355908.4451582, 355038.090928836, 354224.150808417,
353479.989671215, 352817.82662253, 352248.534361316, 351781.460650762,
351424.274828283, 351182.841875208, 351061.126113954, 351061.126113954,
351182.841875208, 351424.274828283, 351781.460650762, 352248.534361316,
352817.82662253, 353479.989671215, 354224.150808417, 355038.090928836,
355908.4451582, 356820.922304122, 357760.539517094, 358711.868308457,
359659.287885757, 360587.241645727, 361480.492613283, 362324.373632234,
363105.028199579, 363809.637988903, 364426.633326947, 364945.883167318,
365358.861441992, 365658.787059115, 365840.735248348, 365901.718425453,
365901.718425453, 471406.967507941, 470123.485439601, 468861.07811134,
467640.474216585, 466481.716037545, 465403.830351483, 464424.516011563,
463559.853332175, 462824.040050607, 462229.1582006, 461784.975725686,
461498.786089822, 461375.288518918, 461416.510839672, 461621.776182718,
461987.714096798, 462508.31589148, 463175.033299687, 463976.91884001,
464900.805574046, 465931.523307164, 467052.147682681, 468244.278079334,
469488.339748967, 470763.90523336, 472050.029782522, 473325.595266915,
474569.656936548, 475761.787333201, 476882.411708718, 477913.129441836,
478837.016175871, 479638.901716194, 480305.619124402, 480826.220919084,
481192.158833164, 481397.42417621, 481438.646496964, 481315.14892606,
481028.959290196, 480584.776815282, 479989.894965275, 479254.081683707,
478389.419004318, 477410.104664399, 476332.218978337, 475173.460799296,
473952.856904542, 472690.449576281, 471406.967507941, 471406.967507941
), .Dim = c(51L, 2L), .Dimnames = list(NULL, c("X_rotated", "Y_rotated"
))), bbox = structure(c(351061.126113954, 461375.288518918, 365901.718425453,
481438.646496964), .Dim = c(2L, 2L), .Dimnames = list(c("X_rotated",
"Y_rotated"), c("min", "max"))), proj4string = new("CRS", projargs = "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"))
You can use the sf
package to accomplish the desired output.您可以使用
sf
package 来完成所需的 output。 First you'll need to convert your points data into sf, then calculate its bounding box and create a polygon from that box.首先,您需要将点数据转换为 sf,然后计算其边界框并从该框创建一个多边形。 Finally, you just need to calculate its area with
st_area
.最后,您只需要使用
st_area
计算其面积。
library(sf)
# First convert to sf
st_as_sf(df) |>
# Get bounding box of points
st_bbox(df) |>
# Create bbox polygon from bbox
st_as_sfc() |>
# Calculate area
st_area()
# 297752116 [m^2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.