rrgooglemaps

Drawing circles with specific radius size in 'RgoogleMaps' package


I am new to the RgoogleMaps package and I am trying to include circles to my map with an exact radius. Here is my current code:

library(RgoogleMaps)
data <- read.csv("test.csv", header = TRUE, sep = ",", quote = "\"",
                  dec = ".", fill = TRUE, comment.char = "")

lat <- data$Latitude
lon <- data$Longitude

PlotOnStaticMap(lat = lat, lon = lon, zoom = 10, maptype ="satellite",
                size = c(480, 480), cex = 0.2, pch = 19, col = "red", FUN = points, add = F)

Here for each "coordinate point", i.e. for each point on map comes from "data" dataframe with Latitude and Longitude information, I want to draw a 2 mile radius circle with the "coordinate point" as the center. So if I have 10 rows in data frame with Latitude and Longitude information, I want to draw 10 circles with each row as the center and 2 miles radius. Is it possible to do this? Is there a function for this in RgoogleMaps package? If not is there any other package available which I can do this?

I think of using left lower corner and right upper corner latitudes and longitudes ($BBOX$ll and $BBOX$ur) and combining this information with the size of the map $size 480 480, to figure out what should be the cex value for a point with 2 miles. But I will really appreciate an easier method if there is one.

Thank you.

SO


Solution

  • One possibility (as long as the scale is such that a circle in the plot is close enough to a circle on the surface (not distorted much by the projection to a plane)) is to plot the circles using the my.symbols function in the TeachingDemos package. Still use the RgoogleMaps package to download and plot the map, then figure out how far 2/10 miles is in terms of latitude or longitude for the region of the map. Then you can use my.symbols with either the xsize or ysize argument set to the appropriate longitude or latitude (you can use the ms.polygon function with a large number of sides to approximate a circle).