library(gibble)

The gibble package provides a basic unit of information about the structure of a spatial data set. The key idea is of a part of spatial data, and the ways these are arranged hierarchically in spatial formats.

If we consider a very simple polygon layer, as understood by the sf package the structure is pretty simple. There are two objects (features), and the first of those has two parts - here we call them paths, because they are represented as a sequence of coordinates.

library(sf)
plot(minimal_mesh)

minimal

The gibble() function tells us about this structure

gibble(minimal_mesh)
#> # A tibble: 3 x 5
#>    nrow  ncol type         subobject object
#>   <int> <int> <chr>            <int>  <int>
#> 1     8     2 MULTIPOLYGON         1      1
#> 2     6     2 MULTIPOLYGON         1      1
#> 3     5     2 MULTIPOLYGON         1      2

and works on much more complicated data sets.

gibble(mpoly)
#> # A tibble: 61 x 5
#>     nrow  ncol type         subobject object
#>    <int> <int> <chr>            <int>  <int>
#>  1     6     2 MULTIPOLYGON         1      1
#>  2     4     2 MULTIPOLYGON         1      1
#>  3     5     2 MULTIPOLYGON         2      1
#>  4     5     2 MULTIPOLYGON         2      1
#>  5     4     2 MULTIPOLYGON         3      1
#>  6  4434     2 MULTIPOLYGON         1      2
#>  7   158     2 MULTIPOLYGON         1      2
#>  8   707     2 MULTIPOLYGON         1      2
#>  9   968     2 MULTIPOLYGON         1      2
#> 10  1405     2 MULTIPOLYGON         1      2
#> # … with 51 more rows

The gibble() function works for data in the formats used by sf, sp, trip, and silicate. This eases the development of tools that work with these formats, because they all have the same underlying structure and we can find out the number of objects there are, how many paths those objects have, and how many coordinates each path includes without considering the way they are represented.