unionSpatialPolygons        package:maptools        R Documentation

_A_g_g_r_e_g_a_t_e _P_o_l_y_g_o_n_s _i_n _a _S_p_a_t_i_a_l_P_o_l_y_g_o_n_s _o_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     The function aggregates Polygons in a SpatialPolygons object,
     according to the IDs vector specifying which input Polygons belong
     to which output Polygons; internal boundaries are dissolved using
     the gpclib package union() function.

_U_s_a_g_e:

     unionSpatialPolygons(SpP, IDs, threshold=NULL)

_A_r_g_u_m_e_n_t_s:

     SpP: A SpatialPolygons object as defined in package sp

     IDs: A vector defining the output Polygons objects, equal in
          length to the length of the polygons slot of SpRs; it may be
          character, integer, or factor (try table(factor(IDs)) for a
          sanity check)

threshold: if not NULL, an area measure below which slivers will be
          discarded (some polygons have non-identical boundaries, for
          instance along rivers, generating slivers on union which are
          artefacts, not real sub-polygons)

_V_a_l_u_e:

     Returns an aggregated SpatialPolygons object named with the
     aggregated IDs values in their sorting order; see the ID values of
     the output object to view the order.

_A_u_t_h_o_r(_s):

     Roger Bivand

_E_x_a_m_p_l_e_s:

     library(sp)
     library(gpclib)
     nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
      proj4string=CRS("+proj=longlat +datum=NAD27"))
     lps <- coordinates(nc1)
     ID <- cut(lps[,1], quantile(lps[,1]), include.lowest=TRUE)
     reg4 <- unionSpatialPolygons(nc1, ID)
     sapply(slot(reg4, "polygons"), function(i) slot(i, "ID"))

