Create valid multipoints
arcgissamples\geometry\CreateValidMultipoints.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package arcgissamples.geometry;

import com.esri.arcgis.geometry.*;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;

/**
 * This demonstrates how to create a valid multipoint geometry.
 */

public class CreateValidMultipoints
{
  public void CreateValidMultipoints()
  {
    
  }

  public static void main(String[] args)
  {
    System.out.println("Starting ClipByEnvelope - An ArcObjects Java SDK Developer Sample");
    try
    {
      // Initialize the engine and licenses.
      EngineInitializer.initializeEngine();

      AoInitialize aoInit = new AoInitialize();
      initializeArcGISLicenses(aoInit);
      
      CreateValidMultipoints x = new CreateValidMultipoints();
      x.createMultipointIPointCollection();

      aoInit.shutdown();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  /**
   * Creates a multi point collection
   * @throws Exception
   */
  private void createMultipointIPointCollection() throws Exception
  {
    Point pts[] = new Point[4];
    ISpatialReference spref;

    // Create a new multipoint
    Multipoint pointColl = new Multipoint();

    // Initialize points

    for (int i = 0; i <= 3; i++)
      pts[i] = new Point();

    // Putcoords of points
    pts[0].putCoords(0, 0);
    pts[1].putCoords(0, 10);
    pts[2].putCoords(10, 10);
    pts[3].putCoords(10, 0);

    // *********************************************************
    // THE SPATIAL REFERENCE SHOULD BE SET HERE ON THE MULTIPOINT
    // Here the spatial reference is created in memory but could also come from various sources:
    // IMap, IGeodataset, IGeometry etc...

    // Set the false origin and units.
    // The XYUnits value is equivalent to the precision specified when creating a feature class
    spref = new UnknownCoordinateSystem();
    spref.setFalseOriginAndUnits(-10000, -10000, 100000);

    // Finally, apply the spatial reference
    pointColl.setSpatialReferenceByRef(spref);

    // Add all the points to the multipoint using AddPoints method of the IGeometryBridge interface
    IGeometryBridge gBridge = new GeometryEnvironment();
    gBridge.addPoints(pointColl, pts);

    // You can draw, store or use the multipoint(pointColl) in other geometry operations at this point
    System.out.println("done");
  }

  /**
   * Initializes the lowest available ArcGIS License
   */
  private static void initializeArcGISLicenses(AoInitialize aoInit)
  {
    try
    {
      if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
      {
        aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
      }
      else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable)
      {
        aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
      }
      else
      {
        System.err.println("Could not initialize an Engine or ArcView license. Exiting application.");
        System.exit(-1);
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

}