AnsweredAssumed Answered

Issue when add point to a IPointCollection

Question asked by ppLily on Oct 5, 2016
Latest reply on Oct 7, 2016 by ppLily

Hi,

 

My polygon has several interior rings, and I want to move all vertices in these interior rings. I define the list of interior ring points into a list of IPointCollection, but when I try to add point to an IPointCollection, I got the "Index was out of range. Must be non-negative and less than the size of the collection" error.

 

My code as follows:

 

Dim polygon As IPolygon4 = TryCast(mFeature.Shape, IPolygon4)
Dim exteriorRingGeometryBag As IGeometryBag = polygon.ExteriorRingBag
Dim exteriorRingGeometryCollection As IGeometryCollection = TryCast(exteriorRingGeometryBag, IGeometryCollection)
Dim inRing As List(Of IPointCollection) = New List(Of IPointCollection)

For i = 0 To exteriorRingGeometryCollection.GeometryCount - 1
    Dim exteriorRingGeometry As IGeometry = exteriorRingGeometryCollection.Geometry(i)
    Dim exteriorRingPointCollection As IPointCollection = TryCast(exteriorRingGeometry, IPointCollection)
    Dim interiorRingGeometryBag As IGeometryBag = polygon.InteriorRingBag(TryCast(exteriorRingGeometry, IRing))
    Dim interiorRingGeometryCollection As IGeometryCollection = TryCast(interiorRingGeometryBag, IGeometryCollection)

    For k = 0 To interiorRingGeometryCollection.GeometryCount - 1
        Dim InteriorRingGeometry As IGeometry = interiorRingGeometryCollection.Geometry(k)
        Dim InteriorRingPointCollection As IPointCollection = TryCast(InteriorRingGeometry, IPointCollection)
        For m = 0 To InteriorRingPointCollection.PointCount - 1
            Dim pp As IPoint = InteriorRingPointCollection.Point(m)
            pp.X = Round(pp.X, 2)
            pp.Y = Round(pp.Y, 2)

           inRing(k).AddPoint(pp)  ' I got error this line

    Next
Next

Outcomes