degenerate Polygon / Line
mdsumner opened this issue · comments
Why is this not an error? I suspect there might be some deeper reason, or practical constraint?
The "single coordinate polygon/line" case and the "duplicated two coordinate polygon" cases seem like it should be an error, or at least trigger a warning. The other cases are degenerate geometries and so out of sp scope, I understand .
Polygon(cbind(0, 0))
Line(cbind(0, 0))
SpatialPolygons(list(Polygons(list(Polygon(cbind(0, 0))), "1")))
Slightly more insidious, there's a different behaviour when given two duplicate points vs. two different points because of the "ring completion":
Polygon(cbind(c(0, 0), c(0, 0)), hole = FALSE)
Polygon(cbind(c(0, 0), c(0, 0)), hole = TRUE)
Line(cbind(c(0, 0), c(0, 0)))
## this time the first point is copied on for the Polygon
Polygon(cbind(c(0, 0), c(0, 1)), hole = FALSE)
Polygon(cbind(c(0, 0), c(0, 1)), hole = TRUE)
I also see "stack imbalance" warnings from some degenerate cases
Polygon(cbind(c(0, 0), c(1, 0)))
#Warning: stack imbalance in '.Call', 12 then 11
#Warning: stack imbalance in '<-', 10 then 9
#Warning: stack imbalance in '{', 7 then 6
Polygon(cbind(1:10, 1:10))
#Warning: stack imbalance in '.Call', 12 then 11
#Warning: stack imbalance in '<-', 10 then 9
#Warning: stack imbalance in '{', 7 then 6
The stack imbalance warnings are now gone; I now see
> x = Polygon(cbind(c(0, 0), c(1, 0)))
Warning message:
In Polygon(cbind(c(0, 0), c(1, 0))) : less than 4 coordinates in polygon
and as of your first point: sp objects don't pretend to be valid in a simple feature access way.