BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8


I'm trying to find the area for an irregular polygon. My dataset consists of many points but the example below contains just 8 coordinates.

Is there a good algorithm available for doing this? Ideally generalizing it so that it can apply to potentially 100s of points.

data coord;

input x 1. y 1.;

datalines;

14

31

53

87

79

58

47

25

run;

2 REPLIES 2
Rick_SAS
SAS Super FREQ

These computational geometry questions might be better to ask in the SAS Support Community for Graphics, which includes experts in mapping and GIS. Goto https://communities.sas.com/community/support-communities/sas_graph_and_ods_graphics They might know of a built-in function or macro.

These computations are possible to do in the DATA step, but they are much easier in a vector language like SAS/IML.

A simple internet search will reveal many web pages that discuss formulas for the area of a general polygon. For example, see Area of Triangles and Polygons. The following SAS/IML function implements the second summation formula after the paragraph that begins "One can make the formula more explicit by..."

proc iml;
start AreaPolygon(_x, _y);
   /* close polygon by appending first point to end */
   y = _y // _y[1];
   x = _x // _x[1];
   n = nrow(x);
   xx = x[ 1:(n-1) ] + x[ 2:n ];
   yy = y[ 2:n ] - y[ 1:(n-1) ];
   A = 0.5 * sum(xx # yy); /* is negative for clockwise polys */
   return( abs(A) );
finish;

use coord; read all var {x y}; close;
A = AreaPolygon(x,y);
print A;

JacobSimonsen
Barite | Level 11

Or try this

data elipse;

  pi=4*atan(1);

  do i=0 to 256 ;

    x=cos(i*2*pi/256);

    y=2*sin(i*2*pi/256);

output;

  end;

run;

data _NULL_;

  set elipse end=eof;

  retain area lastx lasty;

  if _N_=1 then area=0;

  else do;

    area+((lastx-x)*(y+lasty)/2);

  end;

  lastx=x;lasty=y;

  if eof then put area=;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1581 views
  • 0 likes
  • 3 in conversation