通过Shiny/Leaflet/R中的缩放级别更改标记聚类 [英] Changing marker clustering by zoom level in Shiny / Leaflet / R

查看:42
本文介绍了通过Shiny/Leaflet/R中的缩放级别更改标记聚类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Web应用程序,用户在其中输入一组标识符,并在地图上显示与这些标识符相关的一组点.

I want to create a web application where a user inputs a set of identifiers, and a set of dots on a map related to those identifiers appear.

麻烦的是,此数据可能会在数万至数十万乃至潜在的数百万之内.鉴于这种可能性,我想采取一种轻松的策略.以下是我理想的聚合行为.

Trouble is, this data can number in the tens to hundreds of thousands to even potentially millions. Given this possibility, I want to take a light tack. Below is my ideal aggregation behavior.

在低缩放级别下,我想按状态将这些点聚合为计数(适当的符号体系大小/颜色表示更高的强度,点以状态质心为中心).在稍高的缩放级别下,这些像素将被较小的多边形分开计数.以更高的缩放比例,却缩小了多边形.如果不进行汇总,则地图上的点数少于500个时,只需绘制点即可.

At low zoom levels, I want to aggregate these dots into counts by state (appropriate symbology size/color indicating higher intensity, with the dot centered on the state centroid). at slightly higher zoom levels, these would separate into counts by smaller polygons. at even higher zoom, yet smaller polygons. When, if unaggregated, the number of dots on the map would be less than ~500, then just plot the dots.

这些多边形已经确定,每个点在其数据中都有其下每个多边形的多边形ID.

These polygons were already decided, and each dot has within its data the polygon ID for each polygon it is under.

由于首先将点随机绘制在各个多边形内,所以点在多边形内的实际分布无关紧要.或更确切地说,任何忽略点在哪个多边形上绘制的聚合都将清除信息.因此,我不能使用markercluster(至少不能使用我看到的选项.如果有一种简便的方法可以按照我所寻找的方式进行汇总,请告诉我)

Since the dots are randomly plotted within respective polygons to begin with, actual distribution of dots within polygons doesn't matter. Or rather, any aggregation that ignores which polygon the dots were plotted in will wipe out information. For this reason, I can't use markercluster (at least not with the options I saw. If there's an easy means to aggregate in the manner i'm looking for, please let me know)

由于各种原因(我不是JavaScript程序员,我是R程序员),我正在R中的Leaflet包的范围内工作.是否有一种方法可以根据缩放更改聚合级别?以这种方式?

For various reasons (I'm not a javascript programmer, I'm an R programmer) I am working within the bounds of the leaflet package within R. Is there a means by which I can change the aggregation level depending on zoom in this manner?

我整理了一个玩具数据集,其中包含一个相对较小的子集(1个实体,3个州,大约1万个观测值)以及质检中心和这些州的县.

I've put together a toy dataset containing a relatively small subset (1 entity, 3 states, ~10k observations) along with the centroids for census tracts and counties for those states.

http://s000.tinyupload.com/index.php?file_id=00048836337627834343

推荐答案

这不完全是答案,但几乎不能包含在注释中.

This is not exactly an answer but it would hardly fit in a comment.

您想显示每个预定义地理区域的汇总数据(点/标记的数量?),这些区域以较低的缩放级别合并(假设可以是每个城市,然后是县,州等).

You would like to show aggregated data (counts of dots / markers?) per predefined geographic areas, with those areas merging at lower zoom levels (let's say it could be per cities, then counties, States, etc.).

即使在JavaScript中,我也不知道该用例有任何现成的解决方案.有一些可能的解决方法,但是我不确定它们是否可以在R中轻松实现.

Even in JavaScript I am not aware of any out-of-the-box solution for this use case. There are some possible workarounds, but I am not sure they would be easily do-able in R.

通常的解决方法是摆脱任何自动聚类,并使用适当的数据聚合算法(在每个缩放级别上生成自己的标记)(因为您可以依赖父多边形ID,所以这样做并不难).然后只需在缩放更改时添加/删除标记即可.

A usual workaround is to get rid of any automatic clustering, and generate your own markers at each zoom level, with appropriate data aggregation algorithm (not very difficult to do since you can rely on parent polygon ID). Then simply add/remove markers when zoom changes.

不幸的是,这意味着您不会从MarkerCluster获得动画和覆盖率显示.

Unfortunately this means you will not get the animations and coverage display from MarkerCluster.

您可能对此线程也有兴趣 [问题]根据某些地理实体构建集群GitHub上的Leaflet.markercluster问题页面上的#521 .用例在某种程度上是相似的,您可以看到一些实现示例,但不幸的是,它没有在任何常规且可靠的解决方案中输出.

You might also be interested in this thread [Question] Build clusters depending on some geographical entity #521 from Leaflet.markercluster issues page on GitHub. The use case is somehow similar, and you can see some examples of implementations, but it did not output in any general and reliable solution unfortunately.

这篇关于通过Shiny/Leaflet/R中的缩放级别更改标记聚类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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