[R-sig-Geo] gUnion causes segfault

Brian J. Stults bstults at fsu.edu
Thu Jun 2 18:15:26 CEST 2011


Hello,

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:

http://www2.census.gov/geo/tiger/TIGER2009/04_ARIZONA/04001_Apache_County/tl_2009_04001_faces.zip

My code (modified to work on a single county) is:

library(maptools)
library(rgeos)

tiger <- readShapePoly("tl_2009_04001_faces.shp",
proj4string=CRS("+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs"))[,
c(4,37)]
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)
q()


The error message is:

> tiger.dissolve <- gUnionCascaded(tiger, tiger$uniqueid)

 *** caught segfault ***
address 0x17c9, cause 'memory not mapped'

Traceback:
 1: .Call(func, .RGEOS_HANDLE, spgeom, id, byid, PACKAGE = "rgeos")
 2: TopologyFunc(groupID(spgeom, id), unique(na.omit(id)), TRUE,
"rgeos_unioncascaded")
 3: gUnionCascaded(tiger, tiger$uniqueid)
aborting ...


The full output can be viewed here:
http://www2.criminology.fsu.edu/~stults/misc/union_tiger.txt


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.

Thanks,
Brian

-- 
Brian J. Stults
Assistant Professor
College of Criminology and Criminal Justice
Florida State University
phone: 850-645-7376   fax: 850-644-9614



More information about the R-sig-Geo mailing list