Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gpc-polyfile

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

Examples

## None right now.

rgeos

Interface to Geometry Engine - Open Source ('GEOS')

v0.5-5
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Colin Rundel [aut], Edzer Pebesma [ctb], Rainer Stuetz [ctb], Karl Ove Hufthammer [ctb], Patrick Giraudoux [ctb], Martin Davis [cph, ctb], Sandro Santilli [cph, ctb]
Initial release
2020-09-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.