Skip to content
Prev 5633 / 29559 Next

unique spatial polygons

On Wed, 29 Apr 2009, Alina Sheyman wrote:

            
Actually, maybe my advice wasn't well-judged, unless you are happy to 
interpret code in a fairly naked setting, you may actually need the book 
text to see what is going on. The code treats a number of different 
issues, not all of which are necessarily relevant for your case.
# not LSAD_TRANS?
I guess that you need all of the features (geometries) in zipmaps1, but 
that some zipcodes have several features. Don't discard geometries 
unless you know that that is what you really want to do. Even if they are 
not contiguous, use:

zipmaps1u <- unionSpatialPolygons(as(zipmaps1, "SpatialPolygons"),
   as.character(zipmaps1$LSAD_TRANS))

to group all of the features belonging to each value of LSAD_TRANS as 
Polygon objects in unique Polygons objects (with multiple features).

The output (re. your next mail) is a SpatialPolygons object. How you then 
aggregate the data.frame part of the input object is up to you. The ID 
values of the Polygons objects in zipmaps1u will be the unique values of 
LSAD_TRANS. Unless you need to work with attribute data, you could stay 
just with SpatialPolygons objects until you are through.
If you need it later on, you could look at spChFIDs as I suggested before.

Hope this helps,

Roger