SHPDissolve: Shapefile Dissolve Tool

Description Usage Arguments Value Examples

View source: R/SHPDissolve.R

Description

This function automatically dissolves a shapefile based on its feature attributes.

Usage

1
SHPDissolve(my_poly, my_col)

Arguments

my_poly

Either a SpatialPolygonsDataFrame, SpatialPointsDataFrame or SpatialLinesDataFrame.

my_col

The attribute column after which the shapefile should be dissolved.

Value

The dissolved SpatialPolygonsDataFrame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
library(sp)
library(raster)
library(rgdal)
library(rgeos)

# Create test polygons from extents
my_extent1 <- extent(5,7,8,10)
my_extent2 <- extent(7,9,8,10)
my_extent3 <- extent(9,11,8,10)

# Convert extents into "SpatialPolygons"
my_poly1 <- as(my_extent1, 'SpatialPolygons')
my_poly2 <- as(my_extent2, 'SpatialPolygons')
my_poly3 <- as(my_extent3, 'SpatialPolygons')

# Create dataframes
data1 <- data.frame(Id=1)
data2 <- data.frame(Id=2)

# Add the data.drames to the spatial polyongs
spdf1 = SpatialPolygonsDataFrame(my_poly1, data1)
spdf2 = SpatialPolygonsDataFrame(my_poly2, data1)
spdf3 = SpatialPolygonsDataFrame(my_poly3, data2)

# Combine all polygons
spdf_comb <- rbind(spdf1,spdf2,spdf3)

# Dissolve based on Id value
spdf_diss <- SHPDissolve(my_poly = spdf_comb, my_col = "Id")

plot(spdf_comb)
plot(spdf_diss)

MBalthasar/SpatialDataToolbox documentation built on Jan. 29, 2020, 3:15 a.m.