# wkt-functions: RGEOS WKT Functions In rgeos: Interface to Geometry Engine - Open Source ('GEOS')

 RGEOS WKT Functions R Documentation

## RGEOS WKT Functions

### Description

Functions for reading and writing Well Known Text (WKT)

### Usage

``````	readWKT(text, id = NULL, p4s = NULL)
writeWKT(spgeom, byid = FALSE)
``````

### Arguments

 `text` character string of WKT `id` character vector of unique ids to label geometries. Length must match the number of subgeometries in the WKT `p4s` Either a character string or an object of class `CRS` `spgeom` sp object as defined in package sp `byid` Logical determining if the function should be applied across subgeometries (TRUE) or the entire object (FALSE)

### Details

readWKT processes the given WKT string and returns an appropriate sp geometry object. If id is not specified then geometries will be labeled by their index position. Because no sp Spatial object may be empty, `readWKT` is not permitted to create an empty object.

writeWKT converts an sp geometry object to a GEOS C object which is then written out as a WKT string. If byid is TRUE then each subgeometry is individually converted to a WKT string.

Colin Rundel

### References

Additional information on WKT Simple Feature Specification can be found at the following locations:

### Examples

``````g1=readWKT("POINT(6 10)")
g3=readWKT("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))")
g5=readWKT("MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))")
g6=readWKT("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))")

writeWKT(g1)
writeWKT(g2)
writeWKT(g3)
writeWKT(g4)
writeWKT(g5)
writeWKT(g6)
writeWKT(g9,byid=FALSE)
writeWKT(g9,byid=TRUE)
``````

rgeos documentation built on July 26, 2023, 5:42 p.m.