Measure the angle of each corner of a polygon

How can I automatically measure the angle for each corner of a polygon (in a vector GIS) using VBA and ArcObjets?

• Note: With the corner I mean the point that joins two vertices of a polygon. – Demetris Jun 2 '11 at 5:03
• Did you try IConstructAngle? – Kirk Kuykendall Jun 2 '11 at 14:49
• Thanks for that. It needs some more thinking how to do it with a polygon. – Demetris Jun 2 '11 at 18:08
• Just use maths Demetris; you need to find the gradient of the first line, then compare it to the second, etc; you don't even need the GIS, you just need to look at algorithms to find gradients of lines. It is so very easy – Hairy Jun 3 '11 at 7:04

As Kirk said, you can use IConstructAngle to do that.

Cast your geometry to IPointCollection and iterate over it (I did not tested this - and this should work only for simple polygons, without holes)

public class VertexAngleMeasure
{
int _vertexId;
double _angle;

public int VertexId
{
get { return _vertexId; }
set { _vertexId = value; }
}

public double Angle
{
get { return _angle; }
set { _angle = value; }
}

public VertexAngleMeasure()
{ }

public VertexAngleMeasure(int id, double angle)
{
_vertexId = id;
_angle = angle;
}
}

public class PolygonAngleMeasure
{
IPolygon _polygon;
List<VertexAngleMeasure> _measures;

{
double degrees = radians * (180 / System.Math.PI);

return degrees == 360 ? 0 : degrees;
}

public PolygonAngleMeasure(IPolygon poly)
{
_polygon = poly;
}

public void CalculateMeasures()
{
IGeometryEnvironment4 environment = new GeometryEnvironmentClass();
IConstructAngle constructAngle = environment as IConstructAngle;

IPointCollection pointCollection = _polygon as IPointCollection;

double angle = 0;

_measures.Clear();

for (int i = 0; i <= pointCollection.PointCount - 1; i++)
{
if (i != 0 && i != pointCollection.PointCount - 1)
{
angle = constructAngle.ConstructThreePoint(
pointCollection.get_Point(i - 1),
pointCollection.get_Point(i),
pointCollection.get_Point(i + 1));
}

if (i == 0)
{
angle = constructAngle.ConstructThreePoint(
pointCollection.get_Point(pointCollection.PointCount - 1),
pointCollection.get_Point(0),
pointCollection.get_Point(1));
}

if (i == pointCollection.PointCount - 1)
{
angle = constructAngle.ConstructThreePoint(
pointCollection.get_Point(i - 1),
pointCollection.get_Point(i),
pointCollection.get_Point(0));
}