Dear all,
My question is how to create a circular spatial polygon, with 8 arcs of 45 degrees, and radius measuring 15m. Having in the centre point the UTM coordinates, zone 20S. x= *673593.21* *y= **9365367.08* *Thanks* -- Kátia Emídio da Silva DSc Eng. Florestal Manaus/AM Forestry Engineer Manaus/AM-Brazil [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
On 13/09/17 08:48, Kátia Emidio wrote: > Dear all, > My question is how to create a circular spatial polygon, with 8 arcs of 45 > degrees, and radius measuring 15m. Having in the centre point the UTM > coordinates, zone 20S. > > x= *673593.21* > y= *673593.21* "Circular polygon" is a contradiction in terms. If a shape is a polygon then it is *not* a circle. (Of course in real life we use polygons with large numbers of sides to *approximate* circles. But 8 is not large!) You can create an octagon with the required centre and radius using *spatstat* via: oct <- disc(radius=15,centre=c(673593.21,673593.21),npoly=8) Does that provide (at least a start on) what you want? cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
This is also possible with rgeos
library(sp) library(rgeos) x <- 673593.21 y <- 673593.21 sp0 <- SpatialPoints(coords = data.frame(x=x, y=y), proj4string = CRS('+proj=utm +zone=20 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs')) sp1 <- gBuffer(sp0, byid=TRUE, width = 15, quadsegs = 2) plot(sp1) Cheers, Loïc On 12/09/2017 16:57, Rolf Turner wrote: > > On 13/09/17 08:48, Kátia Emidio wrote: > >> Dear all, >> My question is how to create a circular spatial polygon, with 8 arcs >> of 45 >> degrees, and radius measuring 15m. Having in the centre point the UTM >> coordinates, zone 20S. >> >> x= *673593.21* >> y= *673593.21* > > "Circular polygon" is a contradiction in terms. If a shape is a polygon > then it is *not* a circle. (Of course in real life we use polygons with > large numbers of sides to *approximate* circles. But 8 is not large!) > > You can create an octagon with the required centre and radius using > *spatstat* via: > > oct <- disc(radius=15,centre=c(673593.21,673593.21),npoly=8) > > Does that provide (at least a start on) what you want? > > cheers, > > Rolf Turner > _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
Your question is still a tiny bit imprecisely defined, since you haven't
said how you want this polygon to align to the axes. This function computes the coordinates of an N-sided regular polygon centred at (x,y) of radius r, of n sides, at angle theta: ngon = function(x,y,r,n,theta){ phi = seq(theta, theta+2*pi, length=n+1) xc = x + r * sin(phi) yc = y + r * cos(phi) cbind(xc,yc) } Two possible solutions to your question are therefore: plot(ngon(673593.21, 9365367.08, 15, 8, 0), asp=1) plot(ngon(673593.21, 9365367.08, 15, 8, pi/8), asp=1) although that only shows points, building some sort of spatial polygon follows easily enough. Creating points on a circle using trigonometry (sines and cosines) should be in any introductory trigonometry book. B On Wed, Sep 13, 2017 at 2:30 AM, Loïc Dutrieux <[hidden email] > wrote: > This is also possible with rgeos > > library(sp) > library(rgeos) > > x <- 673593.21 > y <- 673593.21 > > sp0 <- SpatialPoints(coords = data.frame(x=x, y=y), > proj4string = CRS('+proj=utm +zone=20 +south > +ellps=WGS84 +datum=WGS84 +units=m +no_defs')) > sp1 <- gBuffer(sp0, byid=TRUE, width = 15, quadsegs = 2) > plot(sp1) > > > Cheers, > Loïc > > On 12/09/2017 16:57, Rolf Turner wrote: > > > > On 13/09/17 08:48, Kátia Emidio wrote: > > > >> Dear all, > >> My question is how to create a circular spatial polygon, with 8 arcs > >> of 45 > >> degrees, and radius measuring 15m. Having in the centre point the UTM > >> coordinates, zone 20S. > >> > >> x= *673593.21* > >> y= *673593.21* > > > > "Circular polygon" is a contradiction in terms. If a shape is a polygon > > then it is *not* a circle. (Of course in real life we use polygons with > > large numbers of sides to *approximate* circles. But 8 is not large!) > > > > You can create an octagon with the required centre and radius using > > *spatstat* via: > > > > oct <- disc(radius=15,centre=c(673593.21,673593.21),npoly=8) > > > > Does that provide (at least a start on) what you want? > > > > cheers, > > > > Rolf Turner > > > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
In reply to this post by Rolf Turner
Whoops. I cc-ed my message to r-help rather than to r-sig-geo. (Duhhhh!) Consequently I'm resending, with r-sig-geo as a cc recipient. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 On 13/09/17 19:37, Rolf Turner wrote: > On 13/09/17 13:24, Kátia Emidio wrote: >> Dear Rolf, >> >> Thanks for your help! >> >> What I need is a spatial window with shape equal to the figure >> attached. This figure I made using ArcGis, but it is important to me >> make it in R. After having this figure I will make some analysis using >> spatstat among others. The points within figure are trees... > > (1) I believe that this discussion should be kept on-list. It is not my > role to provide private consulting for you. I am therefore cc-ing the > list in this email. > > (2) It is still not completely clear what you really want; the figure > that you attached appears to be a disc with 4 diameters superimposed. So > you might be after a single (circular) owin object and a line segment > pattern consisting of the 4 diameters. Or you might be after *eight* > owin objects, each being one the eight disc-segments into which the > diameters divide the disc. > > I shall assume the latter. To start with define a function, say "wedge": > > wedge <- function(theta1,theta2,radius,npoly=100,centre=c(0,0)){ > library(spatstat) > # Should do some checking on the values of theta1 and theta2 here, > # but I shan't bother. > theta <- seq(theta1,theta2,length=npoly+1) > x <- c(0,radius*cos(theta),0) > y <- c(0,radius*sin(theta),0) > W <- owin(poly=list(x=x,y=y)) > return(affine(W,vec=centre)) > } > > Then do something like: > > wedgies <- vector("list",length=8) > cntr <- c(673593.21,673593.21) > for(i in 1:8) wedgies[[i]] <- wedge((i-1)*pi/4,i*pi/4,15,centre=cntr) > ttt <- tess(tiles=wedgies) > plot(ttt) # Looks OK to me. > > And maybe also do: > > W <- do.call(union.owin,wedgies) > plot(W) > for(i in 1:8) { > plot(wedgies[[i]],add=TRUE,border="red") > readline("Go? ") > } > > Also looks OK to me. > > Is *this* what you want? _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
Dear Rolf,
Thanks so much for your help! The script worked well, as I wanted. Only thing that is need to correct, in order to have it in a projected world (in my case UTM-zone 20S), is to change one of the values associated to object "cntr"... the coordinates are the same in the above code.... changing to X/Y UTM coordinates, everthing worked well! Thanks!! Katia 2017-09-13 3:47 GMT-04:00 Rolf Turner <[hidden email]>: > > Whoops. I cc-ed my message to r-help rather than to r-sig-geo. (Duhhhh!) > > Consequently I'm resending, with r-sig-geo as a cc recipient. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > On 13/09/17 19:37, Rolf Turner wrote: > >> On 13/09/17 13:24, Kátia Emidio wrote: >> >>> Dear Rolf, >>> >>> Thanks for your help! >>> >>> What I need is a spatial window with shape equal to the figure attached. >>> This figure I made using ArcGis, but it is important to me make it in R. >>> After having this figure I will make some analysis using spatstat among >>> others. The points within figure are trees... >>> >> >> (1) I believe that this discussion should be kept on-list. It is not my >> role to provide private consulting for you. I am therefore cc-ing the >> list in this email. >> >> (2) It is still not completely clear what you really want; the figure >> that you attached appears to be a disc with 4 diameters superimposed. So >> you might be after a single (circular) owin object and a line segment >> pattern consisting of the 4 diameters. Or you might be after *eight* owin >> objects, each being one the eight disc-segments into which the diameters >> divide the disc. >> >> I shall assume the latter. To start with define a function, say "wedge": >> >> wedge <- function(theta1,theta2,radius,npoly=100,centre=c(0,0)){ >> library(spatstat) >> # Should do some checking on the values of theta1 and theta2 here, >> # but I shan't bother. >> theta <- seq(theta1,theta2,length=npoly+1) >> x <- c(0,radius*cos(theta),0) >> y <- c(0,radius*sin(theta),0) >> W <- owin(poly=list(x=x,y=y)) >> return(affine(W,vec=centre)) >> } >> >> Then do something like: >> >> wedgies <- vector("list",length=8) >> cntr <- c(673593.21,673593.21) >> for(i in 1:8) wedgies[[i]] <- wedge((i-1)*pi/4,i*pi/4,15,centre=cntr) >> ttt <- tess(tiles=wedgies) >> plot(ttt) # Looks OK to me. >> >> And maybe also do: >> >> W <- do.call(union.owin,wedgies) >> plot(W) >> for(i in 1:8) { >> plot(wedgies[[i]],add=TRUE,border="red") >> readline("Go? ") >> } >> >> Also looks OK to me. >> >> Is *this* what you want? >> > -- Kátia Emídio da Silva DSc Eng. Florestal Manaus/AM Forestry Engineer Manaus/AM-Brazil [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo |
Free forum by Nabble | Edit this page |