geomPolygon: Create a polygon geometry

Description Usage Arguments Details Value Functions See Also Examples

View source: R/geometries.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
geomPolygon(anchor = NULL, window = NULL, template = NULL,
  features = 1, vertices = NULL, regular = FALSE, show = FALSE,
  ...)

geomTriangle(anchor = NULL, window = NULL, template = NULL,
  features = 1, show = FALSE, ...)

geomSquare(anchor = NULL, window = NULL, template = NULL,
  features = 1, show = FALSE, ...)

geomRectangle(anchor = NULL, window = NULL, template = NULL,
  features = 1, show = FALSE, ...)

geomHexagon(anchor = NULL, window = NULL, template = NULL,
  features = 1, show = FALSE, ...)

Arguments

anchor

[geom | data.frame(1)]
Object to derive the geom from. In case of data.frame, it must include column names x, y and optinal variables such as id; see Examples.

window

[data.frame(1)]
in case the reference window deviates from the bounding box of anchor (minimum and maximum values), specify this here.

template

[RasterLayer(1) | matrix(1)]
Gridded object that serves as template to sketch the geometry.

features

[integerish(1)]
number of geometries to create.

vertices

[integerish(.)]
number of vertices per geometry; 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 according to anchor or vertices (FALSE, default)?

show

[logical(1)]
should the geometry be plotted (TRUE) or should it not be plotted (FALSE, default)? In case template is set, it is automatically TRUE.

...

[various]
graphical parameter, in case show = TRUE; see gpar.

Details

The arguments anchor and template have NULL value, because leaving them unset is meant to result in a specific behaviour:

Value

An invisible geom.

Functions

See Also

Tools to modify geometries: gRotate, gScale, gGroup
Tools to transform geometries to other classes: gToSp, gToSf, gToRaster, gFrom

Other shapes: geomPoint, geomRand

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# create a polygon programmatically
coords <- data.frame(x = c(40, 70, 70, 50),
                     y = c(40, 40, 60, 70))
window <- data.frame(x = c(0, 80),
                     y = c(0, 80))
                     
# if no window is set, the bounding box (i.e. min/max values) will be set as window
(aGeom <- geomPolygon(anchor = coords))

# the vertices are plottet relative to the window
aTriangle <- geomPolygon(anchor = coords, window = window, vertices = 3, regular = TRUE, 
                         fill = "darkorange", show = TRUE)
(geomHexagon(anchor = coords, col = "green", show = TRUE))

# if a geom is used in 'anchor', its properties (e.g. 'window') are passed on
grid::grid.newpage()
aGeom <- geomPolygon(anchor = coords, window = window, fill = "deeppink", show = TRUE)
anExtent <- geomRectangle(anchor = aGeom, show = TRUE)

# geoms with more than one element are treated element-wise
aGeom <- gGroup(geom = aGeom, index = c(1, 2, 1, 2))
visualise(geom = aGeom)
itsExtent <- geomRectangle(anchor = aGeom, show = TRUE)

## Not run: 

input <- rtData$continuous

# create a square interactively
squareGeom <- geomSquare(template = input, show = TRUE, col = "orange")

# ... or an approximate circle (actually a hectogon)
circleGeom <- geomPolygon(template = input, vertices = 100, regular = TRUE,
                          show = TRUE, col = "deeppink")

# create two arbitrary polygons interactively
polyGeom <- geomPolygon(template = input, features = 2, vertices = c(4, 6),
                        col = "green", lwd = 1, lty = "dashed", show = TRUE)

## End(Not run)

EhrmannS/rasterTools documentation built on Feb. 4, 2019, 11:22 a.m.