Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created February 22, 2012 19:12
Show Gist options
  • Save jlehtoma/1886707 to your computer and use it in GitHub Desktop.
Save jlehtoma/1886707 to your computer and use it in GitHub Desktop.
Dissolve polygons
library(rgeos)
library(maptools)
library(gpclib)
if (!rgeosStatus()) gpclibPermit()
gpclibPermit()
# Read in the data
fi.kunnat <- readShapePoly("fi_kunnat.shp")
# Get the polygon coordinates (not sure what these are really)
lps <- coordinates(fi.kunnat)
# Divide the coordinates into 4 bins
ID <- cut(lps[,1], quantile(lps[,1]), include.lowest=TRUE)
# Dissolve the original SpatialPolygonsDataFrame into 4 bins
reg4 <- unionSpatialPolygons(fi.kunnat, ID, avoidGEOS=T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment