Closed richardbeare closed 6 years ago
Thanks a load for the inspiration here @richardbeare! This hefty commit implements new ~lines2poly
~ osm_line2poly
function. The example is directly inspired by your question. Check it:
bb <- osmdata::getbb ("melbourne, australia")
coast <- opq (bb) %>%
add_osm_feature (key = "natural", value = "coastline") %>%
osmdata_sf ()
coast <- osm_line2poly (coast$osm_lines, bbox = bb)
map <- osm_basemap (bbox = bb) %>%
add_osm_objects (coast [[1]], col = "lightsteelblue") %>%
print_osm_map ()
Give it a spin and let me know what you think!
line2poly()
~ osm_line2poly()
always returns two polygons. For coastline, one will be land, the other water, but there are likely other use cases where distinction won't be so clear, so no attempts are made to distinguish them.bbox
before coming back in and then finally extending beyond again. I think these cases will likely work smoothly, but am not sure.sf
data.frame
with the two polygons instead of a list.~ This ain't easy to do because it needs to have a default [,] -> [,drop=FALSE]
operator to work properly. Standard solution would be to re-define/overload the [[.sf
operator](https://github.com/r-spatial/sf/blob/master/R/sf.R), but that's silly and dangerous so it's probably better to leave it as a list.Hi, This is close, but didn't work for my case. I'm working on modifications now.
Okay, let me know and we'll see what else can be added...
Hi, I'm wondering about the best way to display ocean. I'm aware of the coastline tag for key "natural". However this returns a mix of polygons and lines and it is not obvious how to fill the appropriate category.
Thanks