[R-sig-Geo] shape of circles
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Fri Feb 22 13:20:18 CET 2008
Agustin Lobo wrote:
> Hi!
>
> I have to create a shp of "circular" polygons
> out of a file with x,y coordinates and radii.
>
> I've found that disc() from package GRID makes
> an owin object for each circle, but then how can
> I convert to sp (from there to shp using writeOGR)?
To generate n points on a circle centred at (x,y) of radius r you can do:
circle =
function(x,y,r,n=100){t=seq(0,2*pi,len=n+1)[-1];return(cbind(r*sin(t),r*cos(t)))}
Increasing the n parameter makes the circle smoother. n=4 gives a
square! Note this function doesn't generate duplicate points at start
and finish.
From here to sp should be trivial...
Barry
More information about the R-sig-Geo
mailing list