[R-sig-Geo] default hole-status of sp::Polygon

chris english englishchristophera at gmail.com
Thu Mar 31 19:04:19 CEST 2016


Thanks Micheal for the clear explication and Edzer for fixing. Triangles
specifically were not being created or assessed properly (anti or not). İ
couldn't figure out why and assumed it was me or my approach. But it did
cause me to drop sp and friends from parts of my tool chain relating to
triangles as differential in saccade inflection detection, so I'm happy
this is sorted out. Now to github.
Cheers,
Chris
On Mar 30, 2016 15:00, "Edzer Pebesma" <edzer.pebesma at uni-muenster.de>
wrote:

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

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list