Skip to content

Recombining polygon shapefiles using maptools

2 messages · Roger Bivand

#
On Thu, 27 Mar 2008, Don MacQueen wrote:

            
Sorry for not replying earlier. For this case, brute force may be the most 
suitable.
The higher level methods (spCbind() in maptools) are for Polygons objects 
rather than for Polygon objects, because spCbind() expects to cbind two 
lists of Polygons objects and two data frames.

The difficulty here is to find out how to pack and unpack your geometries 
to use checkPolygonsHoles() in maptools. If you can put all your 
geometries into a single Polygons object, checkPolygonsHoles() will return 
a single Polygons object with the holes correctly identified, and that 
will work with spsample. It will, however, treat the sammpled points as 
lying within the same Polygons object, but maybe that doesn't matter.

This is untried:

Do spCbind() on the 5 SpatialPolygonDataFrames after having given the 
constituent Polygons objects unique IDs (spChFIDs() method).

ALL <- spCbind(spCbind(spCbind(spCbind(A, B), C), D), E)

Add a constant vector to the output object, and use it as the IDs= 
argument to unionSpatialPolygons()

ALL$all <- 1
out <- unionSpatialPolygons(as(ALL, "SpatialPolygons"), IDs=ALL$all)

Check out - it may be that the first pass through gpclib will be enough, 
or

out1 <- sapply(slot(out, "polygons"), checkPolygonsHoles)

where out1 will be a list of Polygons object of length

length(slot(out, "polygons"))

If only one, just use spsample() on that (there is a sample.Polygons() 
method), if more than one, build a SpatialPolygons object, and use 
spsample() on that.

Have you considered using the spsurvey package - it is more targetted than 
spsample() methods - or does spsample() meet your needs?

Hope this helps,

Roger

  
    
#
On Wed, 2 Apr 2008, Roger Bivand wrote:

            
Certainly untried - not spCbind() methods, but, of course, spRbind() 
methods to bind the *rows*, sorry.

Roger