r - 在 map 中绘制半径为定义距离的圆

标签 r geometry maps geographic-distance

我能够绘制 map 并为特定点添加标题:

library(maps)
map("state")
text(-80.83,35.19,"Charlotte",cex=.6)

我还可以绘制一个以该点为中心的圆:

symbols(-80.83,35.19,circles=2, add=TRUE)

但是,我想控制圆的大小。特别是,我想围绕数据框、矩阵或列表中包含的多个位置绘制一个半径为 100 英里的圆。

最佳答案

Gary 的命题很适用于平面 map ,但不能应用于“ map ”包生成的 map ,因为它没有考虑用于绘制 map 的投影。严格如此应用,它会导致绘制一个椭圆(见下文),因为圆半径的单位是度,而不是千米或英里。但是纬度和经度的度数并不对应于相同的物理距离。要在一个点周围画一个圆或接近圆的东西,其半径是以英里或公里为单位的恒定距离,您需要计算关于投影的校正坐标。根据 Chris Veness 在 http://www.movable-type.co.uk 上的解释采用您的函数并对其进行调整,你的功能变成了:

library(maps)
library(mapdata)#For the worldHires database
library(mapproj)#For the mapproject function
plotElipse <- function(x, y, r) {#Gary's function ;-)
   angles <- seq(0,2*pi,length.out=360)
   lines(r*cos(angles)+x,r*sin(angles)+y)
}
plotCircle <- function(LonDec, LatDec, Km) {#Corrected function
    #LatDec = latitude in decimal degrees of the center of the circle
    #LonDec = longitude in decimal degrees
    #Km = radius of the circle in kilometers
    ER <- 6371 #Mean Earth radius in kilometers. Change this to 3959 and you will have your function working in miles.
    AngDeg <- seq(1:360) #angles in degrees 
    Lat1Rad <- LatDec*(pi/180)#Latitude of the center of the circle in radians
    Lon1Rad <- LonDec*(pi/180)#Longitude of the center of the circle in radians
    AngRad <- AngDeg*(pi/180)#angles in radians
    Lat2Rad <-asin(sin(Lat1Rad)*cos(Km/ER)+cos(Lat1Rad)*sin(Km/ER)*cos(AngRad)) #Latitude of each point of the circle rearding to angle in radians
    Lon2Rad <- Lon1Rad+atan2(sin(AngRad)*sin(Km/ER)*cos(Lat1Rad),cos(Km/ER)-sin(Lat1Rad)*sin(Lat2Rad))#Longitude of each point of the circle rearding to angle in radians
    Lat2Deg <- Lat2Rad*(180/pi)#Latitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
    Lon2Deg <- Lon2Rad*(180/pi)#Longitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
    polygon(Lon2Deg,Lat2Deg,lty=2)
}
map("worldHires", region="belgium")#draw a map of Belgium (yes i am Belgian ;-)
bruxelles <- mapproject(4.330,50.830)#coordinates of Bruxelles
points(bruxelles,pch=20,col='blue',cex=2)#draw a blue dot for Bruxelles
plotCircle(4.330,50.830,50)#Plot a dashed circle of 50 km arround Bruxelles 
plotElipse(4.330,50.830,0.5)#Tries to plot a plain circle of 50 km arround Bruxelles, but drawn an ellipse

Result in image

(抱歉,我的“声誉”不允许我发布图片 ;-)。编辑:添加了您的图片。

希望对您有所帮助。 格雷瓜尔

关于r - 在 map 中绘制半径为定义距离的圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23071026/

相关文章:

java - 确定多边形是否在 map 边界内

java - 需要缩放/平移点数组,因此路径将匹配给定的终点

java - 如何在谷歌地图android中添加hashmap?

iOS - 使用方向 URL 方案启动 Yandex map

r - 亚马逊 EMR : Using R code in Amazon EMR

r - 使用knitr生成复杂的动态文档

从 Corr 矩阵返回最大相关性和行名称

r - 基于一列向量的 data.table 到 long 重复另一列

javascript - 在 three.js 中合并几何

javascript - 如何更新 Leaflet 弹出窗口中的内容?