Create a ggplot-friendly data frame from a spatial object

df_spatial(x, ...)

Arguments

x

A spatial object

...

Passed to specific methods

Value

A tibble with coordinates as x and y, features as feature_id, and parts as part_id.

Examples

# \donttest{
load_longlake_data(which = c("longlake_osm", "longlake_depthdf"))
df_spatial(longlake_osm)
#> # A tibble: 260,463 × 5
#>          x        y band1 band2 band3
#>      <dbl>    <dbl> <dbl> <dbl> <dbl>
#>  1 409893. 5084851.   180   217   163
#>  2 409896. 5084851.   184   219   164
#>  3 409900. 5084851.   189   223   167
#>  4 409903. 5084851.   186   223   166
#>  5 409906. 5084851.   166   210   157
#>  6 409910. 5084851.   163   208   156
#>  7 409913. 5084851.   160   206   155
#>  8 409916. 5084851.   154   202   151
#>  9 409920. 5084851.   156   203   152
#> 10 409923. 5084851.   149   199   150
#> # … with 260,453 more rows
df_spatial(longlake_depthdf)
#> # A tibble: 64 × 10
#>          x        y feature_id part_id WAYPOIN…¹   LAT   LON DEPTH NOTES DEPTH_M
#>      <dbl>    <dbl>      <int>   <int>     <dbl> <dbl> <dbl> <dbl> <chr>   <dbl>
#>  1 411659. 5084501.          1       1         2  45.9 -64.1   2.5 mout…     0.8
#>  2 411630. 5084560.          2       1         3  45.9 -64.1   3.1 NA        0.9
#>  3 411553. 5084601.          3       1         5  45.9 -64.1   2.5 NA        0.8
#>  4 411476. 5084600.          4       1         6  45.9 -64.1   2.5 NA        0.8
#>  5 411467. 5084488.          5       1         8  45.9 -64.1   4.5 NA        1.4
#>  6 411466. 5084410.          6       1        10  45.9 -64.1   2   NA        0.6
#>  7 411379. 5084490.          7       1        12  45.9 -64.1   4.7 NA        1.4
#>  8 411321. 5084721.          8       1        16  45.9 -64.1   2.5 NA        0.8
#>  9 411293. 5084670.          9       1        17  45.9 -64.1   4.7 NA        1.4
#> 10 411291. 5084593.         10       1        19  45.9 -64.1   5   NA        1.5
#> # … with 54 more rows, and abbreviated variable name ¹​WAYPOINT_I
df_spatial(as(longlake_depthdf, "Spatial"))
#> # A tibble: 64 × 10
#>          x        y feature_id part_id WAYPOIN…¹   LAT   LON DEPTH NOTES DEPTH_M
#>      <dbl>    <dbl>      <int>   <int>     <dbl> <dbl> <dbl> <dbl> <chr>   <dbl>
#>  1 411659. 5084501.          1       1         2  45.9 -64.1   2.5 mout…     0.8
#>  2 411630. 5084560.          2       1         3  45.9 -64.1   3.1 NA        0.9
#>  3 411553. 5084601.          3       1         5  45.9 -64.1   2.5 NA        0.8
#>  4 411476. 5084600.          4       1         6  45.9 -64.1   2.5 NA        0.8
#>  5 411467. 5084488.          5       1         8  45.9 -64.1   4.5 NA        1.4
#>  6 411466. 5084410.          6       1        10  45.9 -64.1   2   NA        0.6
#>  7 411379. 5084490.          7       1        12  45.9 -64.1   4.7 NA        1.4
#>  8 411321. 5084721.          8       1        16  45.9 -64.1   2.5 NA        0.8
#>  9 411293. 5084670.          9       1        17  45.9 -64.1   4.7 NA        1.4
#> 10 411291. 5084593.         10       1        19  45.9 -64.1   5   NA        1.5
#> # … with 54 more rows, and abbreviated variable name ¹​WAYPOINT_I
# }