【发布时间】:2021-05-31 23:48:09
【问题描述】:
我正在使用包 osmdata 来了解巴黎街道和地理的概况。我弄清楚了与街道有关的一切,但现在我面临一个新问题:河流(以及一般的水)。
我想从巴黎地图中提取河流(我的意思是多边形,而不仅仅是河流线)。我需要去河岸。我观察到,河流的某些部分保存为多边形,而某些部分保存为线。
这是一个代表:
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)
正如您在图像上看到的,我有绿色和蓝色的多边形,但河流的主要部分仅由一条线(红色)定义。有没有办法得到所有的河岸,这样我就可以从巴黎的土地上提取它们?
我在里斯本做过,但这里的主要部分是由多边形定义的(我把它称为“海岸”)。这让您对我正在尝试做的事情有一个很好的了解,但与巴黎河有关。
【问题讨论】:
标签: r ggplot2 polygon openstreetmap