polyfile {rgeos} | R Documentation

## Read/Write polygon data

### Description

Read/Write polygon and contour information from/to a text file.

### Usage

    read.polyfile(filename, nohole = TRUE)
    write.polyfile(poly, filename = "GPCpoly.txt")

### Arguments

`filename` | the name of the file (a character string) from/to which data should be read/written.
`nohole` | Is this a polygon without holes?
`poly` | an object of class `"gpc.poly"`

### Details

The text file representation of a polygon is of the following format:

<number of contours>
<number of points in first contour>
x1 y1
x2 y2
...
<number of points in second contour>
x1 y1
x2 y2
...

For example, a data file for a polygon with 2 contours (a four-sided object and a triangle) might look like:

2
4
1.0 1.0
1.0 2.0
3.4 3.21
10 11.2
3
21.0 11.2
22.3 99.2
4.5 5.4

The vertices of the polygon can be ordered either clockwise or counter-clockwise.

If a polygon has contours which are holes, then the format is slightly different. Basically, a flag is set to indicate that a particular contour is a hole. The format is

<number of contours>
<number of points in first contour>
<hole flag>
x1 y1
x2 y2
...
<number of points in second contour>
<hole flag>
x1 y1
x2 y2
...

The hole flag is either 1 to indicate a hole, or 0 for a regular contour. For example, a four-sided polygon with a triangular hole would be written as:

2
3
1
4.0 4.0
6.0 5.0
5.0 6.0
4
0
2.0 1.0
8.0 2.0
7.0 9.0
1.0 7.0

### Value

If `nohole` is `TRUE` (the default) `read.polyfile` returns an object of class `"gpc.poly.nohole"`. This object has the hole flag set to `FALSE` for all contours. If `nohole` is `FALSE`, then an object of class `"gpc.poly"` is returned.

`write.polyfile` does not return anything useful.

### Author(s)

Roger D. Peng

### See Also

`gpc.poly-class`, `gpc.poly.nohole-class`

### Examples

    ## None right now.

[Package rgeos version 0.5-1 Index]