Is there a way to remove holes from a polygon in R?

Is there a way to remove holes from a polygon in R?

Is there a way to remove holes from a polygon in R with the package sf? I would be interested in solutions that include other packages, too. Here’s an example of a polygon with two holes.

How to remove columns in a spatialpolygonsdataframe in R?

I know how to do this with a regular data frame in R, but I am unsure how to do this when dealing with object of class SpatialPolygonsDataFrame? Use the syntax object_ name [,- (1:5)] to remove columns 1 to 5 or object_name [,-c (1,5)] to drop columns 1 and 5.

Which is the best way to retain polygons?

Two quick ways to accomplish what your are after are using an index or using subset. This will retain polygons with an area < 10 (dropping those > 10). Thanks for contributing an answer to Geographic Information Systems Stack Exchange!

What’s the best way to read a shapefile?

First, I would highly recommend using readOGR, from the rgdal library, to read your shapefile. It will retain the projection information (proj4string) and save numerous headaches, when string matching, using other functions. Two quick ways to accomplish what your are after are using an index or using subset.

How to get geometry from a SF object?

st_geometry returns an object of class sfc, a list-column with geometries st_geometry returns an object of class sfc. Assigning geometry to a data.frame creates an sf object, assigning it to an sf object replaces the geometry list-column.

How to convert a line to a polygon?

For converting lines to polygons, see also st_polygonize below. convert from XX to MULTIXX, e.g. LINESTRING to MULTILINESTRING convert from MULTIXX to XX if MULTIXX has length one (else, it will still convert but warn about loss of information)

How to create a superclass of a geometry?

This option is handled by the GDAL library; in case of failure to convert to the target type, the original types are returned, which in this case is a mix of POLYGON and MULTIPOLYGON geometries, leading to a GEOMETRY as superclass. When we try to read multipolygons as polygons, all secondary rings of multipolygons get lost.

What can be done with simple feature geometries?

Manipulating Simple Feature Geometries type transformations (e.g., POLYGON to MULTIPOLYGON) transformation into a different coordinate reference system geometrical operations, e.g. finding the centroid of a polygon, detecting whether pairs of feature geometries intersect, or find the union (overlap) of two polygons.