This document is archived and information here might be outdated.  Recommended version.


How to create a multipoint (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with geometry > Creating geometries > How to create a multipoint (ArcObjects .NET 10.6 SDK)

How to create a multipoint


Summary
A multipoint geometry can be built in several ways depending on user input. This topic shows two commonly used methods for efficiently creating a multipoint geometry.

In this topic


Creating a multipoint using points

The following code shows how to build a multipoint using a collection of points. This approach is preferred when you have a sequence of vertices as input.
[VB.NET]
Public Sub CreateMultipointByPoints()
    
    'Build multipoint from a sequence of points.
    'Add arrays of points to a geometry using the IGeometryBridge2 interface on the
    'GeometryEnvironment singleton object.
    
    Dim geometryBridge2 As IGeometryBridge2=New GeometryEnvironmentClass
    Dim pointCollection4 As IPointCollection4=New MultipointClass
    
    'TODO:
    'pointCollection4.SpatialReference='Define the spatial reference of the new multipoint.
    
    Dim aWKSPointBuffer() As WKSPoint
    Dim cPoints As Long=4 'The number of points in the first part.
    ReDim aWKSPointBuffer(0 To CInt(cPoints - 1))
    
    'TODO:
    'aWKSPointBuffer='Read cPoints into the point buffer.
    
    geometryBridge2.SetWKSPoints(pointCollection4, aWKSPointBuffer)
    
    'pointCollection4 has now been defined.
    
End Sub
[C#]
public void CreateMultipointByPoints()
{
    //Build multipoint from a sequence of points. 
    //Add arrays of points to a geometry using the IGeometryBridge2 interface on the 
    //GeometryEnvironment singleton object.

    IGeometryBridge2 geometryBridge2=new GeometryEnvironmentClass();
    IPointCollection4 pointCollection4=new MultipointClass();

    //TODO:
    //pointCollection4.SpatialReference='Define the spatial reference of the new multipoint.

    WKSPoint[] aWKSPointBuffer=null;
    long cPoints=4; //The number of points in the first part.
    aWKSPointBuffer=new WKSPoint[System.Convert.ToInt32(cPoints - 1) + 1];

    //TODO:
    //aWKSPointBuffer='Read cPoints into the point buffer.

    geometryBridge2.SetWKSPoints(pointCollection4, ref aWKSPointBuffer);

    //pointCollection4 has now been defined.
}

Creating a multipoint using existing geometries

A multipoint can be created based on existing geometries. In the following code, a multipoint is generated by buffering an existing polyline and getting the vertices of the result polygon:
[VB.NET]
Public Sub CreateMultipointFromExistingGeometry(ByVal polyline As IPolyline)
    
    'Build a multipoint from a polygon.
    'The multipoint contains point elements being the copies of buffered polygon.
    Dim topologicalOperator2 As ITopologicalOperator2=CType(polyline, ITopologicalOperator2)
    topologicalOperator2.IsKnownSimple_2=False
    topologicalOperator2.Simplify()
    
    'Create a buffer polygon of the input geometry.
    Dim geometryBuffer As IGeometry=topologicalOperator2.Buffer(5)
    Dim polygonBuffer As IPolygon=CType(geometryBuffer, IPolygon)
    
    'Get the points of the buffered polygon.
    Dim pointCollectionBuffer As IPointCollection=CType(polygonBuffer, IPointCollection)
    
    'Create a multipoint.
    Dim geometryMultipoint As IGeometry=New MultipointClass
    geometryMultipoint.SpatialReference=polyline.SpatialReference
    
    Dim pointCollectionlMultipoint As IPointCollection=CType(geometryMultipoint, IPointCollection)
    
    'Add copies of the polyline vertices to the multipoint.
    pointCollectionlMultipoint.AddPointCollection(pointCollectionBuffer)
    
End Sub
[C#]
public void CreateMultipointFromExistingGeometry(IPolyline polyline)
{
    //Build a multipoint from a polygon.
    //The multipoint contains point elements being the copies of buffered polygon.
    ITopologicalOperator2 topologicalOperator2=(ITopologicalOperator2)polyline;
    topologicalOperator2.IsKnownSimple_2=false;
    topologicalOperator2.Simplify();

    //Create a buffer polygon of the input geometry.
    IGeometry geometryBuffer=topologicalOperator2.Buffer(5);
    IPolygon polygonBuffer=(IPolygon)geometryBuffer;

    //Get the points of the buffered polygon.
    IPointCollection pointCollectionBuffer=(IPointCollection)polygonBuffer;

    //Create a multipoint.
    IGeometry geometryMultipoint=new MultipointClass();
    geometryMultipoint.SpatialReference=polyline.SpatialReference;

    IPointCollection pointCollectionlMultipoint=(IPointCollection)
        geometryMultipoint;

    //Add copies of the polyline vertices to the multipoint.
    pointCollectionlMultipoint.AddPointCollection(pointCollectionBuffer);
}






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):