How to efficiently create a multipoint


Summary
A multipoint geometry can be built in several ways according to the user's input. In this article, some of the most commonly used methods are listed for efficiently creating a multipoint geometry.

Building a multipoint using points

The following code shows how to build a multipoint using a collection of points. This approach is preferred when the user has a sequence of vertices as input. See the following:
[Java]
static void createMultipointByPoints()throws Exception{

    //Build multipoint from a sequence of points. 
    //At 9.2, the recommended way to add arrays of points to a geometry is to use
    //the IGeometryBridge2 interface on the GeometryEnvironment singleton object.
    IGeometryBridge2 geometryBridge = new GeometryEnvironment();
    IPointCollection4 pointCollection = new Multipoint();
    //TODO: Set the spatial reference of the new multipoint.


    int count = ...;
    _WKSPoint[] points = new _WKSPoint[count];
    //TODO: initialize the points array with proper coordinates
    geometryBridge.setWKSPoints(pointCollection, points);

}

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:
[Java]
static void createMultipointFromExistingGeometry(IPolyline pPoly)throws Exception{

    //Build a multipoint from a polygon.
    //The multipoint contains point elements being the copies of buffered polygon.
    ITopologicalOperator2 topoOp = (ITopologicalOperator2)pPoly;
    topoOp.setIsKnownSimple(false);
    topoOp.simplify();

    //Create a buffer polygon of the input geometry.
    IPolygon bufferedPoly = (IPolygon)topoOp.buffer(5);

    //Get the points of the buffered polygon.
    IPointCollection pointColl = (IPointCollection)bufferedPoly;

    //Create a multipoint.
    IGeometry multipoint = new Multipoint();
    multipoint.setSpatialReferenceByRef(pPoly.getSpatialReference());
    IPointCollection pointCollMultipoint = (IPointCollection)multipoint;
    //Add copies of the polyline vertices to the multipoint.
    pointCollMultipoint.addPointCollection(pointColl);

}