Skip to content

how to draw a new circle/round polygon on existing plot

2 messages · Wouter Steenbeek, Edzer Pebesma

#
I have a plot with several layers of SpatialPoints and Polygons. They are all projected and in the correct CRS, so my map looks like it should. I now want to draw a circle with a radius x on a part of this map. This should not just be a circle, but be in the correct projection (so that I can change radius x to whatever I desire, and the circle is drawn correctly on scale, and slightly "distorted" dependent on my zoom of the map).

How do I do this? Thanks!

(I understand that I should define a new polygon and "plot(..., add=T)" that to my map. But how do I make such a polygon? I don't quite understand the "polygon" function in the 'graphics' package, if that's even the correct one to use. Seeing an example would help.)
#
x = 10 # center x
y = 10 # center y
n = 100 # nr of pts
r = 5 # radius
pts = seq(0, 2 * pi, length.out = n)
plot(sin(pts), cos(pts), type = 'l', asp = 1) # test
require(sp)
xy = cbind(x + r * sin(pts), y + r * cos(pts))
sl= SpatialLines(list(Lines(list(Line(xy)), "line")))
plot(sl, add=FALSE, col = 'red', axes=T )

this draws a circle as a line; if you want a filled polygon, I'd replace
every instance of Line with Polygon (but mind the s).
On 11/06/2012 09:30 PM, Wouter Steenbeek wrote: