简体   繁体   English

对彼此相距一定阈值距离内的多边形进行分组

[英]Group polygons that are within a certain threshold distance of each other

I am trying to group polygons that are within a certain distance of each other.我正在尝试对彼此相距一定距离内的多边形进行分组。

For example, polygon 1 is within 200,000m of polygon 2 and polygon 2 is within 200,000m of polygon 3 so I want to group all three together.例如,多边形 1 在多边形 2 的 200,000m 范围内,多边形 2 在多边形 3 的 200,000m 范围内,所以我想将这三个组合在一起。 Polygon 4 and 5 would be grouped together and then polygon 6 would be in a group alone.多边形 4 和 5 将组合在一起,然后多边形 6 将单独在一个组中。 在此处输入图像描述

Data:数据:

food <-structure(list(shape = c(17.1, 17.1, 17.1, 17.1, 18.1, 18.1, 
18.1, 18.1, 19.1, 19.1, 19.1, 19.1, 20.1, 20.1, 20.1, 20.1, 21.1, 
21.1, 21.1, 21.1, 24.1, 24.1, 24.1, 24.1), longitude = c(28, 
38, 38, 28, 38, 48, 48, 38, 38, 48, 48, 38, 58, 68, 68, 58, 58, 
68, 68, 58, 95, 100, 100, 95), latitude = c(-4, -4, -7, -7, -8, 
-8, -11, -11, -12, -12, -15, -15, -15, -15, -18, -18, -18.5, 
-18.5, -22, -22, -12, -12, -19, -19)), class = "data.frame", row.names = c(NA, 
-24L)

And then I turn it into a shapefile using this code:然后我使用以下代码将其转换为 shapefile:

library(sf)
library(sfheaders)

food <- lapply(split(food, food$shape), function(x) { coords <- as.matrix(cbind(x$longitude, 
x$latitude)); list(rbind(coords, coords[1,]))}) 

names(food)<- NULL

Coord_Ref <- st_crs(4326)

food <-  st_sfc(st_multipolygon(x=food), crs = Coord_Ref)

st_is_valid(food)

food <-  st_cast(food, "POLYGON")

You can use:您可以使用:

st_is_within_distance(st_centroid(food), dist = 2000000)
#> Sparse geometry binary predicate list of length 6, where the predicate was 
#> `is_within_distance '
#>  1: 1, 2, 3
#>  2: 1, 2, 3
#>  3: 1, 2, 3
#>  4: 4, 5
#>  5: 4, 5
#>  6: 6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果两组之间的距离在一定范围内,则在R中组合rleid分组 - Combine rleid grouping in R if two groups are within certain distance from each other "正则表达式环顾四周(两个单词在一定距离内彼此靠近,无论顺序如何)" - regex look around on either side (two words are nearby each other within certain distance, regardless of order) 比较大小不等的向量之间的值,以找到彼此相距一定距离内的值(没有循环?) - Compare values between vectors of unequal size to find values within a certain distance of each other (without loops?) 如果行在特定时间内按 R 中的组值发生,则删除行 - Removing rows if they occur within a certain time of each other by a group value in R 使用R检查位置是否在一组其他位置的特定距离内 - Check if location is within a certain distance of a set of other locations using R 将低于阈值的值分组到其他 - Group values below a threshold into Other 按组计数高于特定阈值的值 - Count values higher than a certain threshold by group 如何计算R中低于某个阈值的2个坐标之间的距离? - How to calculate distance between 2 coordinates below a certain threshold in R? 组内累计,直至达到阈值 - Cumulative sum within group till threshold is reached 如何在R中互相找到特定时间范围内的观测值 - How to find observations within a certain time range of each other in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM