split_polygon: Split soil profile

Description Usage Arguments Value Examples

View source: R/split_polygon.R

Description

This fuction splits the whole soil profile into individual horizons using lines. If you do not want a straight line as a horizon transition, you can use this function to create various transition shapes.

Usage

1

Arguments

polygon

A simple feature multipolygon, which can been build by the sf_polygon function. The simple feature should be have at least a geom column. In any case, the order of the raws should be the same as the real order of the horizons. The top horizon must appear in the first line.

line

A simple feature multiline, which can been build by the line_mod function. The simple feature should be have at least a geometry column and a name column with the Id. In any case, the order of the raws should be the same as the real order of the horizons. The uppermost line (i.e. the first line) represents the surface of the earth. Each additional line represents the upper horizon limit.

Value

A new simple feature with one line for each horizont and the columns for the atttributes.

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
41
42
library(dplyr)
## Example data
data_example <- data.frame(name = c(1, 2),
                          from1 = c(0,20),
                          to1 = c(20, 40)
)
 
 ##Coordination setting
 cord_example <- cord_setting(data_example, plot_width = 3)
 
 ## build simple feature
 poly_example <- sf_polygon(df_geom = cord_example)
 
 ## Line attributes data frame:
 lattri_example <- data.frame(name= unique(cord_example$name),
                              numberX = c(2, 10),
                              sd = c(1,1),
                              sm = c(TRUE, TRUE)
 )
 
 ## Apply the line_mod fuction
 line_example <- line_mod(df = cord_example, line_attri = lattri_example)
 
 ## Split the Profile with the new line shape:
 example_profile <- split_polygon(polygon = poly_example,
                                  line = line_example) %>%
   #join by the id (name) user-defined properties
   left_join(data.frame(name = c(1,2),
                        rgb_col = c("#6F5F4CFF", "#947650FF")
   ), by = "name")
 
 ## Plot simple feature geometry
 library(ggplot2)
 example_profile %>%
   ggplot() +
   geom_sf(fill = example_profile$rgb_col) +
   geom_text(label = c("Ah", "Bv"),
             x = c(10, 10), y = c(-10,-30)) +
   theme(axis.title.x=element_blank(),
         axis.text.x=element_blank(),
         axis.ticks.x=element_blank(),
         panel.background = element_blank())

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