if (rmapshaper:::check_v8_major_version() >= 6L) {
library(geojsonsf, quietly = TRUE)
library(sf)
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("geojson", "json"))
points <- geojson_sf(points)
plot(points)
erase_poly <- structure('{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[51, -40],
[55, -40],
[55, -45],
[51, -45],
[51, -40]
]
]
}
}', class = c("geojson", "json"))
erase_poly <- geojson_sf(erase_poly)
out <- ms_erase(points, erase_poly)
plot(out, add = TRUE)
}
Run the code above in your browser using DataLab