如何计算r中多边形形状文件的质心
我需要上传将其转换为 R 并根据经度和纬度提取多边形的质心,以便我可以用它来计算两个质心之间的距离。
到目前为止,我已经这样做了:
PC4shape <- read_sf(dsn = "georef-netherlands-postcode-pc4", layer = "georef-netherlands-postcode-pc4")
PC4shape$centroids <- st_transform(PC4shape, 28992) %>%
st_centroid() %>%
st_transform(., '+proj=longlat +ellps=GRS80 +no_defs') %>%
st_geometry()
遵循 使用 R 计算两点(纬度、经度)之间的地理空间距离的函数
但是,我确信我的投影和 EPSG 是错误的。我只是不知道如何找到合适的人。非常感谢任何帮助。
I have this dataset:
https://public.opendatasoft.com/explore/dataset/georef-netherlands-postcode-pc4/export/?location=6,52.1564,5.29337&basemap=jawg.light
I need to upload it to R and extract the centroid of the polygons in terms of longitude and latitude, so that I can use it to calculate distances between two centroids.
So far I've done this:
PC4shape <- read_sf(dsn = "georef-netherlands-postcode-pc4", layer = "georef-netherlands-postcode-pc4")
PC4shape$centroids <- st_transform(PC4shape, 28992) %>%
st_centroid() %>%
st_transform(., '+proj=longlat +ellps=GRS80 +no_defs') %>%
st_geometry()
Following Function to calculate geospatial distance between two points (lat,long) using R
However, I am sure I have the projection and the EPSG wrong. I just don't know how to find the right one. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您要测量哪些质心,因此下面提供了几种不同方法来查找部分或全部距离的示例。
下面的代码找到每行的质心,显示前两行质心之间的距离,然后显示前 10 行的小距离矩阵。
crs 是原来的 wgs 84,距离以米为单位。我认为没有必要更改crs。
由 reprex 软件包 (v0.3.0) 创建于 2022 年 3 月 10 日
It isn't clear between which centroids you want to measure, so there's a sample below of couple of different ways to find some or all distances.
The code below finds the centroid of each row, shows the distance between centroids of the first two rows, and then a small distance matrix of the first 10 rows.
The crs is the original wgs 84, distances are in meters. I didn't see a need to change the crs.
Created on 2022-03-10 by the reprex package (v0.3.0)