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

Roger Bivand Roger.Bivand at nhh.no
Thu Oct 3 15:29:15 CEST 2013


On Thu, 3 Oct 2013, Barry Rowlingson wrote:

> 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:

Yes, but ...

The user gets a SpatialPolygonsDataFrame object with the data slot intact, 
but some of the polygons are clearly now invalid. Should we do 
book-keeping to only retain the data slot rows for valid polygons, only 
return the subset of valid polygons, or proceed as now, and have the user 
do:

plot(b[gArea(b, byid=TRUE) > 0,])

What makes more sense? I'm open to suggestions ...

Roger

>
> > 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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 mailing list