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

xylist {polyCub} | R 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 polygons by their 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

- `"gpc.poly"` from package rgeos (or gpclib)

- `"Polygons"` from package sp (as well as `"Polygon"` and `"SpatialPolygons"`)

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 '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

Different packages concerned with spatial data use different polygon specifications with respect to:

- do we repeat the first vertex?

- which direction represents holes?

Package overview:

sp:

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

spatstat:

  do not repeat first vertex, anticlockwise = normal boundary, clockwise = hole. This convention is also used in `xylist`.

gpclib:

  Unfortunately, there seems to be no convention for the specification of polygons of class `"gpc.poly"`.

### 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's `"owin"` convention (anticlockwise order without repeating any vertex). The opposite vertex order can be retained for the sp-classes by the non-default use with `reverse=FALSE`.

### Author(s)

Sebastian Meyer

[Package polyCub version 0.7.1 Index]