Skip to contents

Given an rsgeo class object, extract the object's coordinates as a data frame. Empty or missing geometries are ignored.

Usage

coords(x)

Arguments

x

an object of class rsgeo

Value

A data.frame with columns x, y. Additional columns are returned based on the geometry type. Additional columns are:

  • id

  • line_id: refers to the LineString ID for rs_LINESTRING, or the component LineString in a MultiLineString, or as the ring ID for a Polygon.

  • multilinestring_id

  • polygon_id

  • multipolygon_id

Examples

pnt <- geom_point(3, 0.14)
mpnt <- geom_multipoint(1:10, 10:1)
ln <- geom_linestring(1:10, 10:1)
ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0))

coords(pnt)
#>   x    y
#> 1 3 0.14
coords(mpnt)
#>     x  y id
#> 1   1 10  1
#> 2   2  9  1
#> 3   3  8  1
#> 4   4  7  1
#> 5   5  6  1
#> 6   6  5  1
#> 7   7  4  1
#> 8   8  3  1
#> 9   9  2  1
#> 10 10  1  1
coords(ln)
#>     x  y line_id
#> 1   1 10       1
#> 2   2  9       1
#> 3   3  8       1
#> 4   4  7       1
#> 5   5  6       1
#> 6   6  5       1
#> 7   7  4       1
#> 8   8  3       1
#> 9   9  2       1
#> 10 10  1       1
coords(union_geoms(rep(ln, 2)))
#>     x  y line_id multilinestring_id
#> 1   1 10       1                  1
#> 2   2  9       1                  1
#> 3   3  8       1                  1
#> 4   4  7       1                  1
#> 5   5  6       1                  1
#> 6   6  5       1                  1
#> 7   7  4       1                  1
#> 8   8  3       1                  1
#> 9   9  2       1                  1
#> 10 10  1       1                  1
#> 11  1 10       2                  1
#> 12  2  9       2                  1
#> 13  3  8       2                  1
#> 14  4  7       2                  1
#> 15  5  6       2                  1
#> 16  6  5       2                  1
#> 17  7  4       2                  1
#> 18  8  3       2                  1
#> 19  9  2       2                  1
#> 20 10  1       2                  1
coords(ply)
#>   x y line_id polygon_id
#> 1 0 0       1          1
#> 2 1 0       1          1
#> 3 1 1       1          1
#> 4 0 1       1          1
#> 5 0 0       1          1
coords(union_geoms(rep(ply, 2)))
#>   x y line_id polygon_id multipolygon_id
#> 1 1 0       1          1               1
#> 2 1 1       1          1               1
#> 3 0 1       1          1               1
#> 4 0 0       1          1               1
#> 5 1 0       1          1               1