I am trying to plot buildings from osm using the leaflet-package in R. Unfortunately with little success and I couldn't find a reproducible example.
In a first step, I define the bounding box and add the 'feature' building:
library(dplyr)
library(osmdata)
q1 <- getbb("steckborn, switzerland") %>%
opq() %>%
add_osm_feature("building")
In a next step, I pass the query to overpass and extract the polygons:
out <- osmdata_sf(q1)
poly <- out$osm_polygons
Now comes the tricky part. How can I plot them using leaflet? I tried the following:
library(leaflet)
leaflet() %>% addTiles() %>% addPolygons(lines, col = "blue")