This document is archived and information here might be outdated. Recommended version. |
Constructs the geometric average of the input point collection. Optionally uses the specified attribute as a source of weights on the locations of the points.
[Visual Basic .NET] Public Sub ConstructAverage ( _ ByVal Points As IPointCollection, _ ByVal attributeType As esriGeometryAttributes _ )
[C#] public void ConstructAverage ( IPointCollection Points, esriGeometryAttributes attributeType );
[C++]
HRESULT ConstructAverage(
IPointCollection* Points,
esriGeometryAttributes attributeType
);
[C++] Parameters Points
Points is a parameter of type IPointCollection* attributeType
attributeType is a parameter of type esriGeometryAttributes
If attributeType is esriAttributeNone then the average point location is computed; otherwise the attribute specified by attributeType serves as a weight. Points whose weight attribute is NaN are ignored (a weight of 0 has a similar affect). The resulting point will have the (weighted) average for all their attributes. However this does not apply to ID's; no average is calculated for them in any case; but thay can be used as weight.
Only the following attributeType values are permitted: esriAttributeNone, esriAttributeZ, esriAttributeM, esriAttributeID.
//This example demonstrates how to use the ConstructAverage method
private void ConstructAverage_Example()
{
IPointCollection4 pointCollection = new MultipointClass();
object Missing = Type.Missing;
//Create a MAware and a ZAware multipoint
IPoint[] points = new IPoint[4];
for(int i = 0; i < 4; i++)
{
points[i]= new PointClass();
}
points[0].PutCoords(0, 0);
points[0].Z = 10;
points[0].M = 10;
points[1].PutCoords(0, 5);
points[1].Z = 10;
points[1].M = 10;
points[2].PutCoords(5, 5);
points[2].Z = 20;
points[2].M = 20;
points[3].PutCoords(5, 0);
points[3].Z = 10;
points[3].M = 20;
IGeometryBridge geomBridge = new GeometryEnvironmentClass();
geomBridge.AddPoints(pointCollection, ref points);
IZAware zAwareCollection = pointCollection as IZAware;
zAwareCollection.ZAware = true;
IMAware mAwareCollection = pointCollection as IMAware;
mAwareCollection.MAware = true;
IConstructPoint2 constructionPoint = new PointClass();
//Construct the average point with esriAttributeM
constructionPoint.ConstructAverage(pointCollection, esriGeometryAttributes.esriAttributeM);
IPoint outPutPoint1 = constructionPoint as IPoint;
System.Windows.Forms.MessageBox.Show("Output point with esriAttributeM: " + outPutPoint1.X + " , " + outPutPoint1.Y + " , " + outPutPoint1.M);
//Construct the average point with esriAttributeZ
constructionPoint.ConstructAverage(pointCollection, esriGeometryAttributes.esriAttributeZ);
IPoint outPutPoint2 = constructionPoint as IPoint;
System.Windows.Forms.MessageBox.Show("Output point with esriAttributeZ: " + outPutPoint2.X + " , " + outPutPoint2.Y + " , " + outPutPoint2.Z);
}
'This example demonstrates how to use the ConstructAverage method
Sub ConstructAverage_Example()
Dim pPoints(0 To 3) As IPoint, pPointcol As IPointCollection4
Dim pZawareCol As IZAware, pMawareCol As IMAware
Dim pPoint As IPoint, pconstpoint2 As IConstructPoint2
'Create a MAware and a ZAware multipoint
pPoints(0) = New Point
pPoints(1) = New Point
pPoints(2) = New Point
pPoints(3) = New Point
pPoints(0).PutCoords(0, 0)
pPoints(1).PutCoords(0, 5)
pPoints(2).PutCoords(5, 5)
pPoints(3).PutCoords(5, 0)
pPoints(0).Z = 10
pPoints(1).Z = 10
pPoints(2).Z = 20
pPoints(3).Z = 10
pPoints(0).M = 10
pPoints(1).M = 10
pPoints(2).M = 20
pPoints(3).M = 10
pPointcol = New Multipoint
Dim pGeometryBridge As IGeometryBridge
pGeometryBridge = New GeometryEnvironment
pGeometryBridge.AddPoints(pPointcol, pPoints)
pZawareCol = pPointcol
pZawareCol.ZAware = True
pMawareCol = pPointcol
pMawareCol.MAware = True
pconstpoint2 = New Point
'** Construct the average point with esriAttributeM
pconstpoint2.ConstructAverage(pPointcol, esriGeometryAttributes.esriAttributeM)
pPoint = pconstpoint2
Debug.Print("***** esriAttributeM *****")
Debug.Print(pPoint.X & " , " & pPoint.Y & " , " & pPoint.M)
'** Construct the average point with esriAttributeZ
pconstpoint2 = New Point
pconstpoint2.ConstructAverage(pPointcol, esriGeometryAttributes.esriAttributeZ)
pPoint = pconstpoint2
Debug.Print("***** esriAttributeZ *****")
Debug.Print(pPoint.X & " , " & pPoint.Y & " , " & pPoint.Z)
End Sub