Exemple #1
0
        private void FindTerminusForSequence(ref IGSForwardStar FwdStar, int StartNodeId,
                                             ref int TerminusPoint, int iInfinityChecker)
        {
            if (TerminusPoint > -1)
            {
                return;
            }

            //iInfinityChecker++;
            if (iInfinityChecker++ > 5000)
            {
                return;
            }

            ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
            int        iCnt2   = 0;

            iCnt2 = iLngArr.Count;
            IGSLine pGSLine = null;

            for (int i = 0; i < iCnt2; i++)
            {
                int  i2          = iLngArr.get_Element(i);
                bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);

                if (iCnt2 == 1) //this is a terminus/end-line
                {
                    TerminusPoint = StartNodeId;
                }

                FindTerminusForSequence(ref FwdStar, i2, ref TerminusPoint, iInfinityChecker);
            }
        }
Exemple #2
0
        protected override void OnClick()
        {
            ICadastralEditor   pCadEd         = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
            IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd;

            ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd;

            //bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen;

            if (pParcEditorMan == null)
            {
                return;
            }

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            if (pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing and try again.");
                return;
            }

            IParcelConstruction       pConstr                   = pParcEditorMan.ParcelConstruction;
            IParcelConstruction4      pConstr4                  = pConstr as IParcelConstruction4;
            ICadastralPoints          pCadastralPts             = pConstr4 as ICadastralPoints;
            ICadastralEditorSettings2 pCadastralEditorSettings2 = pCadEd as ICadastralEditorSettings2;

            ICadastralFixedPoints pFixedPoints = pCadastralPts as ICadastralFixedPoints;
            IPointCalculation     pPointCalc   = new PointCalculationClass();

            if (pConstr == null)
            {
                return;
            }

            IGSLine pParcelLine = null;
            IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd;
            IGSPoint             pStartPoint     = null;
            List <int>           lstPointIds     = new List <int>();

            List <IVector3D> Traverse = new List <IVector3D>();

            //get rotation here
            IParcelConstructionData    pConstrData = pConstr4.ConstructionData;
            IConstructionParentParcels pConstructionParentParcels = pConstrData as IConstructionParentParcels;

            ICadastralUndoRedo pCadUndoRedo = pConstr as ICadastralUndoRedo;

            try
            {
                int iParcelID = -1;
                if (pConstructionParentParcels.ParentParcelCount > 0)
                {
                    pConstructionParentParcels.GetParentParcel(0, ref iParcelID);
                }

                ICadastralParcel pCadaParcel = pCadPacketMan.JobPacket as ICadastralParcel;

                IGSParcel pGSParcel = null;

                if (pCadaParcel != null)
                {
                    pGSParcel = pCadaParcel.GetParcel(iParcelID);
                }
                //if in measurement view then rotation is 0
                double TheRotation = 0;

                if (pGSParcel == null)
                {
                    pGSParcel = pConstr.Parcel;
                }

                if (!pCadastralEditorSettings2.MeasurementView)
                {
                    TheRotation = pGSParcel.Rotation;//radians
                }
                if (TheRotation == 123456789)
                {
                    TheRotation = 0;
                }

                pPointCalc.Rotation = TheRotation;
                IGSPoint pClosingPoint = null;

                #region simple method as fall-back
                bool bUseSimpleStackSelection = false;
                if (bUseSimpleStackSelection)
                {
                    //bool bLineSelectionSequence = false;
                    //IGSLine pLastSelectedGSLineInGrid = null;
                    //for (int i = 0; i < pConstr.LineCount; i++)
                    //{
                    //  if (pConstr.GetLineSelection(i))
                    //  {
                    //    if (pConstr.GetLine(i, ref pParcelLine))
                    //    {
                    //      if (!bLineSelectionSequence) //first line
                    //      {
                    //        pStartPoint = pCadastralPts.GetPoint(pParcelLine.FromPoint);
                    //        pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
                    //      }

                    //      pPointCalc.AddLine(pParcelLine);

                    //      pLastSelectedGSLineInGrid = pParcelLine;
                    //      pToPoint = pCadastralPts.GetPoint(pParcelLine.ToPoint);
                    //      lstPointIds.Add(pToPoint.Id);

                    //    }
                    //    bLineSelectionSequence = true;

                    //    double dBear = pParcelLine.Bearing; //Azimuth of IVector3D is north azimuth radians zero degrees north
                    //    double dDist = pParcelLine.Distance;
                    //    IVector3D vec = new Vector3DClass();
                    //    vec.PolarSet(dBear, 0, dDist); ////Azimuth of IVector3D is north azimuth radians zero degrees north
                    //    Traverse.Add(vec);
                    //  }
                    //  else
                    //  {
                    //    if (bLineSelectionSequence && pConstr.GetLine(i, ref pParcelLine) && HasLineSelectionAfter(pConstr, i))
                    //    //if there was a prior selection and this line is a complete line, and there is no later selection
                    //    {
                    //      MessageBox.Show("Please select a continuous set of lines for closure.");
                    //      return;
                    //    }
                    //  }
                    //}
                    //pClosingPoint = pCadastralPts.GetPoint(pLastSelectedGSLineInGrid.ToPoint);
                }
                else
                #endregion

                {//build a forward star for the selected lines
                    IEnumCELines pCELines     = new EnumCELinesClass();
                    IEnumGSLines pEnumGSLines = (IEnumGSLines)pCELines;
                    ILongArray   pLongArray   = new LongArrayClass();
                    int          iFirstToNode = -1;
                    for (int i = 0; i < pConstr.LineCount; i++)
                    {
                        if (pConstr.GetLineSelection(i))
                        {
                            if (pConstr.GetLine(i, ref pParcelLine))
                            {
                                if (iFirstToNode < 0)
                                {
                                    iFirstToNode = pParcelLine.ToPoint;
                                }
                                pLongArray.Add(i);
                                pCELines.Add(pParcelLine);
                            }
                        }
                    }

                    if (pCELines.Count == 0)
                    {
                        MessageBox.Show("No lines selected. Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Line selection should not have branches.", "Traverse");
                        return;
                    }

                    IParcelLineFunctions3 ParcelLineFx = new ParcelFunctionsClass();
                    IGSForwardStar        pFwdStar     = ParcelLineFx.CreateForwardStar(pEnumGSLines);
                    //forward star object is now created for all the selected lines,
                    //need to first re-sequence the lines, and test for branching and discontinuity

                    int           iBranches = 0; int iTracedLines = 0;
                    int           iLoops = 0; int iTerminals = 0;
                    List <int>    LineIDList = new List <int>();
                    List <int>    FromList   = new List <int>();
                    List <int>    ToList     = new List <int>();
                    List <string> FromToLine = new List <string>();

                    bool bTraceSucceeded = TraceLines(ref pFwdStar, iFirstToNode, ref iBranches, ref iTracedLines,
                                                      ref iLoops, ref iTerminals, ref FromToLine, ref FromList, ref ToList, 0);

                    if (iBranches > 0)
                    {
                        MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Line selection should not have branches.", "Traverse");
                        return;
                    }

                    if (iTracedLines < pLongArray.Count)
                    {
                        MessageBox.Show("Please select a continuous set of lines for closure." + Environment.NewLine +
                                        "Selected Lines should be connected in a single sequence without branches.", "Traverse");
                        return;
                    }

                    //if it's a single loop check to see if the sequence needs to be reversed
                    //CW or CCW based on bearings
                    if (iLoops == 1)
                    {
                        bool bIsReversed = false;
                        foreach (int i in FromList)
                        {
                            if (i < 0)
                            {
                                bIsReversed = true;
                            }
                            else
                            {
                                bIsReversed = false;
                                break;
                            }
                        }
                        if (bIsReversed)
                        {//all courses are running reversed, so reverse the whole sequence
                            FromToLine.Clear();
                            FromList.Reverse();
                            ToList.Reverse();
                            int    iNewFrom   = -ToList[ToList.Count - 1];
                            int    iNewTo     = -FromList[ToList.Count - 1];
                            string sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
                            FromToLine.Add(sNewFromTo);
                            for (int i = 1; i < ToList.Count; i++)
                            {
                                iNewFrom   = -ToList[i - 1];
                                iNewTo     = -FromList[i - 1];
                                sNewFromTo = iNewFrom.ToString() + "," + iNewTo.ToString();
                                FromToLine.Add(sNewFromTo);
                            }
                        }
                    }

                    LineIDList.Clear();
                    FromList.Clear();
                    ToList.Clear();
                    pLongArray.RemoveAll();

                    pCadUndoRedo.StartUndoRedoSession("Adjust Traverse");

                    if (iLoops == 0)
                    {
                        //re-sequence using TraceLines function based on either end point, because the order of
                        //selected construction lines in grid don't control start or end point
                        FromToLine.Clear();
                        int iTerminus = -1;
                        iTracedLines = 0;
                        iBranches    = 0;
                        iLoops       = 0; iTerminals = 0;
                        FindTerminusForSequence(ref pFwdStar, iFirstToNode, ref iTerminus, 0);
                        if (iTerminus == -1)
                        {
                            pCadUndoRedo.WriteUndoRedoSession(false);
                            return;
                        }
                        TraceLines(ref pFwdStar, iTerminus, ref iBranches, ref iTracedLines, ref iLoops, ref iTerminals,
                                   ref FromToLine, ref FromList, ref ToList, 0);
                    }

                    List <IVector3D> SequencedTraverse = new List <IVector3D>();
                    IGSLine          pGSLineInPath     = null;
                    foreach (string s in FromToLine)
                    {
                        string[] sFromTo = s.Split(',');
                        int      iFrom   = Convert.ToInt32(sFromTo[0]);
                        int      iTo     = Convert.ToInt32(sFromTo[1]);

                        bool bReversed = pFwdStar.GetLine(iFrom, iTo, ref pGSLineInPath);
                        if (bReversed)
                        {
                            IGSLine pGSLine180 = new GSLineClass();
                            pGSLine180.FromPoint = pGSLineInPath.ToPoint;
                            pGSLine180.ToPoint   = pGSLineInPath.FromPoint;
                            pGSLine180.Bearing   = pGSLineInPath.Bearing + Math.PI;
                            pGSLine180.Distance  = pGSLineInPath.Distance;

                            IVector3D vec180 = new Vector3DClass();
                            vec180.PolarSet(pGSLine180.Bearing, 0, pGSLine180.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                            Traverse.Add(vec180);
                            lstPointIds.Add(pGSLine180.ToPoint);
                            pPointCalc.AddLine(pGSLine180);
                        }
                        else
                        {
                            double    dBear = pGSLineInPath.Bearing;
                            double    dDist = pGSLineInPath.Distance;
                            IVector3D vec   = new Vector3DClass();
                            vec.PolarSet(dBear, 0, dDist); //Azimuth of IVector3D is north azimuth radians zero degrees north
                            Traverse.Add(vec);
                            lstPointIds.Add(pGSLineInPath.ToPoint);
                            pPointCalc.AddLine(pGSLineInPath);
                        }

                        if (pStartPoint == null)
                        {
                            if (bReversed)
                            {
                                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
                            }
                            else
                            {
                                pStartPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
                            }
                        }

                        if (bReversed)
                        {
                            pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.FromPoint);
                        }
                        else
                        {
                            pClosingPoint = pCadastralPts.GetPoint(pGSLineInPath.ToPoint);
                        }
                    }
                }

                if (pStartPoint == null)
                {
                    pCadUndoRedo.WriteUndoRedoSession(false);
                    return;
                }
                IPoint pStart = new PointClass();
                pStart.X = pStartPoint.X;
                pStart.Y = pStartPoint.Y;

                string sAdjustMethod = "Compass";
                esriParcelAdjustmentType eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;

                if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentNone ||
                    pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCompass)
                {
                    eAdjMethod = esriParcelAdjustmentType.esriParcelAdjustmentCompass;
                }
                else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentCrandall)
                {
                    sAdjustMethod = "Crandall";
                    eAdjMethod    = pCadastralEditorSettings2.ParcelAdjustment;
                }
                else if (pCadastralEditorSettings2.ParcelAdjustment == esriParcelAdjustmentType.esriParcelAdjustmentTransit)
                {
                    sAdjustMethod = "Transit";
                    eAdjMethod    = pCadastralEditorSettings2.ParcelAdjustment;
                }

                pPointCalc.CalculatePoints(eAdjMethod, pStartPoint.Id, pStartPoint, pClosingPoint.Id, pClosingPoint, true);
                ITraverseClosure pClose = pPointCalc.Closure;
                List <string>    lstCoursesFromTo = new List <string>();
                List <IVector3D> AdjustedTraverse = new List <IVector3D>();
                double           dAdjustedPointX = 0; double dAdjustedPointY = 0;
                double           dPreviousPointX = 0; double dPreviousPointY = 0;

                for (int i = 0; i < pClose.CourseCount; i++)
                {
                    IGSPoint pPt = pCadastralPts.GetPoint(lstPointIds[i]);
                    dAdjustedPointY = pPointCalc.GetCalculatedPoint(lstPointIds[i], ref dAdjustedPointX);
                    string    sFromTo       = "";
                    IVector3D pAdjustedLine = new Vector3DClass();
                    if (i == 0)
                    {
                        sFromTo = pStartPoint.Id.ToString() + "-" + lstPointIds[i].ToString();
                        pAdjustedLine.SetComponents(dAdjustedPointX - pStartPoint.X, dAdjustedPointY - pStartPoint.Y, 0);
                    }
                    else
                    {
                        sFromTo = lstPointIds[i - 1].ToString() + "-" + lstPointIds[i].ToString();
                        pAdjustedLine.SetComponents(dAdjustedPointX - dPreviousPointX, dAdjustedPointY - dPreviousPointY, 0);
                    }
                    lstCoursesFromTo.Add(sFromTo);

                    IVector3D Z_Axis = new Vector3DClass();
                    Z_Axis.SetComponents(0, 0, 100);

                    pAdjustedLine.Rotate(TheRotation, Z_Axis);
                    AdjustedTraverse.Add(pAdjustedLine);

                    dPreviousPointX = dAdjustedPointX;
                    dPreviousPointY = dAdjustedPointY;

                    pPt.X = dAdjustedPointX;
                    pPt.Y = dAdjustedPointY;

                    if (!pCadastralEditorSettings2.MeasurementView)
                    {
                        pFixedPoints.SetFixedPoint(lstPointIds[i], true);
                    }
                }

                double  dMisclosureDistance = pClose.MisclosureDistance; double dMisclosureBearing = pClose.MisclosureDirection;
                IVector MiscloseVector = new Vector3DClass();

                IEditProperties2 pEdProps = pEd as IEditProperties2;

                IAngularConverter pAngConv = new AngularConverterClass();
                pAngConv.SetAngle(dMisclosureBearing, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians);
                //int iPrec = 7;
                //if (pConstr.Parcel.Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds)
                //  iPrec = 0;

                string sMiscloseBearing = pAngConv.GetString(pEdProps.DirectionType, pEdProps.DirectionUnits, pEdProps.AngularUnitPrecision);

                Utilities UTIL   = new Utilities();
                string    sRatio = "High Accuracy";

                if (pClose.RelativeErrorRatio < 10000)
                {
                    sRatio = "1:" + pClose.RelativeErrorRatio.ToString("0");
                }

                if (dMisclosureDistance >= 0.001)
                {
                    sMiscloseBearing = UTIL.FormatDirectionDashesToDegMinSecSymbols(sMiscloseBearing);
                }
                else
                {
                    sMiscloseBearing = "----";
                }

                ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass();
                double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, pConstr.Parcel.Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter);

                string sReport = "Closure:" + Environment.NewLine +
                                 "        error:  " + sRatio + Environment.NewLine +
                                 "        distance:  " + (dMisclosureDistance / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        bearing:  " + sMiscloseBearing + Environment.NewLine +
                                 "        xdist:  " + (pClose.MisclosureX / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        ydist:  " + (pClose.MisclosureY / dMetersPerUnit).ToString("0.000") + Environment.NewLine +
                                 "        courses: " + (pClose.CourseCount) + Environment.NewLine +
                                 Environment.NewLine + "Adjustment:" + Environment.NewLine +
                                 "        method: " + sAdjustMethod;

                dlgTraverseResults dlgTraverseResults = new dlgTraverseResults();
                AddTraverseInfoToGrid(pConstr.Parcel.Plan, dlgTraverseResults.dataGridView1, Traverse, AdjustedTraverse, lstCoursesFromTo);
                dlgTraverseResults.txtMiscloseReport.Text = sReport;
                DialogResult dRes = dlgTraverseResults.ShowDialog();
                if (dRes == DialogResult.Cancel)
                {
                    //since we cancelled, set the points back
                    foreach (int i in lstPointIds)
                    {
                        pFixedPoints.SetFixedPoint(i, false);
                    }
                    pCadUndoRedo.WriteUndoRedoSession(false);
                }
                else
                {
                    pCadUndoRedo.WriteUndoRedoSession(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + "Line number:" + ex.LineNumber().ToString()
                                + " in " + ex.TargetSite.Name, "Traverse");
                pCadUndoRedo.WriteUndoRedoSession(false);
            }
        }
Exemple #3
0
        private bool TraceLines(ref IGSForwardStar FwdStar, int StartNodeId, ref int BranchCount,
                                ref int TracedLinesCount, ref int LoopCount, ref int TerminusCount, ref List <string> FromToLine,
                                ref List <int> FromList, ref List <int> ToList, int iInfinityChecker)
        {
            iInfinityChecker++;
            if (iInfinityChecker > 5000)
            {
                return(false);
            }
            //(This is a self-calling function.) In this context 5000 downstream lines is like infinity,
            //so exit gracefully, and avoid probable endless loop.
            //Possible cause of endless loop? Corrupted data; example, a line with the same from and to point id
            IVector3D vect = new Vector3DClass();

            try
            {
                ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
                //get_ToNodes returns an array of radiated points, not "TO" points in the fabric data model sense
                int iCnt2 = 0;
                iCnt2 = iLngArr.Count;

                if (iCnt2 == 1)
                {
                    TerminusCount++;
                }

                IGSLine pGSLine = null;
                for (int i = 0; i < iCnt2; i++)
                {
                    int i2 = iLngArr.get_Element(i);

                    string sFromTo = StartNodeId.ToString() + "," + i2.ToString();
                    string sToFrom = i2.ToString() + "," + StartNodeId.ToString();

                    if (FromToLine.Contains(sFromTo) || FromToLine.Contains(sToFrom))
                    {
                        if (FromToLine.Contains(sFromTo))
                        {
                            LoopCount++;
                        }
                        continue;
                    }

                    if (iCnt2 > 2)
                    {
                        BranchCount++;
                    }

                    TracedLinesCount++;

                    FromToLine.Add(StartNodeId.ToString() + "," + i2.ToString());

                    bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);
                    if (bIsReversed)
                    {
                        FromList.Add(-StartNodeId);
                        ToList.Add(-i2);
                        vect.PolarSet(pGSLine.Bearing + Math.PI, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                    }
                    else
                    {
                        FromList.Add(StartNodeId);
                        ToList.Add(i2);
                        vect.PolarSet(pGSLine.Bearing, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                    }

                    if (!TraceLines(ref FwdStar, i2, ref BranchCount, ref TracedLinesCount, ref LoopCount, ref TerminusCount,
                                    ref FromToLine, ref FromList, ref ToList, iInfinityChecker))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool TraceLines(ref IGSForwardStar FwdStar, int StartNodeId, ref int BranchCount, 
      ref int TracedLinesCount, ref int LoopCount, ref int TerminusCount, ref List<string> FromToLine,
      ref List<int> FromList, ref List<int> ToList, int iInfinityChecker)
        {
            iInfinityChecker++;
              if (iInfinityChecker > 5000)
            return false;
              //(This is a self-calling function.) In this context 5000 downstream lines is like infinity,
              //so exit gracefully, and avoid probable endless loop.
              //Possible cause of endless loop? Corrupted data; example, a line with the same from and to point id
              IVector3D vect = new Vector3DClass();
              try
              {
            ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
            //get_ToNodes returns an array of radiated points, not "TO" points in the fabric data model sense
            int iCnt2 = 0;
            iCnt2 = iLngArr.Count;

            if (iCnt2 == 1)
              TerminusCount++;

            IGSLine pGSLine = null;
            for (int i = 0; i < iCnt2; i++)
            {
              int i2 = iLngArr.get_Element(i);

              string sFromTo = StartNodeId.ToString() + "," + i2.ToString();
              string sToFrom = i2.ToString() + "," + StartNodeId.ToString();

              if (FromToLine.Contains(sFromTo) || FromToLine.Contains(sToFrom))
              {
            if (FromToLine.Contains(sFromTo))
              LoopCount++;
            continue;
              }

              if (iCnt2 > 2)
            BranchCount++;

              TracedLinesCount++;

              FromToLine.Add(StartNodeId.ToString() + "," + i2.ToString());

              bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);
              if (bIsReversed)
              {
            FromList.Add(-StartNodeId);
            ToList.Add(-i2);
            vect.PolarSet(pGSLine.Bearing + Math.PI, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
              }
              else
              {
            FromList.Add(StartNodeId);
            ToList.Add(i2);
            vect.PolarSet(pGSLine.Bearing, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
              }

              if (!TraceLines(ref FwdStar, i2, ref BranchCount, ref TracedLinesCount,ref LoopCount, ref TerminusCount,
             ref FromToLine,ref FromList, ref ToList, iInfinityChecker))
            return false;
            }

            return true;
              }
              catch
              {
            return false;
              }
        }
        private void FindTerminusForSequence(ref IGSForwardStar FwdStar, int StartNodeId, 
      ref int TerminusPoint, int iInfinityChecker)
        {
            if (TerminusPoint > -1)
            return;

              //iInfinityChecker++;
              if (iInfinityChecker++ > 5000)
            return;

              ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
              int iCnt2 = 0;
              iCnt2 = iLngArr.Count;
              IGSLine pGSLine = null;
              for (int i = 0; i < iCnt2; i++)
              {
            int i2 = iLngArr.get_Element(i);
            bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);

            if (iCnt2 == 1) //this is a terminus/end-line
              TerminusPoint = StartNodeId;

            FindTerminusForSequence(ref FwdStar, i2, ref TerminusPoint, iInfinityChecker);
              }
        }
        private void CalculateStatedArea(IQueryFilter m_pQF, ITable pParcelsTable, ICadastralEditor pCadEd, ISpatialReference pMapSR,
                                         double SquareMetersPerUnitFactor, string Suffix, int DecimalPlaces, ref Dictionary <int, string> dict_ParcelSelection2CalculatedArea, ITrackCancel pTrackCancel)
        {
            bool bTrackCancel = (pTrackCancel != null);
            //ILine pLine = new LineClass();

            ICursor   pCursor       = pParcelsTable.Search(m_pQF, false);
            IRow      pParcelRecord = pCursor.NextRow();
            Utilities Utils         = new Utilities();

            IArray                     pParcelFeatArr = new ArrayClass();
            IGeoDataset                pGeoDS         = (IGeoDataset)((IFeatureClass)pParcelsTable).FeatureDataset;
            ISpatialReference          pFabricSR      = pGeoDS.SpatialReference;
            IProjectedCoordinateSystem pPCS           = null;
            double                     dMetersPerUnit = 1;
            bool bFabricIsInGCS = !(pFabricSR is IProjectedCoordinateSystem);

            if (!bFabricIsInGCS)
            {
                pPCS           = (IProjectedCoordinateSystem)pFabricSR;
                dMetersPerUnit = pPCS.CoordinateUnit.MetersPerUnit;
            }
            else
            {
                pPCS           = (IProjectedCoordinateSystem)pMapSR;
                dMetersPerUnit = pPCS.CoordinateUnit.MetersPerUnit;
            }

            //for each parcel record
            while (pParcelRecord != null)
            {
                IFeature pFeat = (IFeature)pParcelRecord;
                //IGeometry pGeom = pFeat.Shape;
                pParcelFeatArr.Add(pFeat);

                Marshal.ReleaseComObject(pParcelRecord);
                if (bTrackCancel)
                {
                    if (!pTrackCancel.Continue())
                    {
                        break;
                    }
                }

                pParcelRecord = pCursor.NextRow();
            }
            Marshal.ReleaseComObject(pCursor);

            ICadastralFeatureGenerator pFeatureGenerator = new CadastralFeatureGeneratorClass();
            IEnumGSParcels             pEnumGSParcels    = pFeatureGenerator.CreateParcelsFromFeatures(pCadEd, pParcelFeatArr, true);

            pEnumGSParcels.Reset();
            Dictionary <int, int>    dict_ParcelAndStartPt = new Dictionary <int, int>();
            Dictionary <int, IPoint> dict_PointID2Point    = new Dictionary <int, IPoint>();

            //dict_PointID2Point -->> this lookup makes an assumption that the fabric TO point geometry is at the same location as the line *geometry* endpoint
            IParcelLineFunctions3 ParcelLineFx = new ParcelFunctionsClass();

            IGSParcel pGSParcel      = pEnumGSParcels.Next();
            int       iFromPtIDX     = -1;
            int       iToPtIDX       = -1;
            int       iParcelIDX     = -1;
            int       iIsMajorFldIdx = -1;

            while (pGSParcel != null)
            {
                IEnumCELines pCELines     = new EnumCELinesClass();
                IEnumGSLines pEnumGSLines = (IEnumGSLines)pCELines;

                IEnumGSLines pGSLinesInner = pGSParcel.GetParcelLines(null, false);
                pGSLinesInner.Reset();
                IGSParcel         pTemp   = null;
                IGSLine           pGSLine = null;
                ICadastralFeature pCF     = (ICadastralFeature)pGSParcel;
                int iParcID = pCF.Row.OID;
                pGSLinesInner.Next(ref pTemp, ref pGSLine);
                bool bStartPointAdded = false;
                int  iFromPtID        = -1;
                while (pGSLine != null)
                {
                    if (pGSLine.Category == esriCadastralLineCategory.esriCadastralLineBoundary ||
                        pGSLine.Category == esriCadastralLineCategory.esriCadastralLineRoad ||
                        pGSLine.Category == esriCadastralLineCategory.esriCadastralLinePartConnection)
                    {
                        pCELines.Add(pGSLine);
                        ICadastralFeature pCadastralLineFeature = (ICadastralFeature)pGSLine;
                        IFeature          pLineFeat             = (IFeature)pCadastralLineFeature.Row;
                        if (iFromPtIDX == -1)
                        {
                            iFromPtIDX = pLineFeat.Fields.FindField("FROMPOINTID");
                        }
                        if (iToPtIDX == -1)
                        {
                            iToPtIDX = pLineFeat.Fields.FindField("TOPOINTID");
                        }
                        if (iParcelIDX == -1)
                        {
                            iParcelIDX = pLineFeat.Fields.FindField("PARCELID");
                        }
                        if (iIsMajorFldIdx == -1)
                        {
                            iIsMajorFldIdx = pLineFeat.Fields.FindField("ISMAJOR");
                        }

                        if (!bStartPointAdded)
                        {
                            iFromPtID        = (int)pLineFeat.get_Value(iFromPtIDX);
                            bStartPointAdded = true;
                        }
                        IPolyline pPolyline = (IPolyline)pLineFeat.ShapeCopy;
                        //if (bFabricIsInGCS)
                        pPolyline.Project(pPCS);
                        //dict_PointID2Point -->> this lookup makes an assumption that the fabric TO point geometry is at the same location as the line *geometry* endpoint
                        int iToPtID = (int)pLineFeat.get_Value(iToPtIDX);
                        //first make sure the point is not already added
                        if (!dict_PointID2Point.ContainsKey(iToPtID))
                        {
                            dict_PointID2Point.Add(iToPtID, pPolyline.ToPoint);
                        }
                    }
                    pGSLinesInner.Next(ref pTemp, ref pGSLine);
                }

                if (pGSParcel.Unclosed)
                {//skip unclosed parcels
                    pGSParcel = pEnumGSParcels.Next();
                    continue;
                }

                ICadastralFeature pCadastralPolygonFeature = (ICadastralFeature)pGSParcel;
                IFeature          pPolygonFeat             = (IFeature)pCadastralPolygonFeature.Row;
                IPolygon          pParcelPolygon           = (IPolygon)pPolygonFeat.ShapeCopy;

                IGSForwardStar pFwdStar = ParcelLineFx.CreateForwardStar(pEnumGSLines);
                //forward star is created for this parcel, now ready to find misclose for the parcel
                List <int>       LineIdsList               = new List <int>();
                List <IVector3D> TraverseCourses           = new List <IVector3D>();
                List <int>       FabricPointIDList         = new List <int>();
                List <double>    RadiusList                = new List <double>();
                List <bool>      IsMajorList               = new List <bool>();
                List <bool>      IsRunningCounterClockwise = new List <bool>();

                bool bPass = false;
                if (!bFabricIsInGCS)
                {
                    bPass = Utils.GetParcelTraverseEx(ref pFwdStar, iIsMajorFldIdx, iFromPtID, dMetersPerUnit,
                                                      ref LineIdsList, ref TraverseCourses, ref FabricPointIDList, ref RadiusList, ref IsMajorList, ref IsRunningCounterClockwise,
                                                      pParcelPolygon, 0, -1, -1, false);
                }
                else
                {
                    bPass = Utils.GetParcelTraverseEx(ref pFwdStar, iIsMajorFldIdx, iFromPtID, dMetersPerUnit * dMetersPerUnit,
                                                      ref LineIdsList, ref TraverseCourses, ref FabricPointIDList, ref RadiusList, ref IsMajorList, ref IsRunningCounterClockwise,
                                                      pParcelPolygon, 0, -1, -1, false);
                }
                //List<double> SysValList = new List<double>();
                IVector3D MiscloseVector = null;
                IPoint[]  FabricPoints   = new IPoint[FabricPointIDList.Count];//from control

                int f = 0;
                foreach (int j in FabricPointIDList)
                {
                    FabricPoints[f++] = dict_PointID2Point[j];
                }

                double dRatio = 10000;
                double dArea  = 0;
                double dGroundToGridFactor = pGSParcel.Scale;
                bool   bHasCircularArcs    = false;
                f = FabricPointIDList.Count - 1;
                IPoint[] AdjustedTraversePoints = Utils.BowditchAdjustEx(TraverseCourses, FabricPoints[f], FabricPoints[f],
                                                                         RadiusList, IsMajorList, IsRunningCounterClockwise, out MiscloseVector, out dRatio, out dArea,
                                                                         out bHasCircularArcs);

                if (MiscloseVector == null)
                {//skip if vector closure failed
                    pGSParcel = pEnumGSParcels.Next();
                    continue;
                }
                //now compare the Geometry polygon area with the computed area to see if we need to use parametric computed area
                // there needs to be at least one circular arc to warrant using this approach.
                IArea  pGeomArea           = pPolygonFeat.ShapeCopy as IArea;
                double dGroundArea         = pGeomArea.Area / (dGroundToGridFactor * dGroundToGridFactor);
                double dAreaPercentageDiff = Math.Abs(dGroundArea - Math.Abs(dArea)) / dGroundArea;

                if (dAreaPercentageDiff > 0.075 && bHasCircularArcs && dRatio > 250)
                {
                    dArea = dGroundArea;
                }
                else if (bHasCircularArcs && dArea < 0 && dRatio > 7500) //if dArea is negative then lines are running counter-clockwise
                {
                    dArea = Math.Abs(dArea);
                }
                else if (bHasCircularArcs && dArea < 0 && pParcelPolygon.ExteriorRingCount > 1)
                {
                    dArea = pGeomArea.Area;
                }

                dArea *= (dMetersPerUnit * dMetersPerUnit); //convert to square meters first
                dArea /= SquareMetersPerUnitFactor;         //convert to the given unit equivalent

                string sFormattedArea = Math.Round(dArea, DecimalPlaces).ToString() + Suffix;
                dict_ParcelSelection2CalculatedArea.Add(pGSParcel.DatabaseId, sFormattedArea);

                pGSParcel = pEnumGSParcels.Next();

                //if (bShowProgressor)
                //{
                //  if (pStepProgressor.Position < pStepProgressor.MaxRange)
                //    pStepProgressor.Step();
                //}
            }
        }