如果我只有 X、Y 坐标,如何计算 R 中多边形的面积? [英] How calculate the area of a polygon in R, if I only have X,Y coordinates?

查看:84
本文介绍了如果我只有 X、Y 坐标,如何计算 R 中多边形的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 X、Y 坐标的数据框,但我需要计算覆盖

Library splancs 有一个 areapl 函数来计算非自相交多边形的面积,例如上面的 convex_hull.因此,我们可以这样做:

库(splancs)as.matrix(convex_hull) %>% areapl

I have a data frame with X, Y coordinates, but I need to calculate the area that cover all the points in the scatterplot there is a way to draw a polygon that surround all the points and calculate this area?

解决方案

This is a convex hull problem. Other questions cover similar territory. We can gather the plotting and area calculation problems here for good measure.

To plot the convex hull of a point cloud, we can use the chull function:

library(tidyverse)

data <- tibble(x = runif(50), y = runif(50))

convex_hull <- data %>% slice(chull(x, y))

ggplot(data, aes(x = x, y = y)) + 
  geom_point() + 
  geom_polygon(data = convex_hull,
               alpha = 0.25)

Library splancs has an areapl function to calculate the area of a non-selfintersecting polygon, such as the convex_hull above. Hence, we may do:

library(splancs)
as.matrix(convex_hull) %>% areapl

这篇关于如果我只有 X、Y 坐标,如何计算 R 中多边形的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆