简体   繁体   English

在shapefile中组合多个形状

[英]Combine multiple shapes within a shapefile

My shapefile has 1612 shapes that I would like to combine to 10 shapes (between 9 and 11) each (I am working on collapsing Canadian postal codes). 我的shapefile有1612个形状,我想将它们组合成10个形状(每个9到11之间)(我正在努力折叠加拿大邮政编码)。

How do I best create those clusters? 如何最好地创建这些集群? I don't need a specific criterion but if it is easier, imagine that each big cluster should have roughly equal size. 我不需要特定的标准,但如果更容易,想象每个大集群应该具有大致相同的大小。

If I programmatically scan over the map from left to right, stop, select 10 neighbours, move further, stop, select 10 neighbours, etc. there will always be some shapes that would be left out because of their shapes. 如果我以编程方式从左到右扫描地图,停止,选择10个邻居,进一步移动,停止,选择10个邻居等等。总会有一些形状由于它们的形状而被遗漏。

As an example, I am taking the world map from maptools. 举个例子,我从maptools中获取世界地图。 How can I make groups of 5 countries that are next to each other automatically (ie it selects which polygons to merge)? 如何自动创建彼此相邻的5个国家/地区组(即选择要合并的多边形)?

library(maptools)
plot(wrld_simpl)

You will need gUnaryUnion() from rgeos package. 您将需要来自rgeos包的gUnaryUnion() An example can be found here . 这里可以找到一个例子。 Of course, you first have to decide on which polygons you want to disolve. 当然,您首先必须决定要解析哪些多边形。 Therefore, you will have to merge a refernce dataframe first. 因此,您必须首先合并引用数据框。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM