# polygon vertex to vertex distance calculation in arcobjects

I have polygon with multipart (donuts) I want to calculate vertex to vertex distance. I tried to get outer ring vertex to vertex distance and it is working. Could you please tell me how to get inner ring vertex to outer ring vertex distance?

``````IPolygon polygon = buld_F.Shape as IPolygon;
IPointCollection ppcol = polygon as IPointCollection;
for (int j = 0; j < ppcol.PointCount -1; j++)
{
IPoint pp = ppcol.get_Point(j);
IPoint pp2 = ppcol.get_Point(j + 1);
double xvalue2 = pp2.X;
double yvalue2 = pp2.Y;
double xvalue1 = pp.X;
double yvalue1 = pp.Y;
double dist = Math.Sqrt(Math.Pow(xvalue2 - xvalue1, 2) + Math.Pow(yvalue2 - yvalue1, 2));
double ptop_dist = dist * 100;
if (ptop_dist <= 20)
{
dt.Rows.Add(buld_F.OID, buld_F.Class.AliasName, tgid_val, xvalue2, yvalue2, "Vertex to Vertex distance < 20CM");
}
}
`````` Thank's guys,

I have solved my problem.

``````IPolygon4 polygon = buld_F.Shape as IPolygon4;
IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag;
IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;
for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
{
IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
IPointCollection exteriorRingPointCollection = exteriorRingGeometry as IPointCollection;
for (int j = 0; j < exteriorRingPointCollection.PointCount - 1; j++)
{
IPoint pp = exteriorRingPointCollection.get_Point(j);
IPoint pp2 = exteriorRingPointCollection.get_Point(j + 1);
double xvalue2 = pp2.X;
double yvalue2 = pp2.Y;
double xvalue1 = pp.X;
double yvalue1 = pp.Y;
double dist = Math.Sqrt(Math.Pow(xvalue2 - xvalue1, 2) + Math.Pow(yvalue2 - yvalue1, 2));
double ptop_dist = dist * 100;
if (ptop_dist <= 20)
{
dt.Rows.Add(buld_F.OID, buld_F.Class.AliasName, tgid_val, xvalue2, yvalue2, "Vertex to Vertex distance < 20CM");
}
}
IGeometryBag interiorRingGeometryBag = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;
for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
{
interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
IPointCollection interiorRingPointCollection = interiorRingPointCollection = interiorRingGeometry as IPointCollection;
for (int m = 0; m < interiorRingPointCollection.PointCount - 1; m++)
{
IPoint pp = interiorRingPointCollection.get_Point(m);
IPoint pp2 = interiorRingPointCollection.get_Point(m + 1);
double xvalue2 = pp2.X;
double yvalue2 = pp2.Y;
double xvalue1 = pp.X;
double yvalue1 = pp.Y;
double dist = Math.Sqrt(Math.Pow(xvalue2 - xvalue1, 2) + Math.Pow(yvalue2 - yvalue1, 2));
double ptop_dist = dist * 100;
if (ptop_dist <= 20)
{
dt.Rows.Add(buld_F.OID, buld_F.Class.AliasName, tgid_val, xvalue2, yvalue2, "Vertex to Vertex distance < 20CM");
}
}
}
``````