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
#> # ℹ 260,453 more rows
df_spatial(longlake_depthdf)
#> # A tibble: 64 × 10
#>          x       y feature_id part_id WAYPOINT_I   LAT   LON DEPTH NOTES DEPTH_M
#>      <dbl>   <dbl>      <int>   <int>      <dbl> <dbl> <dbl> <dbl> <chr>   <dbl>
#>  1 411659.  5.08e6          1       1          2  45.9 -64.1   2.5 mout…     0.8
#>  2 411630.  5.08e6          2       1          3  45.9 -64.1   3.1 NA        0.9
#>  3 411553.  5.08e6          3       1          5  45.9 -64.1   2.5 NA        0.8
#>  4 411476.  5.08e6          4       1          6  45.9 -64.1   2.5 NA        0.8
#>  5 411467.  5.08e6          5       1          8  45.9 -64.1   4.5 NA        1.4
#>  6 411466.  5.08e6          6       1         10  45.9 -64.1   2   NA        0.6
#>  7 411379.  5.08e6          7       1         12  45.9 -64.1   4.7 NA        1.4
#>  8 411321.  5.08e6          8       1         16  45.9 -64.1   2.5 NA        0.8
#>  9 411293.  5.08e6          9       1         17  45.9 -64.1   4.7 NA        1.4
#> 10 411291.  5.08e6         10       1         19  45.9 -64.1   5   NA        1.5
#> # ℹ 54 more rows
df_spatial(as(longlake_depthdf, "Spatial"))
#> # A tibble: 64 × 10
#>          x       y feature_id part_id WAYPOINT_I   LAT   LON DEPTH NOTES DEPTH_M
#>      <dbl>   <dbl>      <int>   <int>      <dbl> <dbl> <dbl> <dbl> <chr>   <dbl>
#>  1 411659.  5.08e6          1       1          2  45.9 -64.1   2.5 mout…     0.8
#>  2 411630.  5.08e6          2       1          3  45.9 -64.1   3.1 NA        0.9
#>  3 411553.  5.08e6          3       1          5  45.9 -64.1   2.5 NA        0.8
#>  4 411476.  5.08e6          4       1          6  45.9 -64.1   2.5 NA        0.8
#>  5 411467.  5.08e6          5       1          8  45.9 -64.1   4.5 NA        1.4
#>  6 411466.  5.08e6          6       1         10  45.9 -64.1   2   NA        0.6
#>  7 411379.  5.08e6          7       1         12  45.9 -64.1   4.7 NA        1.4
#>  8 411321.  5.08e6          8       1         16  45.9 -64.1   2.5 NA        0.8
#>  9 411293.  5.08e6          9       1         17  45.9 -64.1   4.7 NA        1.4
#> 10 411291.  5.08e6         10       1         19  45.9 -64.1   5   NA        1.5
#> # ℹ 54 more rows
# }