Skip to contents

Cast geometries to another type

Usage

cast_geoms(x, to)

Arguments

x

an object of class rsgeo

to

a character scalar of the target geometry type. Must be one of "point", "multipoint", "polygon", "multipolygon", "linestring", or "multilinestring".

Value

An object of class rsgeo

Details

The below conversions are made available. The left hand column indicates the originating vector class and the right hand column indicates the class that it will can be cast to.

Note that correctness of conversions will not be checked or verified. If you cast an rs_MULTIPOINT to an rs_POLYGON, the validity of the polygon cannot be guaranteed.

Conversions from an rs_POLYGON into an rs_LINESTRING will result in only the exterior ring of the polygon ignoring any interrior rings if there are any.

FromTo
rs_POINTrs_MULTIPOINT
rs_MULTIPOINTrs_POLYGON, rs_MULTIPOLYGON, rs_LINESTRING, rs_MULTILINESTRING
rs_POLYGONrs_MULTIPOINT, rs_MULTIPOLYGON, rs_LINESTRING, rs_MULTILINESTRING
rs_MULTIPOLYGONrs_MULTIPOINT, rs_MULTILINESTRING
rs_LINESTRINGrs_MULTIPOINT, rs_MULTILINESTRING, rs_POLYGON
rs_MULTILINESTRINGrs_MULTIPOINT, rs_MULTIPOLYGON

Examples

ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0))
cast_geoms(ply, "linestring")
#> <rs_LINESTRING[1]>
#> [1] LineString([Coord { x: 0.0, y: 0.0 }, Coord { x: 1.0, y: 0.0 }, Coord { x:...
cast_geoms(ply, "multipoint")
#> <rs_MULTIPOINT[1]>
#> [1] MultiPoint([Point(Coord { x: 0.0, y: 0.0 }), Point(Coord { x: 1.0, y: 0.0 ...