[R-sig-Geo] default hole-status of sp::Polygon
Michael Sumner
mdsumner at gmail.com
Wed Mar 30 06:50:47 CEST 2016
Hello,
help(Polygon) (sp version 1.2-2) says that if `hole` is unspecified
then anti-clockwise ring direction means hole = TRUE. The
ring-direction detection can be over-ridden by explicitly setting
`hole` to TRUE or FALSE, and if necessary this reorders the
coordinates to align to the rule,
Polygon() will accept a n-row or (n+1)-row matrix as input, and simply
appends the first coordinate if it's not there.
The anti-clockwise=hole rule holds true if we leave out the final
closing coordinate for a 4-vertex shape (square), but not a 3-vertex
shape (triangle).
(For the purpose of this email, "is a hole" and "is not a hole" refers to
the
logical attribute actually set on the object.)
Is this expected? Is it discussed somewhere?
Cheers, Mike.
library(sp)
## 1) the rule is followed for a square no matter if the closing coordinate
included
## square with repeated first coord
xs <- c(0, 1, 1, 0, 0)
ys <- c(0, 0, 1, 1, 0)
## this is a hole
Polygon(cbind(xs, ys))
## this is not a hole
Polygon(cbind(xs, ys)[rev(seq_along(xs)), ])
## square with 4 unique coords
xs0 <- c(0, 1, 1, 0)
ys0 <- c(0, 0, 1, 1)
## this is a hole
Polygon(cbind(xs0, ys0))
## this is not a hole
Polygon(cbind(xs0, ys0)[rev(seq_along(xs0)), ])
## 2) rule is followed for a triangle with fourth closing coordinate
## triangle with repeated first coord
x <- c(0, 1, 1, 0)
y <- c(0, 0, 1, 0)
## this is a hole
Polygon(cbind(x, y))
## this is not a hole
Polygon(cbind(x, y)[rev(seq_along(x)), ])
## triangle with 3 unique coords
x0 <- c(0, 1, 1)
y0 <- c(0, 0, 1)
## this is a NOT a hole ## <- expected a hole -> ##
Polygon(cbind(x0, y0))
## this is not a hole
Polygon(cbind(x0, y0)[rev(seq_along(x0)), ])
--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list