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

ms_lines

Convert polygons to topological boundaries (lines)


Description

Convert polygons to topological boundaries (lines)

Usage

ms_lines(input, fields = NULL, force_FC = TRUE, sys = FALSE)

Arguments

input

input polygons object to convert to inner lines. One of:

  • geo_json or character polygons;

  • geo_list polygons;

  • SpatialPolygons*;

  • sf or sfc polygons object

fields

character vector of field names. If left as NULL (default), external (unshared) boundaries are attributed as TYPE 0 and internal (shared) boundaries are TYPE 1. Giving a field name adds an intermediate level of hierarchy at TYPE 1, with the lowest-level internal boundaries set to TYPE 2. Supplying a character vector of field names adds additional levels of hierarchy.

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.

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.

Value

topological boundaries as lines, in the same class as the input

Examples

library(geojsonio)
library(sp)

poly <- structure('{"type":"FeatureCollection",
             "features":[
             {"type":"Feature",
             "properties":{"foo": "a"},
             "geometry":{"type":"Polygon","coordinates":[[
             [102,2],[102,3],[103,3],[103,2],[102,2]
             ]]}}
             ,{"type":"Feature",
             "properties":{"foo": "a"},
             "geometry":{"type":"Polygon","coordinates":[[
             [103,3],[104,3],[104,2],[103,2],[103,3]
             ]]}},
             {"type":"Feature",
             "properties":{"foo": "b"},
             "geometry":{"type":"Polygon","coordinates":[[
             [102.5,1],[102.5,2],[103.5,2],[103.5,1],[102.5,1]
             ]]}}]}', class = c("json", "geo_json"))

poly <- geojson_sp(poly)
summary(poly)
plot(poly)

out <- ms_lines(poly)
summary(out)
plot(out)

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.