How to efficiently create a multipoint


SummaryA 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:

[VB.NET]
Sub CreateMultipointByPoints()

'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.
Dim pGeoBrg As ESRI.ArcGIS.Geometry.IGeometryBridge2
pGeoBrg = New ESRI.ArcGIS.Geometry.GeometryEnvironment
Dim pPointColl As ESRI.ArcGIS.Geometry.IPointCollection4
pPointColl = New ESRI.ArcGIS.Geometry.Multipoint
'Set pPointColl.SpatialReference = 'Define the spatial reference of the new multipoint.

Dim aWKSPointBuffer() As ESRI.ArcGIS.esriSystem.WKSPoint
Dim cPoints As Long
cPoints = 4 'The number of points in the first part
ReDim aWKSPointBuffer(0 To cPoints - 1)
'aWKSPointBuffer = 'Read cPoints into the point buffer.
pGeoBrg.SetWKSPoints(pPointColl, aWKSPointBuffer)
'pPointColl has now been defined.

End Sub

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]
Sub CreateMultipointFromExistingGeometry(ByVal pPoly As ESRI.ArcGIS.Geometry.IPolyline)

'Build a multipoint from a polygon.
'The multipoint contains point elements being the copies of buffered polygon.
Dim pTopoOp2 As ESRI.ArcGIS.Geometry.ITopologicalOperator2
pTopoOp2 = pPoly
pTopoOp2.IsKnownSimple_2 = False
pTopoOp2.Simplify()

'Create a buffer polygon of the input geometry.
Dim pBufferedPoly As ESRI.ArcGIS.Geometry.IPolygon
pBufferedPoly = pTopoOp2.Buffer(5)

'Get the points of the buffered polygon.
Dim pPointCollPoly As ESRI.ArcGIS.Geometry.IPointCollection
pPointCollPoly = pBufferedPoly

'Create a multipoint.
Dim pMultipoint As ESRI.ArcGIS.Geometry.IGeometry
pMultipoint = New ESRI.ArcGIS.Geometry.Multipoint
pMultipoint.SpatialReference = pPoly.SpatialReference
Dim pPointCollMultipoint As ESRI.ArcGIS.Geometry.IPointCollection
pPointCollMultipoint = pMultipoint
'Add copies of the polyline vertices to the multipoint.
pPointCollMultipoint.AddPointCollection(pPointCollPoly)

End Sub