Different packages concerned with spatial data use different polygon
specifications, which sometimes becomes very confusing (see Details below).
To be compatible with the various polygon classes, package polyCub
uses an S3 class "xylist"
, which represents a polygonal domain
(of potentially multiple polygons) by its core feature only: a list of lists
of vertex coordinates (see the "Value" section below).
The generic function xylist
can deal with the
following polygon classes:
"owin"
from package spatstat.geom
"gpc.poly"
from package gpclib
"Polygons"
from package sp
(as well as "Polygon"
and
"SpatialPolygons"
)
"(MULTI)POLYGON"
from package sf
The (somehow useless) default xylist
-method
does not perform any transformation but only ensures that the polygons are
not closed (first vertex not repeated).
xylist(object, ...)# S3 method for owin
xylist(object, ...)
# S3 method for sfg
xylist(object, ...)
# S3 method for gpc.poly
xylist(object, ...)
# S3 method for SpatialPolygons
xylist(object, reverse = TRUE, ...)
# S3 method for Polygons
xylist(object, reverse = TRUE, ...)
# S3 method for Polygon
xylist(object, reverse = TRUE, ...)
# S3 method for default
xylist(object, ...)
Applying xylist
to a polygon object, one gets a simple list,
where each component (polygon) is a list of "x"
and "y"
coordinates. These represent vertex coordinates following spatstat.geom's
"owin"
convention (anticlockwise order for exterior boundaries,
without repeating any vertex).
an object of one of the supported spatial classes.
(unused) argument of the generic.
logical (TRUE
) indicating if the vertex order of the
sp classes should be reversed to get the xylist
/owin
convention.
Sebastian Meyer
Polygon specifications differ with respect to:
is the first vertex repeated?
which ring direction represents holes?
Package overview:
"owin"
does not repeat the
first vertex, and anticlockwise = normal boundary, clockwise = hole.
This convention is also used for the return value of xylist
.
Repeat first vertex at the end (closed), anticlockwise = hole, clockwise = normal boundary
Repeat first vertex at the end (closed), clockwise = hole, anticlockwise = normal boundary; however, sf does not check the ring direction by default, so it cannot be relied upon.
There seem to be no such conventions
for polygons of class "gpc.poly"
.
Thus, for polygons from sf and gpclib, xylist
needs
to check the ring direction, which makes these two formats the least
efficient for integration domains in polyCub.