Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ms_explode

Convert multipart lines or polygons to singlepart


Description

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

Usage

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 mapshaper node package to be installed and on the PATH.

Details

There is currently no method for SpatialMultiPoints

Value

same class as input

Examples

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

Client for 'mapshaper' for 'Geospatial' Operations

v0.4.4
MIT + file LICENSE
Authors
Andy Teucher [aut, cre], Kenton Russell [aut] (JavaScript support), Matthew Bloch [cph] (mapshaper Javascript library)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.