在地图中绘制具有定义距离半径的圆 [英] Drawing a Circle with a Radius of a Defined Distance in a Map

查看:409
本文介绍了在地图中绘制具有定义距离半径的圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以绘制地图和标题的一个特定点:

 图书馆(地图)
地图( state)
text(-80.83,35.19,Charlotte,cex = .6)



我也可以画出一个以此为中心的圆圈:

 符号(-80.83,35.19,circles = 2,add = TRUE)

但是,我想控制圆的大小。特别是,我想在data.frame,matrix或list中包含的多个位置周围绘制一个半径为100英里的圆。

解决方案 div>

你可以编写一个函数来定制你希望圆的外观。例如:

  plotCircle < -  function(x,y,r){
angles< - seq 0,2 * pi,length.out = 360)
lines(r * cos(angles)+ x,r * sin(angles)+ y)
}


 >  coords<  -  data.frame(x = c(-1,0,1),y = c(-1,0.5,1))



您可以从一些初始情节开始(地图或空情节等)

  plot(1,type ='n',xlim = c(-2,2),ylim = c(-2,2))

然后在坐标列表中调用绘图函数:

  apply(coords,1,function(df)plotCircle(df [1],df [2],。3))


I am able to plot a map and caption a specific point:

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

I can also plot a circle centered around that point:

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

However, I would like to control the size of the circle. In particular, I want to draw a circle with a radius of 100 mile around multiple locations contained in a data.frame, matrix, or list.

解决方案

You can write a function to customize how you want the circle to look. For example:

plotCircle <- function(x, y, r) {
  angles <- seq(0,2*pi,length.out=360)
  lines(r*cos(angles)+x,r*sin(angles)+y)
}

Then if you had a set of coordinates in a data frame:

coords <- data.frame(x = c(-1,0,1), y = c(-1, 0.5, 1))

You can start with some initial plot (map, or empty plot, etc)

plot(1,type='n',xlim=c(-2,2),ylim=c(-2,2))

Then call the plotting function over your list of coordinates:

apply(coords,1,function(df) plotCircle(df[1],df[2],.3))

这篇关于在地图中绘制具有定义距离半径的圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆