gpt4 book ai didi

r - ggmap 创建的图上纬度/经度点周围的圆半径

转载 作者:行者123 更新时间:2023-12-04 16:48:20 26 4
gpt4 key购买 nike

我想知道是否有人使用 ggmap 围绕纬度/经度点绘制圆半径?例如,我想绘制一个给定的点,然后在该点周围 2,500 英尺的半径范围内绘制和着色。我脑子里有一个关于如何使用更大的圆周公式来做到这一点的想法,但我想我会先在这里检查一下。

最佳答案

我致力于构建一个简单的 hack,虽然不是我想象的圈子,但它现在可以用。

library(ggmap)
##__________________________________________________________________
### earth.dist I found on r-bloggers. I believe it now belongs to the fossil package.
earth.dist <- function ( lat1,long1,lat2, long2)
{
rad <- pi/180
a1 <- lat1 * rad
a2 <- long1 * rad
b1 <- lat2 * rad
b2 <- long2 * rad
dlon <- b2 - a2
dlat <- b1 - a1
a <- (sin(dlat/2))^2 + cos(a1) * cos(b1) * (sin(dlon/2))^2
c <- 2 * atan2(sqrt(a), sqrt(1 - a))
R <- 6378.145
d <- R * c
# this I changed to return feet instead of KM
return(d* 3280.8)
}

##__________________________________________________________________
## Function to output polygon to map
BoxGon <- function(Lat,Long,feet){

for(i in 1:1000){
point = Long - i/1000
Dist <- earth.dist(Lat,Long, Lat,point)
if(Dist > feet){
West <- cbind(Lat,point)
break}
}

for(i in 1:1000){
point = Long + i/1000
Dist <- earth.dist(Lat,Long, Lat,point)
if(Dist > feet){
East <- cbind(Lat,point)
break}
}

for(i in 1:1000){
point = Lat + i/1000
Dist <- earth.dist(Lat,Long, point,Long)
if(Dist > feet){
North <- cbind(point,Long)
break}
}

for(i in 1:1000){
point = Lat - i/1000
Dist <- earth.dist(Lat,Long, point,Long)
if(Dist > feet){
South <- cbind(point,Long)
break}
}

return(rbind(West,North,East,South,West))
}

##__________________________________________________________________
df = BoxGon(37.295844, -121.898057,5000)
df = as.data.frame(df)
colnames(df) <- c('Latitude','Longitude')

map <- get_map(location = 'san,jose', zoom = 12)
map <- ggmap(map)

# we select - 1 because once we map in pairs. IE once we have the last record there is nothing for that record to map to
for(i in 1:nrow(df)-1){
latlon <- head(df,2)
map <- map + geom_polygon(data=latlon,aes(x=Longitude,y=Latitude),alpha=0.1,size = 1,colour="green",fill="green")
df = df[-1,]
print(i)
}
map <- map + geom_polygon(aes(x=-121.898057,y=37.295844),alpha=0.1,size = 6,colour='Purple',fill='Purple')

关于r - ggmap 创建的图上纬度/经度点周围的圆半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34077657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com