[R-sig-Geo] default hole-status of sp::Polygon
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Wed Mar 30 12:08:25 CEST 2016
Thanks Mike, this is now fixed on github.
On 30/03/16 06:50, Michael Sumner wrote:
> 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)), ])
>
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software: http://www.jstatsoft.org/
Computers & Geosciences: http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160330/fdd53810/attachment.bin>
More information about the R-sig-Geo
mailing list