[R-sig-Geo] gUnion causes segfault
Roger.Bivand at nhh.no
Thu Jun 2 19:34:16 CEST 2011
On Thu, 2 Jun 2011, Brian J. Stults wrote:
> I am working with the 2009 Tiger/LINE topological faces files. I want
> to create a shapefile with polygons for unique instances of state,
> county, place, and tract. Since the topological faces shapefiles
> provide many smaller geographies, my approach has been to dissolve those
> smaller geographies into larger ones using the gUnion function from
> rgeos. This works for most counties, but it causes segfaults for some.
> One example is Apache County, AL. The shapefile is here:
Please always include the output of sessionInfo() in any report like this.
Both the OS for binary packages, and the specific version of rgeos, may
play a role. I cannot check on a 1GB laptop, because the shapefile creates
a 180MB object and has 63K polygons. I don't know why subsetting the
columns in the data slot would help, but I do think that your assignment
back into the object is a hidrance in memory terms for such a large object
- provoking copies. I assumed that you do know that you have no other way
to dissolve so many polygons into so few (40) output units - this isn't a
typical use case. The version of rgeos may matter, as protection against
unclean objects provoking seg.faults has recently been extended.
> My code (modified to work on a single county) is:
> tiger <- readShapePoly("tl_2009_04001_faces.shp",
> proj4string=CRS("+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs"))[,
> tiger$PLACEFP <- as.character(tiger$PLACEFP)
> tiger$PLACEFP[is.na(tiger$PLACEFP)] <- "99999"
> tiger$uniqueid <- paste(tiger$PLACEFP00, tiger$TRACTCE00, sep="")
> tiger.dissolve <- gUnionCascaded(tiger, tiger$uniqueid)
> The error message is:
>> tiger.dissolve <- gUnionCascaded(tiger, tiger$uniqueid)
> *** caught segfault ***
> address 0x17c9, cause 'memory not mapped'
> 1: .Call(func, .RGEOS_HANDLE, spgeom, id, byid, PACKAGE = "rgeos")
> 2: TopologyFunc(groupID(spgeom, id), unique(na.omit(id)), TRUE,
> 3: gUnionCascaded(tiger, tiger$uniqueid)
> aborting ...
> The full output can be viewed here:
> Can anyone tell me what is going wrong, or how to go about debugging the
> problem? I uninstalled rgeos to force using UnionSpatialPolygons (there
> must be a better way to force that than uninstalling, right?), but that
> ran overnight and never finished. I am guessing there must be something
> strange about these shapefiles.
> I can successfully dissolve this shapefile using the ftools module in
> qgis. However, I want to do this for a large number of counties, which
> is why I am pursuing a programmed solution. I tried doing it via python
> scripting with qgis, but could not get that to work after a lot of
> trying. I am currently trying to do it with Spatialite, which seems
> promising. I would be happy to hear any other suggested approaches.
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo