Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 绘制跑道的内部水平面_R_Leaflet_Sf - Fatal编程技术网

R 绘制跑道的内部水平面

R 绘制跑道的内部水平面,r,leaflet,sf,R,Leaflet,Sf,我之前发布了一个合并圆圈的问题。在社区的帮助下,这个问题得到了解决。但是,现在当我尝试将多边形与现有几何体组合时,我看不到期望的结果。这就是我尝试过的: 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((

我之前发布了一个合并圆圈的问题。在社区的帮助下,这个问题得到了解决。但是,现在当我尝试将多边形与现有几何体组合时,我看不到期望的结果。这就是我尝试过的:

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()
图书馆(传单)
图书馆(sf)
图书馆(rgeos)
图书馆(地球圈)
#跑道1的尺寸

ptTop1如果您想将跑道从圆圈中排除,那么
st_sym_difference(sf_combined1,rect1)
应该能满足您的需要。@TimSalabim谢谢。但我恐怕那不是我想要的。我想把跑道周围画的一个矩形(
rect1
)与前面画的两个圆圈结合起来。
sf\u combined 2我刚刚意识到我的矩形的边界包含在圆圈内,因此我看不到它们重叠!我的错。如果你想把跑道排除在圆圈之外,那么
st_sym_difference(sf_combined1,rect1)
应该会给你想要的。@TimSalabim谢谢。但我恐怕那不是我想要的。我想把跑道周围画的一个矩形(
rect1
)与前面画的两个圆圈结合起来。
sf\u combined 2我刚刚意识到我的矩形的边界包含在圆圈内,因此我看不到它们重叠!我的错。