Remove features or portions of features that fall inside a specified area

Share:

Description

Removes portions of the target layer that fall inside the erasing layer or bounding box.

Usage

1
ms_erase(target, erase = NULL, bbox = NULL, force_FC = TRUE)

Arguments

target

the target layer from which to remove portions. One of:

  • geo_json or character points, lines, or polygons;

  • geo_list points, lines, or polygons;

  • SpatialPolygons, SpatialLines, SpatialPoints

erase

the erase layer (polygon). One of:

  • geo_json or character polygons;

  • geo_list polygons;

  • SpatialPolygons*

bbox

supply a bounding box instead of an erasing layer to remove from the target layer. Supply as a numeric vector: c(minX, minY, maxX, maxY).

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.

Value

erased target in the same format as the input target

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
33
34
35
36
37
38
39
40
41
library(geojsonio, quietly = TRUE)
library(sp)

points <- structure("{\"type\":\"FeatureCollection\",
  \"features\":[{\"type\":\"Feature\",\"properties\":{},
  \"geometry\":{\"type\":\"Point\",\"coordinates\":
  [52.8658,-44.7219]}},{\"type\":\"Feature\",\"properties\":{},
  \"geometry\":{\"type\":\"Point\",\"coordinates\":
  [53.7702,-40.4873]}},{\"type\":\"Feature\",\"properties\":{},
  \"geometry\":{\"type\":\"Point\",\"coordinates\":[55.3204,-37.5579]}},
  {\"type\":\"Feature\",\"properties\":{},\"geometry\":
  {\"type\":\"Point\",\"coordinates\":[56.2757,-37.917]}},
  {\"type\":\"Feature\",\"properties\":{},\"geometry\":
  {\"type\":\"Point\",\"coordinates\":[56.184,-40.6443]}},
  {\"type\":\"Feature\",\"properties\":{},\"geometry\":
  {\"type\":\"Point\",\"coordinates\":[61.0835,-40.7529]}},
  {\"type\":\"Feature\",\"properties\":{},\"geometry\":
  {\"type\":\"Point\",\"coordinates\":[58.0202,-43.634]}}]}", 
  class = c("json", "geo_json"))
points <- geojson_sp(points)

erase_poly <- structure('{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[51, -40],
[55, -40],
[55, -45],
[51, -45],
[51, -40]
]
]
}
}', class = c("json", "geo_json"))
erase_poly <- geojson_sp(erase_poly)

out <- ms_erase(points, erase_poly)
plot(out, add = TRUE)