[R-sig-Geo] how to draw a new circle/round polygon on existing plot

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Nov 6 23:42:46 CET 2012


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:
> 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.)
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list