简体   繁体   中英

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).

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.

As an example, I am taking the world map from maptools. How can I make groups of 5 countries that are next to each other automatically (ie it selects which polygons to merge)?

library(maptools)
plot(wrld_simpl)

You will need gUnaryUnion() from rgeos package. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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