ms_explode: Convert multipart lines or polygons to singlepart

Description Usage Arguments Details Value Examples

View source: R/explode.R

Description

For objects of class Spatial (e.g., SpatialPolygonsDataFrame), you may find it faster to use sp::disaggregate.

Usage

1
ms_explode(input, force_FC = TRUE, sys = FALSE)

Arguments

input

One of:

  • geo_json or character multipart lines, or polygons;

  • geo_list multipart lines, or polygons;

  • multipart SpatialPolygons, SpatialLines;

  • sf or sfc multipart lines, or polygons object

force_FC

should the output be forced to be a FeatureCollection even if there are no attributes? Default TRUE. FeatureCollections are more compatible with rgdal::readOGR and geojsonio::geojson_sp. If FALSE and there are no attributes associated with the geometries, a GeometryCollection will be output. Ignored for Spatial objects, as the output is always the same class as the input.

sys

Should the system mapshaper be used instead of the bundled mapshaper? Gives better performance on large files. Requires the mapshapr node package to be installed and on the PATH.

Details

There is currently no method for SpatialMultiPoints

Value

same class as input

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(geojsonio)
library(sp)

poly <- structure("{\"type\":\"FeatureCollection\",\"crs\":
          {\"type\":\"name\",\"properties\":{\"name\":
          \"urn:ogc:def:crs:OGC:1.3:CRS84\"}},\"features\":
          [\n{\"type\":\"Feature\",\"geometry\":{\"type\":
          \"MultiPolygon\",\"coordinates\":[[[[102,2],[102,3],
          [103,3],[103,2],[102,2]]],[[[100,0],[100,1],[101,1],
          [101,0],[100,0]]]]},\"properties\":{\"rmapshaperid\":0}}\n]}",
          class = c("json", "geo_json"))

poly <- geojson_sp(poly)
plot(poly)
length(poly)
poly@data

# Explode the polygon
out <- ms_explode(poly)
plot(out)
length(out)
out@data

rmapshaper documentation built on April 4, 2018, 1:03 a.m.