问题描述
我正在使用 osmdata 包来大致了解巴黎的街道和地理。我想出了与街道有关的一切,但现在我面临一个新问题:河流(以及一般的水)。
我想从巴黎地图中提取河流(我指的是多边形,而不仅仅是河流线)。我需要得到河岸。我观察到,河流的某些部分保存为多边形,有些部分保存为线。
这是一个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[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,fill = "blue",color = "blue") +
geom_sf(data=river$osm_multilines,fill = "red",color = "red") +
coord_sf(xlim = c(min(p_big[,1]),max(p_big[,1])),ylim = c(min(p_big[,2]),2])),expand = FALSE)
正如您在图像中看到的,我有绿色和蓝色的多边形,但河流的主要部分仅由一条线(红色)定义。有没有办法得到所有的河岸,这样我就可以从巴黎的土地上提取那些?
我在里斯本做过,但这里的主要部分是由多边形定义的(我把它称为“海岸”)。这让你对我正在尝试做的事情有一个很好的了解,但是巴黎河。