Adding point IDs to a polyline
The following code example makes an existing polyline point ID aware and defines ID values for each of its vertices:
[C#]
public void AddPointIDs(IFeatureClass featureClass)
{
IFeatureCursor featureCursor = featureClass.Search(null, true);
IFeature currentFeature = featureCursor.NextFeature();
while (currentFeature != null)
{
IPointIDAware pointIDAware = currentFeature.Shape as IPointIDAware;
pointIDAware.PointIDAware = true;
//The polyline is now point ID aware. It will persist its point IDs the next time it is saved.
ISegmentCollection segmentCollection = pointIDAware as ISegmentCollection;
IEnumSegment segmentEnumeration = segmentCollection.EnumSegments;
ISegment currentSegment;
int partIndex = 0;
int segmentIndex = 0;
segmentEnumeration.Next(out currentSegment, ref partIndex, ref segmentIndex);
while (currentSegment != null)
{
ISegmentID segmentID = currentSegment as ISegmentID;
segmentID.SetIDs(segmentIndex, segmentIndex + 1);
segmentEnumeration.Next(out currentSegment, ref partIndex, ref
segmentIndex);
}
currentFeature.Shape = pointIDAware as IGeometry;
currentFeature.Store();
currentFeature = featureCursor.NextFeature();
}
}
[VB.NET]
Private Sub AddPointIds(ByVal featureClass As IFeatureClass)
Dim featureCursor As IFeatureCursor = featureClass.Search(Nothing, False)
Dim currentFeature As IFeature = featureCursor.NextFeature()
While Not currentFeature Is Nothing
Dim pointIDAware As IPointIDAware = CType(currentFeature.Shape, IPointIDAware)
pointIDAware.PointIDAware = True
'The polyline is now point ID aware.
' It will persist its point IDs the next time it is saved.
Dim segmentCollection As ISegmentCollection = CType(pointIDAware, ISegmentCollection)
Dim segmentEnumeration As IEnumSegment = segmentCollection.EnumSegments
Dim currentSegment As ISegment
Dim partIndex As Integer = 0
Dim segmentIndex As Integer = 0
'Warning about the current segment being passed by reference, and that it can result
'in a null reference exception at run time. No out keyword in VB .NET.
segmentEnumeration.Next(currentSegment, partIndex, segmentIndex)
While Not currentSegment Is Nothing
Dim segmentID As ISegmentID = currentSegment
segmentID.SetIDs(segmentIndex, segmentIndex + 1)
segmentEnumeration.Next(currentSegment, partIndex, segmentIndex)
End While
currentFeature.Shape = pointIDAware
currentFeature.Store()
currentFeature = featureCursor.NextFeature()
End While
End Sub
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
Engine Developer Kit | Engine |