How to efficiently create valid multipoints


This sample demonstrates how to create valid multipoints efficiently.

How to use

  1. Add this code into VBA
[VBA]
'************************************************************************************************
'* 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 sub is demonstrating it by creating a simple multipoint.
'* NOTE : NA
'*************************************************************************

Sub createMultipointIPointCollection()
    Dim pPointColl As IPointCollection, pPoints(3) As IPoint, i As Long, pspref As ISpatialReference, pGeoSpRef As IGeometry
    'Create a new multipoint via the IPointCollection interface
    Set pPointColl = New Multipoint
    'Initialize points
    For i = 0 To 3
        Set pPoints(i) = New EsriGeometry.Point
    Next
    'Putcoords of points
    pPoints(0).PutCoords 0, 0
    pPoints(1).PutCoords 0, 10
    pPoints(2).PutCoords 10, 10
    pPoints(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 pspref = New UnknownCoordinateSystem
    pspref.SetFalseOriginAndUnits -10000, -10000, 100000 'Set the false origin and units.
    'The XYUnits value is equivalent to the precision specified when creating a feature class
    Set pGeoSpRef = pPointColl
    Set pGeoSpRef.SpatialReference = pspref
    'Add all the points to the multipoint using AddPoints method
    pPointColl.AddPoints 4, pPoints(0)
    'You can draw, store or use the multipoint(pPointColl) in other geometry operations at this point
End Sub