Convert a pgeometry object into tabular data (data.frame or tibble)
Source: R/basic_functions.R
as_tibble.pgeometry.RdThese functions convert a pgeometry object into a tabular format, 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_tibble(x, ...)
# S3 method for pgeometry
as.data.frame(x, ...)Arguments
- x
A
pgeometryobject.- ...
<
dynamic-dots> Unused.
Value
A tabular object (data.frame or tibble) with the number of rows corresponding to the number of components of
the pgeometry object given as input and two columns in the format (geometry, md).
Details
These functions are S3 methods for pgeometry.
The as_tibble() function converts 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: (i) geometry (an sfc object) and (ii) md (membership degree).
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 a data.frame object.
Examples
pcomp1 <- create_component("MULTIPOINT(1 2, 3 2)", 0.4)
pcomp2 <- create_component("POINT(2 1)", 0.3)
pcomp3 <- create_component("MULTIPOINT(5 1, 0 0)", 1)
ppoint <- create_pgeometry(list(pcomp1, pcomp2, pcomp3), "PLATEAUPOINT")
# Converting the pgeometry object into a tibble object
ppoint_tibble <- as_tibble(ppoint)
ppoint_tibble
#> # A tibble: 3 × 2
#> geometry md
#> <GEOMETRY> <dbl>
#> 1 POINT (2 1) 0.3
#> 2 MULTIPOINT ((1 2), (3 2)) 0.4
#> 3 MULTIPOINT ((5 1), (0 0)) 1
# Converting it into data.frame
ppoint_df <- as.data.frame(ppoint)
ppoint_df
#> geometry md
#> 1 POINT (2 1) 0.3
#> 2 MULTIPOINT ((1 2), (3 2)) 0.4
#> 3 MULTIPOINT ((5 1), (0 0)) 1.0