[R-sig-Geo] Create points to polygons

Takatsugu Kobayashi tkobayas at indiana.edu
Mon Dec 31 09:04:17 CET 2007


Hi R users,

I have been wandering around several manuals (sp, maptools, and
PBSmapping) to find out how to create polygons from points. Basically,
what I would like to do is to compute the area where two ellipses
overlap. 

I can easily create the coordinates (x,y) of an ellipse. 

library(CircStats)
library(sp)
library(PBSmapping)

  # Draw a standard deviational ellipse
  ElpCoords<-function(sigma_x,sigma_y,angle)
   {
    theta<-seq(0,2*pi,length=2000)
    x<-cos(theta)
    y<-sin(theta)
    x1<-x*sigma_x
    y1<-y*sigma_y
    new_x<-x1*cos(rad(angle))-y1*sin(rad(angle))
    new_y<-x1*sin(rad(angle))+y1*cos(rad(angle))
    coords=cbind(new_x,new_y)  
   }

Using the function above, I created two ellipses;

  el1<-ElpCoords(3,1.5,45)
  el2<-ElpCoords(4,2.2,125)

Now I am stuck. How can I change these points forming ellipses into
polygons? I am believing that once I convert them into polygons I can
compute the overlapped area by using 

  el1Poly<-SpatialPolygons2PolySet(xxx_polygon_of_el1)
  el2Poly<-SpatialPolygons2PolySet(xxx_polygon_of_el2)
  overlappedArea<-joinPolys(el1Poly,eliPoly)
  if(length(overlappedArea)>0)
   {
    combinedArea<-combinePolys(overlappedArea)
    AreaSize<-calcArea(combinedArea)
   }
  else
   {
   warning('No overlapped area found')
   }

So I would like to know processes to get to the last part.....

In addition, I have been wondering if there are tutorial books on
spatial stats/GIS on R. I am basically reading [R], [R-Geo], and R
News...

Thank you very much.

Takatsugu Kobayashi
PhD student
Indiana University Bloomignton




More information about the R-sig-Geo mailing list