I wish to count the number of segments of a polygon that has a length less than 25 meters when the angle between two vertices is not close to 180 degrees i.e. if the angle is between 178 to 182 degrees I want to ignore this case even though the segment length is less than 25 meters. I note the basic part of the code below is in VBA. Could anybody help me please to find why I get the wrong results? Thanks.
Dim pFCursor As IFeatureCursor
Set pFCursor = pFeatureClass.Update(Nothing, True)
Dim pFeature As IFeature
Set pFeature = pFCursor.NextFeature
Dim pGeomColl As IGeometryCollection
Dim pSegColl As ISegmentCollection
Dim pCurve As ICurve
Dim pLine1 As ILine
Dim pLine2 As ILine
Dim dVtxAng As Double
Dim i As Long, j As Long
Dim pi As Double
pi = Atn(1) * 4
Dim counter As Integer
counter = 0
Dim angleDeg As Double
Do Until pFeature Is Nothing
FID = pFeature.Value(intPosFID)
pFilter.WhereClause = "FID=" & FID
pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
Set pSelection = pLayer
pSelection.SelectFeatures pFilter, esriSelectionResultNew, True
'******************Code for measuring angles and minimum lenghts
' Get all disjoint paths
Set pGeomColl = pFeature.Shape
' Loop thru the paths
For i = 0 To pGeomColl.GeometryCount - 1
' Get all segments that make up this path
Set pSegColl = pGeomColl.Geometry(i)
Set pCurve = pSegColl
' Loop thru the segments
For j = 0 To pSegColl.SegmentCount - 2
' Get the next two lines
Set pLine1 = pSegColl.Segment(j)
Set pLine2 = pSegColl.Segment(j + 1)
' Calculate the left side angle (in degrees)
dVtxAng = CalcAngleBetweenLines(pLine1, pLine2)
angleDeg = dVtxAng * 57.2957795
If angleDeg >= 178 And angleDeg <= 182 Then
counter = counter
'if angle is close to 180 degrees then ignore the points and its vertices
GoTo Nextsegment
End If
'if angle is not close to 180 degrees and lenght of segment is less than 25m then count the segment
If angleDeg < 178 Or angleDeg > 182 And pLine1.Length < 25 Then
counter = counter + 1
End If
Nextsegment: Next j
Next i
'Store number of points in the field
pFeature.Value(intPosminLenght) = counter
pFCursor.UpdateFeature pFeature
counter = 0
Set pFeature = pFCursor.NextFeature
Loop
End Sub