在具有半径的地图上绘图

时间:2016-08-03 13:56:15

标签: r plot maps data-visualization

我试图在R的美国地图上绘制几个长点和纬度点。每个点都有一个特定的半径,我也试图想象。它们存储在标题long,lat和rad下的表格中。我还想确定具有拦截国界的半径的点。

我在地图上有点,但似乎无法获得多个点的半径,并返回具有拦截边界的半径的点。 enter image description here

library("maps")
library("mapproj")
library("mapdata")
data("stateMapEnv")

dat <- read.csv("R/longlat.csv",header = T)

map('state',fill = T, col = "white")

points(dat$lng,dat$lat,col = "red", cex = 0.6, pch = 20)

plotCircle <- function(lonDec, latDec, mile) {
  ER <- 3959
  angdeg <- seq(1:360)
  lat1rad <- latDec*(pi/180)
  lon1rad <- lonDec*(pi/180)
  angrad <- angdeg*(pi/180)
  lat2rad <- asin(sin(lat1rad)*cos(mile/ER) + cos(lat1rad)*sin(mile/ER)*cos(angrad))
  lon2rad <- lon1rad + atan2(sin(angrad)*sin(mile/ER)*cos(lat1rad),cos(mile/ER)-sin(lat1rad)*sin(lat2rad))
  lat2deg <- lat2rad*(180/pi)
  lon2deg <- lon2rad*(180/pi)
  polygon(lon2deg,lat2deg,lty = 2 , col = alpha("blue",0.35))
  }

agents <- mapproject(dat$lng,dat$lat)
points(agents, col = "red", cex = 0.4, pch = 20)

plotCircle(dat$lng,dat$lat,dat$rad)

1 个答案:

答案 0 :(得分:0)

相关问题