R中小叶中聚集标记的聚合加权线串

R中小叶中聚集标记的聚合加权线串,r,leaflet,cluster-analysis,sf,R,Leaflet,Cluster Analysis,Sf,我正在尝试绘制位置和加权连接线串。当我放大或缩小时,标记的聚类会调整得很好。显示的簇标签是标记的聚合节点值 我想对线串做类似的处理,以便 绘图不显示连接单个标记的蓝线,而是显示连接标记簇的线,以及 连接标记簇的新字符串的宽度根据wgt变量进行自定义。 我希望下面的代码能够说明这个问题: library(dplyr) library(leaflet) library(sf) set.seed(123) N <- 1000 N_conn <- 100 # data frame for

我正在尝试绘制位置和加权连接线串。当我放大或缩小时,标记的聚类会调整得很好。显示的簇标签是标记的聚合节点值

我想对线串做类似的处理,以便

绘图不显示连接单个标记的蓝线,而是显示连接标记簇的线,以及 连接标记簇的新字符串的宽度根据wgt变量进行自定义。 我希望下面的代码能够说明这个问题:

library(dplyr)
library(leaflet)
library(sf)

set.seed(123)
N <- 1000
N_conn <- 100

# data frame for points
df_points <- data.frame(id = 1:N,
                        lng = sample(c(11.579657, 16.370654), N, TRUE) + rnorm(N, 0, 0.5),
                        lat = sample(c(48.168889, 48.208087), N, TRUE) + rnorm(N, 0, 0.5),
                        node_val = sample(10, N, TRUE))


# data frame for connections
df_conn <- data.frame(id_from = sample(N_conn, replace = TRUE),
                      id_to   = sample(N_conn, replace = TRUE),
                      wgt  = abs(rnorm(N_conn)))

# drop connections where from and to ids are identical
df_conn <- subset(df_conn, id_from != id_to)

# add the coordinates for the connections (merging is not neccessary due to ordering of synth data)
df_conn$lat_from <- df_points[df_conn$id_from, "lat"]
df_conn$lng_from <- df_points[df_conn$id_from, "lng"]
df_conn$lat_to   <- df_points[df_conn$id_to, "lat"]
df_conn$lng_to   <- df_points[df_conn$id_to, "lng"]


sf_conn_from <- df_conn %>% 
  st_as_sf(coords=c("lng_from", "lat_from"))

sf_conn_to <- df_conn %>% 
  st_as_sf(coords=c("lng_to", "lat_to"))

sf_conn <- st_combine(cbind(sf_conn_from, sf_conn_to)) %>% 
  st_cast("LINESTRING")

st_crs(sf_conn) <- 4326

leaflet(df_points) %>% 
  addTiles() %>% 
  addMarkers(options = markerOptions(node_val = ~node_val), 
             label = quakes$mag,
             clusterOptions = markerClusterOptions(
               iconCreateFunction=JS("function (cluster) {    
                var markers = cluster.getAllChildMarkers();
                var sum = 0; 
                for (i = 0; i < markers.length; i++) {
                  sum += Number(markers[i].options.node_val);
                  //sum += 1;
                }
                sum = Math.round(sum);
                return new L.DivIcon({ html: '<div><span>' + sum + '</span></div>',
                  className: 'marker-cluster marker-cluster-medium', 
                  iconSize: new L.Point(40,40)});
              }")
             )) %>% 
  leafem::addFeatures(data = sf_conn,
                      color = 'blue',#~pal(rel_full$N_scale),#
                      weight = 1) 
感谢这两个问题的贡献者:


这是调整行权重的部分解决方案,我无法帮助对这些行进行聚类:

图书馆弹琴 图书馆 图书馆 第123集 N