Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain a flattened data frame from the sgbp object produced by the geosbinarypred {sf} function, specifically st_equals, you can use the following process:

  1. Use the st_intersects() function to find the geometries that intersect with each other.
  2. Use the st_binary() function to create the sgbp object for the intersecting geometries.
  3. Use the st_equals() function with the sgbp object to find which geometries are equal to each other.
  4. Use the st_collapse() function to collapse the sgbp object to a list of geometries.
  5. Use the stassf() function to convert the list of geometries to an sf object.
  6. Use the as.data.frame() function to convert the sf object to a data frame.

Here is an example code snippet that demonstrates this process:

library(sf)

# Load example data
nc <- st_read(system.file("shape/nc.shp", package="sf"))

# Find intersecting geometries
intersects <- st_intersects(nc, nc)

# Create sgbp object for intersecting geometries
sgbp <- st_binary(intersects)

# Find equal geometries with sgbp object
equals <- st_equals(sgbp)

# Collapse sgbp object to list of geometries
clusters <- st_collapse(equals)

# Convert list of geometries to sf object
sf_clusters <- st_as_sf(clusters, crs = 4267)

# Convert sf object to data frame
df_clusters <- as.data.frame(sf_clusters)

This will give you a flattened data frame with cluster IDs and the original data attributes.