我有以下数据:https://ufile.io/p9s0le6g ...由 485 个纬度/经度观测值组成。我最终想计算这个数字的表面积(以平方米或平方公里为单位)。我想用数据点(外部点)创建一个多边形,然后计算表面积。但是,我无法想出一个漂亮的多边形。 我的数据点作为坐标如下所示:
我想要一个看起来像这样(或类似)的多边形: 这是我尝试过的:
library(sp)
df <- read.csv('data.csv')
p = Polygon(df)
ps = Polygons(list(p),1)
sps = SpatialPolygons(list(ps))
plot(sps)
这会导致(显然不是一个漂亮的多边形): 我还尝试实现“从分布的点集创建多边形”的答案,但这对我来说只是一个矩形: 有人知道如何优化我的多边形以获得看起来像我的数据点的外部形状的图形以及如何计算该优化多边形的表面积吗?
比如这个例子,建立在
sf::st_convex_hull
library(sf)
library(tidyverse)
points <- read_csv("data.csv") %>%
st_as_sf(coords = c("LONG","LAT"), crs=4326)
polygon <- st_union(points) %>% # unite the points to 1 object
st_convex_hull() # calculate the convex hull
# verify the results by drawing a map
ggplot() +
geom_sf(data = points, col = "red", size = 2, pch = 4) +
geom_sf(data = polygon, col = "grey45", fill = NA)
# as a bonus: area of the polygon
area <- st_area(polygon)
area
我的 df 的纬度和经度格式为:23°38'34.4'' 和 72°27'38.5'',通常在 GIS 项目的实时数据集中找到,但这些坐标不被 coords=c 接受(经纬度),crs=4326)。 我尝试使用上述两种解决方案,但它不起作用。