How to efficiently create valid Multipoints


This sample demonstrates how to create valid multipoints efficiently. The function creates a multipoint using IPointCollection.  

How to use

  1. Add the function to your project.
[VCPP]
//************************************************************************************************
//* GEOMETRY TYPE : MULTIPOINT
//* NOTE :In the following samples the geometries are simple without having to use ITopologicalOpeartor::Simplify.
//*       However if the data creation process cannot insure simple geometries
//*       the geometries have to be simplified before storing or using those in geometry operations.
//************************************************************************************************

//*************************************************************************
//* NAME : createMultipointIPointCollection
//* DESCRIPTION : Create a multipoint using IPointCollection.
//* This function is demonstrating it by creating a simple multipoint.
//* NOTE : NA
//*************************************************************************
HRESULT createMultipointIPointCollection()
{
  int i;
  // Create a new multipoint via the IPointCollection interface
  IPointCollectionPtr ipPointColl(CLSID_Multipoint);

  // Initialize points
  IPointPtr ipPoints[4];
  for (i = 0; i < 4; ++i)
  {
    ipPoints[i].CreateInstance(CLSID_Point);
  }

  // Putcoords of points
  ipPoints[0]->PutCoords(0, 0);
  ipPoints[1]->PutCoords(0, 10);
  ipPoints[2]->PutCoords(10, 10);
  ipPoints[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...
  ISpatialReferencePtr ipspref(CLSID_UnknownCoordinateSystem);
  ipspref->SetFalseOriginAndUnits( - 10000,  - 10000, 100000); 
    // Set the false origin and units.
  // The XYUnits value is equivalent to the precision specified when creating a feature class
  IGeometryPtr ipGeoSpRef(ipPointColl);
  ipGeoSpRef->putref_SpatialReference(ipspref);
  // Add all the points to the multipoint using AddPoints method
  for (i = 0; i < 4; ++i)
  {
    ipPointColl->AddPoint(ipPoints[i]);
  }

  // You can draw, store or use the multipoint(pPointColl) in other geometry operations at this point
  return S_OK;
}






Development licensing Deployment licensing
Engine Developer Kit Engine