Build an sf Object of Tweets

as_tweet_sf(
  tweet_df,
  geom_col = c("bbox_coords", "quoted_bbox_coords", "retweet_bbox_coords", "geo_coords",
    "all"),
  combine = TRUE,
  as_tibble = tweetio_as_tibble(),
  ...
)

Arguments

tweet_df

A data frame of tweets, as obtained by read_tweets() or one of {rtweet}'s collection functions, e.g. rtweet::search_tweets().

geom_col

Which column to use as the active geometry column in result: "bbox_coords", "quoted_bbox_coords","retweet_bbox_coords", "geo_coords", or "all".

combine

logical(1L), Default: TRUE. Whether to row-bind all geometries into a single sf::st_sf() object. If FALSE, a list() of sf::st_sf() objects are returned.

as_tibble

<logical>, Default: tweetio_as_tibble(). Whether a tibble::tibble() should be returned. Ignored if the {tibble} package is not installed.

...

Arguments passed to or from other methods.

Value

sf::st_sf(), or list() of sf::st_sf() objects if combine = FALSE

Examples

path_to_tweet_file <- example_tweet_file() tweet_df <- read_tweets(file_path = path_to_tweet_file) bbox_coords <- as_tweet_sf(tweet_df) rwtweet_bbox_cooords <- as_tweet_sf(tweet_df, geom_col = "retweet_bbox_coords") tweet_sf <- as_tweet_sf(tweet_df, geom_col = "all", as_tibble = TRUE) tweet_sf[, c("created_at", "text", "which_geom", "geometry")]
#> Simple feature collection with 685 features and 3 fields #> geometry type: POLYGON #> dimension: XY #> bbox: xmin: -157.9505 ymin: -55.11686 xmax: 171.1442 ymax: 63.99495 #> epsg (SRID): 4326 #> proj4string: +proj=longlat +datum=WGS84 +no_defs #> # A tibble: 685 x 4 #> created_at text which_geom geometry #> <dttm> <chr> <chr> <POLYGON [°]> #> 1 2019-09-28 18:05:24 "@_CeeDeeThre… bbox_coor… ((-97.51982 35.15327, -97.5198… #> 2 2019-09-28 18:05:25 "Foto appena … bbox_coor… ((8.665852 44.37908, 8.665852 … #> 3 2019-09-28 18:05:25 "@EsrodKatia … bbox_coor… ((-106.9506 31.12068, -106.950… #> 4 2019-09-28 18:05:27 "Mi viejo fue… bbox_coor… ((-63.39386 -41.03501, -63.393… #> 5 2019-09-28 18:05:30 "@Sanatsalkol… bbox_coor… ((30.42998 39.76794, 30.42998 … #> 6 2019-09-28 18:05:31 "I’m calling … bbox_coor… ((-118.6684 33.70454, -118.668… #> 7 2019-09-28 18:05:32 "@t_Ace_ZERO … bbox_coor… ((139.136 36.24259, 139.136 36… #> 8 2019-09-28 18:05:32 "@crz_updates… bbox_coor… ((135.5633 34.68448, 135.5633 … #> 9 2019-09-28 18:05:36 "Volunteering… bbox_coor… ((-119.0618 34.12687, -119.061… #> 10 2019-09-28 18:05:38 "Un hermoso s… bbox_coor… ((-63.78454 -35.6894, -63.7845… #> # … with 675 more rows