Hi,
I have downloaded data using OSM data and I want to show the data in leaflet using the polygon and multipolygon function.
I have tried to convert the multipolygon to a polygon (and subsequently converting sfc_poylgon to sf) but the data does not appear in the leaflet map.
Can someone help me
library(osmdata)
library(leaflet)
library(sf)
x <-opq(bbox=c(-3.845215,51.041394,4.658203,58.642653),timeout = 25*1000)%>%
add_osm_feature("plant:source","wind") %>%
osmdata_sf()
#convert multipolygons to polygons (picks up Hornsea Zone for example)
x_multip_to_poly<-st_cast(x$osm_multipolygons,"POLYGON")
#convert sfc_polygon to sf
x_mpoly$geometry<-st_as_sf(x_multip_to_poly$geometry)
#Run Polygons
x%>%leaflet()%>%addTiles()%>%addPolygons(data=x$osm_polygons,
popup = paste("Name:",x$osm_polygons$name,"<br/>"))
#Leaflet map with multipolygons
x_mpoly%>%leaflet()%>%addTiles()%>%addPolygons(data=x_mpoly$geometry)