Learn R Programming

fsr (version 1.0.0)

as_tibble.pgeometry: Converting a pgeometry object into tabular data

Description

We can convert a pgeometry object into tabular data, such as a tibble or data.frame object, where the components of the pgeometry object compose the rows of the table.

Usage

# S3 method for pgeometry
as.data.frame(x, ...)

# S3 method for pgeometry as_tibble(x, ...)

Arguments

x

A pgeometry object.

...

<dynamic-dots> Unused.

Value

A tibble object of size n x 2 where n is the number of components of the pgeometry object and two columns in the format (md, geometry).

Details

This function is an interface for the S3 generic as_tibble. Here, it turns a pgeometry object into a tibble, which is a data frame with class tbl_df. This allows us to get the internal components of the pgeometry object (i.e., spatial features objects and membership degrees) as a data frame with two separate columns - called md (membership degree) and geometry (an sfc object).

For each component of the pgeometry object, as_tibble gets the md and geometry values and allocates them into a row of the new created tibble, in separated columns. Therefore, each row of this tibble represents a component of the original pgeometry object.

It is also possible to call the S3 method as.data.frame to convert a pgeometry object into tabular data.

Examples

Run this code
# NOT RUN {
library(sf)

# Creating components for our plateau point object
v1 <- rbind(c(1,2), c(3,4))
v2 <- rbind(c(1,4), c(2,3),c(4,4))

md1 <- 0.2
md2 <- 0.1
md3 <- 0.4
pts1 <- rbind(c(1, 2), c(3, 2))
pts2 <- rbind(c(1, 1), c(2, 3), c(2, 1))
pts3 <- rbind(c(2, 2), c(3, 3))

comp1 <- component_from_sfg(st_multipoint(pts1), md1)
comp2 <- component_from_sfg(st_multipoint(pts2), md2)
comp3 <- component_from_sfg(st_multipoint(pts3), md3)

# Creating the plateau point object as a pgeometry object with 3 components

plateau_point <- create_pgeometry(list(comp1, comp2, comp3), "PLATEAUPOINT")

# Converting the pgeometry object into a tibble object
plateau_point_tibble <- as_tibble(plateau_point)

plateau_point_tibble

# }

Run the code above in your browser using DataLab