private ICircularArc ConstructCurveFromString(string inString, ISegment ExitTangentFromPreviousCourse, esriDirectionType inDirectionType, esriDirectionUnits inDirectionUnits, out double outChordLength, out double outChordBearing) {// IConstructCircularArc pConstArc = new CircularArcClass(); ICircularArc pArc = (ICircularArc)pConstArc; IPoint pPt = new PointClass(); pPt.PutCoords(1000, 1000); //initialize the curve params bool bHasRadius = false; double dRadius = -1; bool bHasChord = false; double dChord = -1; bool bHasArc = false; double dArcLength = -1; bool bHasDelta = false; double dDelta = -1; bool bCCW = false; //assume curve to right unless proven otherwise //now initialize bearing types for non-tangent curves bool bHasRadialBearing = false; double dRadialBearing = -1; bool bHasChordBearing = false; double dChordBearing = -1; bool bHasTangentBearing = false; double dTangentBearing = -1; ISegment EntryTangentSegment = null; int iItemPosition = 0; string[] sCourse = inString.Split(' '); int UpperBound = sCourse.GetUpperBound(0); bool bIsTangentCurve = (((string)sCourse.GetValue(0)).ToLower() == "tc"); foreach (string item in sCourse) { if (item == null) { break; } if ((item.ToLower() == "r") && (!bHasRadius) && (iItemPosition <= 3)) { // this r is for radius dRadius = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasRadius = true; //found a radius } if ((item.ToLower()) == "c" && (!bHasChord) && (iItemPosition <= 3)) { // this c is for chord length dChord = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasChord = true; //found a chord length } if ((item.ToLower()) == "a" && (!bHasArc) && (iItemPosition <= 3)) { // this a is for arc length dArcLength = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasArc = true; //found an arc length } if ((item.ToLower()) == "d" && (!bHasDelta) && (iItemPosition <= 3)) { // this d is for delta or central angle dDelta = Angle_2_Radians((string)sCourse.GetValue(iItemPosition + 1), inDirectionUnits); bHasDelta = true; //found a central angle } if ((item.ToLower()) == "r" && (!bHasRadialBearing) && (iItemPosition > 3) && (UpperBound > 5)) {// this r is for radial bearing try { dRadialBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); if (!(dRadialBearing == -999)) { bHasRadialBearing = true; } //found a radial bearing } catch { }//this will catch case of final R meaning a curve right and not radial bearing } if ((item.ToLower()) == "c" && (!bHasChordBearing) && (iItemPosition > 3)) { // this c is for chord bearing dChordBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasChordBearing = true; //found a chord bearing } if ((item.ToLower()) == "t" && (!bHasTangentBearing) && (iItemPosition > 3)) { // this t is for tangent bearing dTangentBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasTangentBearing = true; //found a tangent bearing IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTangentBearing, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if ((item.ToLower()) == "l") { // this l is for defining a curve to the left bCCW = true; } iItemPosition += 1; } if (!(bIsTangentCurve)) //non-tangent curve { //chord bearing if (bHasRadius && bHasChord && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusChord(pPt, dChordBearing, bCCW, dRadius, dChord, true); } catch { }; } if (bHasRadius && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusArc(pPt, dChordBearing, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusAngle(pPt, dChordBearing, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingAngleChord(pPt, dChordBearing, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingChordArc(pPt, dChordBearing, bCCW, dChord, dArcLength); } catch { }; } //tangent bearing if (bHasRadius && bHasChord && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } //radial bearing if (bHasRadialBearing) { //need to convert radial bearing to tangent bearing by adding/subtracting 90 degrees double dTanBear = 0; if (bCCW) { dTanBear = dRadialBearing - (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); } else { dTanBear = dRadialBearing + (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); } IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTanBear, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if (bHasRadius && bHasChord && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } } else { //tangent curve if (bHasRadius && bHasChord) { try { pConstArc.ConstructTangentRadiusChord(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc) { try { pConstArc.ConstructTangentRadiusArc(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta) { try { pConstArc.ConstructTangentRadiusAngle(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta) { try { pConstArc.ConstructTangentAngleChord(ExitTangentFromPreviousCourse, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc) { try { pConstArc.ConstructTangentChordArc(ExitTangentFromPreviousCourse, false, bCCW, dChord, dArcLength); } catch { }; } } ILine pLine = new LineClass(); try { pLine.PutCoords(pArc.FromPoint, pArc.ToPoint); } catch { outChordLength = -1; outChordBearing = -1; return(null); } outChordLength = pLine.Length; outChordBearing = pLine.Angle; return(pArc); }
private ICircularArc ConstructCurveFromString(string inString, ISegment ExitTangentFromPreviousCourse, esriDirectionType inDirectionType, esriDirectionUnits inDirectionUnits, out double outChordLength, out double outChordBearing) { // IConstructCircularArc pConstArc = new CircularArcClass(); ICircularArc pArc = (ICircularArc)pConstArc; IPoint pPt = new PointClass(); pPt.PutCoords(1000, 1000); //initialize the curve params bool bHasRadius = false; double dRadius = -1; bool bHasChord = false; double dChord = -1; bool bHasArc = false; double dArcLength = -1; bool bHasDelta = false; double dDelta = -1; bool bCCW = false; //assume curve to right unless proven otherwise //now initialize bearing types for non-tangent curves bool bHasRadialBearing = false; double dRadialBearing = -1; bool bHasChordBearing = false; double dChordBearing = -1; bool bHasTangentBearing = false; double dTangentBearing = -1; ISegment EntryTangentSegment = null; int iItemPosition = 0; string[] sCourse = inString.Split(' '); int UpperBound = sCourse.GetUpperBound(0); bool bIsTangentCurve = (((string)sCourse.GetValue(0)).ToLower() == "tc"); foreach (string item in sCourse) { if (item == null) break; if ((item.ToLower() == "r") && (!bHasRadius) && (iItemPosition <= 3)) {// this r is for radius dRadius = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasRadius = true; //found a radius } if ((item.ToLower()) == "c" && (!bHasChord) && (iItemPosition <= 3)) {// this c is for chord length dChord = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasChord = true; //found a chord length } if ((item.ToLower()) == "a" && (!bHasArc) && (iItemPosition <= 3)) {// this a is for arc length dArcLength = Convert.ToDouble(sCourse.GetValue(iItemPosition + 1)); bHasArc = true; //found an arc length } if ((item.ToLower()) == "d" && (!bHasDelta) && (iItemPosition <= 3)) {// this d is for delta or central angle dDelta = Angle_2_Radians((string)sCourse.GetValue(iItemPosition + 1), inDirectionUnits); bHasDelta = true; //found a central angle } if ((item.ToLower()) == "r" && (!bHasRadialBearing) && (iItemPosition > 3) && (UpperBound > 5)) {// this r is for radial bearing try { dRadialBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); if (!(dRadialBearing == -999)) { bHasRadialBearing = true; } //found a radial bearing } catch { }//this will catch case of final R meaning a curve right and not radial bearing } if ((item.ToLower()) == "c" && (!bHasChordBearing) && (iItemPosition > 3)) {// this c is for chord bearing dChordBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasChordBearing = true; //found a chord bearing } if ((item.ToLower()) == "t" && (!bHasTangentBearing) && (iItemPosition > 3)) {// this t is for tangent bearing dTangentBearing = DirectionString_2_PolarRadians((string)sCourse.GetValue(iItemPosition + 1), inDirectionType, inDirectionUnits); bHasTangentBearing = true; //found a tangent bearing IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTangentBearing, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if ((item.ToLower()) == "l") // this l is for defining a curve to the left bCCW = true; iItemPosition += 1; } if (!(bIsTangentCurve)) //non-tangent curve {//chord bearing if (bHasRadius && bHasChord && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusChord(pPt, dChordBearing, bCCW, dRadius, dChord, true); } catch { }; } if (bHasRadius && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusArc(pPt, dChordBearing, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingRadiusAngle(pPt, dChordBearing, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasChordBearing) { try { pConstArc.ConstructBearingAngleChord(pPt, dChordBearing, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasChordBearing) { try { pConstArc.ConstructBearingChordArc(pPt, dChordBearing, bCCW, dChord, dArcLength); } catch { }; } //tangent bearing if (bHasRadius && bHasChord && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasTangentBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasTangentBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } //radial bearing if (bHasRadialBearing) { //need to convert radial bearing to tangent bearing by adding/subtracting 90 degrees double dTanBear = 0; if (bCCW) dTanBear = dRadialBearing - (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); else dTanBear = dRadialBearing + (Angle_2_Radians("90", esriDirectionUnits.esriDUDecimalDegrees)); IConstructPoint2 pToPt = new PointClass(); pToPt.ConstructAngleDistance(pPt, dTanBear, 100); ILine EntryTangentLine = new LineClass(); EntryTangentLine.PutCoords(pPt, (IPoint)pToPt); EntryTangentSegment = (ISegment)EntryTangentLine; } if (bHasRadius && bHasChord && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusChord(EntryTangentSegment, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusArc(EntryTangentSegment, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentRadiusAngle(EntryTangentSegment, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta && bHasRadialBearing) { try { pConstArc.ConstructTangentAngleChord(EntryTangentSegment, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc && bHasRadialBearing) { try { pConstArc.ConstructTangentChordArc(EntryTangentSegment, false, bCCW, dChord, dArcLength); } catch { }; } } else { //tangent curve if (bHasRadius && bHasChord) { try { pConstArc.ConstructTangentRadiusChord(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dChord); } catch { }; } if (bHasRadius && bHasArc) { try { pConstArc.ConstructTangentRadiusArc(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dArcLength); } catch { }; } if (bHasRadius && bHasDelta) { try { pConstArc.ConstructTangentRadiusAngle(ExitTangentFromPreviousCourse, false, bCCW, dRadius, dDelta); } catch { }; } if (bHasChord && bHasDelta) { try { pConstArc.ConstructTangentAngleChord(ExitTangentFromPreviousCourse, false, bCCW, dDelta, dChord); } catch { }; } if (bHasChord && bHasArc) { try { pConstArc.ConstructTangentChordArc(ExitTangentFromPreviousCourse, false, bCCW, dChord, dArcLength); } catch { }; } } ILine pLine = new LineClass(); try { pLine.PutCoords(pArc.FromPoint, pArc.ToPoint); } catch { outChordLength = -1; outChordBearing = -1; return null; } outChordLength = pLine.Length; outChordBearing = pLine.Angle; return pArc; }