xylist: Convert Various Polygon Classes to a Simple List of Vertices

xylistR Documentation

Convert Various Polygon Classes to a Simple List of Vertices

Description

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).

Usage

xylist(object, ...)

## S3 method for class 'owin'
xylist(object, ...)

## S3 method for class 'sfg'
xylist(object, ...)

## S3 method for class 'gpc.poly'
xylist(object, ...)

## S3 method for class 'SpatialPolygons'
xylist(object, reverse = TRUE, ...)

## S3 method for class 'Polygons'
xylist(object, reverse = TRUE, ...)

## S3 method for class 'Polygon'
xylist(object, reverse = TRUE, ...)

## Default S3 method:
xylist(object, ...)

Arguments

object

an object of one of the supported spatial classes.

...

(unused) argument of the generic.

reverse

logical (TRUE) indicating if the vertex order of the sp classes should be reversed to get the xylist/owin convention.

Details

Polygon specifications differ with respect to:

  • is the first vertex repeated?

  • which ring direction represents holes?

Package overview:

spatstat.geom:

"owin" does not repeat the first vertex, and anticlockwise = normal boundary, clockwise = hole. This convention is also used for the return value of xylist.

sp:

Repeat first vertex at the end (closed), anticlockwise = hole, clockwise = normal boundary

sf:

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.

gpclib:

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.

Value

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).

Author(s)

Sebastian Meyer


bastistician/polyCub documentation built on Feb. 3, 2024, 5:41 p.m.