Ask Your Question
2

What is the process for obtaining a flattened dataframe from the sgbp object produced by the geos_binary_pred {sf} function, specifically st_equals?

asked 2022-10-08 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-29 07:00:00 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-08 11:00:00 +0000

Seen: 18 times

Last updated: Jun 29 '21