[R-sig-Geo] invalid geometries from negative buffering in rgeos/sp

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Oct 3 01:06:47 CEST 2013


Using scot_BNG from the rgdal package:

dsn <- system.file("vectors", package = "rgdal")[1]
scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG")

and buffering with a sufficiently large negative width:

b=gBuffer(scot_BNG,width=-10000,byid=TRUE)

produces an object that gives an error on plot:

 > plot(b)
Error in checkSlotAssignment(object, name, value) :
  assignment of an object of class “NULL” is not valid for slot
"coords" in an object of class “Line”; is(value, "matrix") is not TRUE

 Which I think is because the negative buffer has shrunk a feature to nothing.

b[1,] is fine but:

> b[2,]
Error in SpatialPolygons(x at polygons[i], proj4string = CRS(proj4string(x))) :
  INTEGER() can only be applied to a 'integer', not a 'NULL'

I'm not sure what the right thing to do here is. Either return a valid
zero-area polygon (if that's not a contradiction in terms) or drop the
degenerate cases?

Barry



More information about the R-sig-Geo mailing list