geo_polygon: Create a polygon 'geom'

View source: R/geo_polygon.R

geo_polygonR Documentation

Create a polygon geom

Description

Create any (regular) polygon geometry (of class geom) either by specifying anchor values or by sketching it.

Usage

geo_polygon(
  crds = NULL,
  window = NULL,
  features = 1,
  vertices = 3,
  regular = FALSE
)

geo_triangle(crds = NULL, window = NULL, features = 1)

geo_square(crds = NULL, window = NULL, features = 1)

geo_rectangle(crds = NULL, window = NULL, features = 1)

geo_hexagon(crds = NULL, window = NULL, features = 1)

as_polygon(geom)

Arguments

crds

data.frame(2)
Coordinates to build the geom from. It must include the column names x and y.

window

data.frame(2)
in case the reference window deviates from the bounding box of crds, specify here the minimum and maximum values in columns x and y.

features

integerish(1)
number of polygons to create.

vertices

integerish(1)
number of vertices per polygon; will be recycled if it does not have as many elements as specified in features.

regular

logical(1)
should the polygon be regular, i.e. point symmetric (TRUE) or should the vertices be selected as provided by anchor (FALSE, default)?

geom

gridded(1)
the geom to cast to type 'polygon'.

Details

The argument regular determines how the vertices provided in anchor or via template are transformed into a polygon:

  • if regular = FALSE the resulting polygon is created from all vertices in anchor,

  • if regular = TRUE, only the first two vertices are considered, as centre and indicating the distance to the (outer) radius.

Value

A geom.

Functions

  • geo_triangle(): wrapper of geo_polygon where vertices = 3 and regular = TRUE.

  • geo_square(): wrapper of geo_polygon where vertices = 4 and regular = TRUE.

  • geo_rectangle(): wrapper of geo_polygon where vertices = 2, regular = FALSE and the two complementing corners are derived from the two given opposing corners.

  • geo_hexagon(): wrapper of geo_polygon where vertices = 6 and regular = TRUE.

See Also

Other geometry shapes: geo_line(), geo_point(), geo_random()

Examples

# 1. create a polygon programmatically
coords <- data.frame(x = c(0, 40, 40, 0),
                     y = c(0, 0, 40, 40))

# if no window is set, the bounding box will be set as window
polyGeom <- geo_polygon(crds = coords)
geo_vis(polyGeom)

# derive a regular polygon from the (first two) coordinates (per feature)
hexaGeom <- geo_polygon(crds = coords, vertices = 6, regular = TRUE)
geo_vis(hexaGeom, linecol = "green")

# 2. cast to point geom from another type
polyGeom <- as_polygon(geom = gtGeoms$point)

geo_vis(gtGeoms$point, linecol = "#FFB000", pointsymbol = 5)
geo_vis(polyGeom, linecol = "#33FF00", new = FALSE)

# 3. sketch a hexagon
if(dev.interactive()){
  aHexagon <- geo_hexagon(features = 1)
  geo_vis(aHexagon, linecol = "#33FF00", linetype = 2, new = FALSE)
}

EhrmannS/geometr documentation built on Jan. 31, 2024, 9:13 a.m.