Home > front end >  ArcGIS Dissolve equivalent in R
ArcGIS Dissolve equivalent in R

Time:09-28

I am trying to convert some ArcGIS work into an R-script. I have a shapefile that has 2 variables, one is the FRU(an ID field representing different region names 1 through 60) and a geometry variable (I assume this is showing where these features are located spatially).

What I want is to create a new shapefile that combines the geometry for FRU=o, FRU=1, FRU=2...FRU=60.

So instead of having 26, 967 rows, I have 61 rows.

CodePudding user response:

It is generally good practice to include a reproducible code example with your questions so it is easier for others to help solve the problem. You can pass your data into the dput function in R to get a copy and pasteable version of your data.

For this problem, I would suggest using the sf package:

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

# add a dummy column do dissolve with
nc <- dplyr::mutate(nc, example = c(rep('a', 50), rep('b', 50)))

# group the data by the new column
nc <- dplyr::group_by(nc, example)

# summarize the data
nc <- dplyr::summarise(nc)

Using your example, you would instead say my_data <- dplyr::group_by(my_data, FRU) and then use the same summarise function dplyr::summarise(my_data).

CodePudding user response:

In my opinion, the sf package is the premiere tool for working with spatial data in R. However, there is no dedicated sf::st_dissolve().

Instead you can simply define a grouping variable in your data and use dplyr::group_by and dplyr::summarize. The example is simplified version of examples here (enter image description here

  • Related