Reputation: 166
I am working with package osmdata to get an overview of Paris streets and geography. I figured out everything that is related to the streets, but now I am facing a new problem: Rivers (and water in general).
I would like to extract, from Paris map, the river (I mean the polygons, not only the river line). I need to get the river banks. I am observing that, some parts of the river are saved as polygons, and some parts as lines.
Here is a reprex:
require(osmdata)
require(sf)
library(lwgeom)
require(ggplot2)
coord = c(2.252356,48.784685,2.443243,48.946392)
city = "Paris"
country = "France"
EPSG = 4326
# obtain coordinates for ggplot
bbx <- getbb(paste0(city, ", ", country))
bbx[1,1] = coord[1]
bbx[2,1] = coord[2]
bbx[1,2] = coord[3]
bbx[2,2] = coord[4]
q0 <- opq(bbox = coord)
# Defining a buffer
buffer <- 0
p_big <- rbind(c(bbx[1] - buffer, bbx[2] - buffer),
c(bbx[1] - buffer, bbx[4] + buffer),
c(bbx[3] + buffer, bbx[4] + buffer),
c(bbx[3] + buffer, bbx[2] - buffer),
c(bbx[1] - buffer, bbx[2] - buffer))
# Putting the coordinates into a squared polygon object
pol <- st_polygon(list(p_big)) %>% st_geometry
# Providing the SRID (here, unprojected lon/lat)
st_crs(pol) <- EPSG
# Get water data
water <- opq(bbox = st_bbox(pol)) %>%
add_osm_feature(key = "water") %>%
osmdata_sf()
# I thought this would be enough but when I plot it, it was incomplete
# So I need to get more specific query
# Get river data
river <- opq(bbox = st_bbox(pol)) %>%
add_osm_feature(key = 'waterway', value = "river") %>%
osmdata_sf()
ggplot() +
geom_sf(data=water$osm_polygons, inherit.aes = FALSE, lwd=0, fill = "green", color = "green") +
geom_sf(data=water$osm_multipolygons, inherit.aes = FALSE, lwd=0, fill = "blue", color = "blue") +
geom_sf(data=river$osm_multilines, inherit.aes = FALSE, lwd=0, fill = "red", color = "red") +
coord_sf(xlim = c(min(p_big[,1]), max(p_big[,1])), ylim = c(min(p_big[,2]), max(p_big[,2])), expand = FALSE)
As you can see on the image, I have polygons in green and blue, but a major part of the river is only defined by a line (in red). Is there a way to get all the river banks, so I can extract those from Paris land?
I have do it in Lisbon, but here a major part is defined by polygon (and I get it as "coast"). This gives you a good ideia of what I am trying to do, but with Paris river.
Upvotes: 0
Views: 381
Reputation: 31
I have been trying to do similar with Python and OSMnx and just found that by getting data using each of the following three filters with OSMnx and graph_from_address
then using networkx.compose
it has given me the riverbanks:
filter='["highway"]'
filter='["natural"]'
filter='["water"]'
Example riverbanks for New York]
Upvotes: 1