Skip to content

invalid geometries from negative buffering in rgeos/sp

6 messages · Barry Rowlingson, Roger Bivand, Robert J. Hijmans +1 more

#
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:
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
#
On Thu, 3 Oct 2013, Barry Rowlingson wrote:

            
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

  
    
3 days later
#
A more general fix might be to support NULL geometries in Spatial objects.
Robert
On Thu, Oct 3, 2013 at 6:29 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
#
On Mon, 7 Oct 2013, Robert J. Hijmans wrote:

            
Maybe, but we do not have in sp a class for mixed types of geometries 
either, so we would have to define NULL of everything. OGC SFS has NULL, 
but I would argue that NULL geometries have no analytical meaning, like a 
point with no coordinate values - so we don't know where it is. It doesn't 
fit the Spatial class, unless we open for a bounding box with NA corners. 
In rgeos, the typical output if there is no positional data is the R NULL 
value. One might go towards objects with mixed geometries (GDAL is 
permitting them for the drivers that have them in the development 
version), but I don't see an analytical need. How often does, for example, 
newdata for predicting from a geostatistical model include both points and 
lines?

Roger

  
    
#
On Mon, Oct 7, 2013 at 5:51 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
True, but that is a different issue.
There have been cases where I thought it would have been handy, for
example when geometries (e.g. point locations) are known for some, but
not for all records in a data set.
However, addition this type of support would add a significant amount
of overhead to all functions (check for / remove NULL values; NA
bounding box vaues).
Me neither
#
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 10/07/2013 07:11 PM, Robert J. Hijmans wrote:
Since the launch of what would later become sp [1], nearly 10 years
ago, I haven't regretted the decision to not allow missing values in
geometries a single second.

[1] https://stat.ethz.ch/pipermail/r-sig-geo/2003-October/000028.html
- -- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of M?nster
Heisenbergstra?e 2, 48149 M?nster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAD3A77F1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSUvmMAAoJEM1OCHCtOnfxkpcH/R4stGxSSR/5kqHFyrgotsff
2HX5c3rAwi3gfFG/a/NbU9B+5+6XEDPaNV4qd9MgvOd6mMX7IwPKjpiJEUj3CBft
X8Z1fDb1RD5U3BKyr0ggroTOq2PNdpfgdvVWRKd0Q9+wprZ1/u09aQMOQIqrdVt4
p+0Gy+f510T28gQ99ceRgjLiI1a1dZGnxZb2gV0n0DRU6szAyjhK+y3tyZTfFoKz
UUPoH/BumUH3+7wbHseexHMgwQm6P31GX6mrLxDmXzzIk7Zszp19YM8DfXc4KR6W
3TmuXrehit+7c/HI9iKEhUKGCmMfqhQ7hhygQU8kGRoRrtUY54LDt6c59S2oLoo=
=ZXtJ
-----END PGP SIGNATURE-----