我之前发布了一个问题,就是结合圈子here。在社区的帮助下,这个问题得到了解决。但是,现在当我尝试将多边形与现有几何图形组合时,我看不到所需的结果。这就是我的尝试:
library(leaflet)
library(sf)
library(rgeos)
library(geosphere)
#Dimensions of runway1
ptTop1 <- c((72 +(50/60)+(8.64/3600)),(20+(26/60)+(8.08/3600)))
ptBottom1 <- c((72 +(50/60)+(44.21/3600)),(20+(26/60)+(5.63/3600)))
ap1 <- 95 #Approach
#########################################
#Inner Horizontal Surface
#Convert into a dataframe
df1 <- data.frame(lon=c(ptTop1[1],ptBottom1[1]),
lat=c(ptTop1[2],ptBottom1[2]))
#Convert into a simple features data.frmae
sf_df1 <- st_as_sf(df1, coords = c("lon","lat"))
#Convert into circles
sf_circles1 <- st_buffer(sf_df1,dist=0.04)
#Coordinates of the rectangle
pt1 <- destPoint(ptTop1,ap1+90,4000)
pt2 <- destPoint(ptTop1,ap1-90,4000)
pt3 <- destPoint(ptBottom1,ap1-90,4000)
pt4 <- destPoint(ptBottom1,ap1+90,4000)
#Convert into a dataframe
iRect1 <- data.frame(lon=c(pt1[1],pt2[1],pt3[1],pt4[1]),
lat=c(pt1[2],pt2[2],pt3[2],pt4[2]))
#Convert into a simple features df
sf_iRect1 <- st_as_sf(iRect1,coords = c("lon","lat"))
rect1 <- st_sfc(st_polygon(list(cbind(lon=c(pt1[1],pt2[1],pt3[1],pt4[1],pt1[1]),
lat=c(pt1[2],pt2[2],pt3[2],pt4[2],pt1[2])))))
#Combine the 3 shapes
sf_combined1 <- st_union(sf_circles1)
sf_combined2 <- st_union(sf_combined1,rect1,by_feature = F)
#Plot in leaflet
sp <- as(sf_combined2,'Spatial')#as(st_sfc(sf_combined1), "Spatial")
sp%>%leaflet()%>%addTiles()%>%
addProviderTiles(providers$Esri.WorldImagery, group ="ESRI")%>%
addPolygons()
有人可以告诉我我做错了什么吗?