texture: Creates a pattern for a layer with a given function

Description Usage Arguments Value Examples

View source: R/texture.R

Description

For each horizon name there should be a function which creates a corresponding pattern. This function applies the pattern function and creates a new layer. This new layer is smaller than the original layer due to a defined buffer.This is a helper function of the apply_texture. Here only pattern for one horizont is generated. With the apply_texture the whole profile will be created as a pattern.

Usage

1
texture(shape, fun_horizont, buffer, ...)

Arguments

shape

A Simple Features with one row (one geometry). At least with one geometry column and one "nameC" column (C for character)

fun_horizont

A function that creates a pattern for this specific horizon.

buffer

Usually a negative value that indicates the distance between the pattern and the horizon boundary.

...

is passed on to the specific texture function

Value

This function returns a new Simple Features which contains all informations (columns) of the Input Simple Features (shape). Columns with the graphic parameters are added. Adding patterns to the given layer can result in multiple geometries. (e.g. points and lines). To save this information, rows are added to the dataset

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
## Example data with one horizont (Ah)
library(dplyr)
library(sf)
df_example <- data.frame(x = c(0, 20, 20, 0, 0), 
y = c(0, 0, 20, 20,0), 
nameC = rep("Ah", 5))

## Build an Simple Features
shape_example <- df_example %>% 
st_as_sf(coords = c("x", "y")) %>% 
group_by(nameC) %>% 
summarise(do_union = FALSE) %>%
st_cast("POLYGON") %>%
st_cast("MULTIPOLYGON") 

## example Function
fun_example <- function(polygon){
st_sample(polygon, size = 50) %>%
st_union() %>% 
st_sf(parID = 1)
}


## Apply Function
texture_example <- texture(shape = shape_example,
fun_horizont = fun_example, 
buffer = -1)

##Plotting
library(ggplot2)

texture_example %>% 
ggplot() + 
geom_sf()
 

nardusstricta/soilprofile2 documentation built on May 23, 2019, 6:04 p.m.