protected void AddTraverseInfoToGrid(IGSPlan Plan, DataGridView TraverseGrid, List <IVector3D> Traverse, List <IVector3D> AdjustedTraverse, List <string> FromToList) { ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass(); double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter); IAngularConverter pAngConv = new AngularConverterClass(); Utilities Utils = new Utilities(); List <string> lstAdjustedCourses = new List <string>(); List <string> lstResiduals = new List <string>(); foreach (IVector3D vect in AdjustedTraverse) { pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); int iPrec = 7; if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds) { iPrec = 0; } string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec); string sAdjusted = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000"); lstAdjustedCourses.Add(sAdjusted); } int i = 0; foreach (IVector3D vect in Traverse) { pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); int iPrec = 7; if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds) { iPrec = 0; } string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec); string sDescription = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000"); string sDistResidual = ((vect.Magnitude - AdjustedTraverse[i].Magnitude) / dMetersPerUnit).ToString("0.000"); //get the angle difference between the vectors IVector3D vec1 = new Vector3DClass(); vec1.PolarSet(vect.Azimuth, 0, 1); IVector3D vec2 = new Vector3DClass(); vec2.PolarSet(AdjustedTraverse[i].Azimuth, 0, 1); double dAngleDifference = Math.Acos(vec1.DotProduct(vec2)); pAngConv.SetAngle(dAngleDifference, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians); string sAngResidual = pAngConv.GetString(esriDirectionType.esriDTPolar, Plan.AngleUnits, iPrec); sAngResidual = Utils.FormatDirectionDashesToDegMinSecSymbols(sAngResidual); TraverseGrid.Rows.Add(FromToList[i], sDescription, lstAdjustedCourses[i], sAngResidual + ", " + sDistResidual); i++; } }
protected void AddTraverseInfoToGrid(IGSPlan Plan, DataGridView TraverseGrid, List<IVector3D> Traverse, List<IVector3D> AdjustedTraverse, List<string> FromToList) { ICadastralUnitConversion pCadUnitConverter = new CadastralUnitConversionClass(); double dMetersPerUnit = pCadUnitConverter.ConvertDouble(1, Plan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter); IAngularConverter pAngConv = new AngularConverterClass(); Utilities Utils = new Utilities(); List<string> lstAdjustedCourses = new List<string>(); List<string> lstResiduals = new List<string>(); foreach (IVector3D vect in AdjustedTraverse) { pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); int iPrec = 7; if (Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds) iPrec = 0; string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec); string sAdjusted = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude / dMetersPerUnit).ToString("0.000"); lstAdjustedCourses.Add(sAdjusted); } int i = 0; foreach (IVector3D vect in Traverse) { pAngConv.SetAngle(vect.Azimuth, esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); int iPrec = 7; if(Plan.AngleUnits == esriDirectionUnits.esriDUDegreesMinutesSeconds) iPrec=0; string sBearing = pAngConv.GetString(Plan.DirectionFormat, Plan.AngleUnits, iPrec); string sDescription = Utils.FormatDirectionDashesToDegMinSecSymbols(sBearing) + ", " + (vect.Magnitude/dMetersPerUnit).ToString("0.000"); string sDistResidual= ((vect.Magnitude-AdjustedTraverse[i].Magnitude)/dMetersPerUnit).ToString("0.000"); //get the angle difference between the vectors IVector3D vec1 = new Vector3DClass(); vec1.PolarSet(vect.Azimuth, 0, 1); IVector3D vec2 = new Vector3DClass(); vec2.PolarSet(AdjustedTraverse[i].Azimuth, 0, 1); double dAngleDifference = Math.Acos(vec1.DotProduct(vec2)); pAngConv.SetAngle(dAngleDifference, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians); string sAngResidual = pAngConv.GetString(esriDirectionType.esriDTPolar, Plan.AngleUnits, iPrec); sAngResidual = Utils.FormatDirectionDashesToDegMinSecSymbols(sAngResidual); TraverseGrid.Rows.Add(FromToList[i], sDescription, lstAdjustedCourses[i], sAngResidual + ", " + sDistResidual); i++; } }
private IGSPlan FindFabricPlanByName(string PlanName, ICadastralEditor CadastralEditor) { ICursor pCur = null; try { ICadastralFabric pCadaFab = CadastralEditor.CadastralFabric; ITable pPlanTable = pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans); int iPlanNameFldID = pPlanTable.FindField("NAME"); string PlanNameFld = pPlanTable.Fields.get_Field(iPlanNameFldID).Name; IQueryFilter pQF = new QueryFilter(); pQF.WhereClause = PlanNameFld + "= '" + PlanName + "'"; pQF.SubFields = pPlanTable.OIDFieldName + PlanNameFld; pCur = pPlanTable.Search(pQF, false); IRow pPlanRow = pCur.NextRow(); IGSPlan pGSPlan = null; if (pPlanRow != null) { //Since plan was found, generate plan object from database: ICadastralFeatureGenerator pFeatureGenerator = new CadastralFeatureGenerator(); pGSPlan = pFeatureGenerator.CreatePlanFromRow(CadastralEditor, pPlanRow); Marshal.ReleaseComObject(pPlanRow); } return(pGSPlan); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } finally { if (pCur != null) { Marshal.ReleaseComObject(pCur); } } }
private IGSPlan FindFabricPlanByName(string PlanName, ICadastralEditor CadastralEditor) { ICursor pCur = null; try { ICadastralFabric pCadaFab = CadastralEditor.CadastralFabric; ITable pPlanTable = pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans); int iPlanNameFldID = pPlanTable.FindField("NAME"); string PlanNameFld = pPlanTable.Fields.get_Field(iPlanNameFldID).Name; IQueryFilter pQF = new QueryFilterClass(); pQF.WhereClause = PlanNameFld + "= '" + PlanName + "'"; pQF.SubFields = pPlanTable.OIDFieldName + PlanNameFld; pCur = pPlanTable.Search(pQF, false); IRow pPlanRow = pCur.NextRow(); IGSPlan pGSPlanDB = null; IGSPlan pGSPlan = null; if (pPlanRow != null) { //Since plan was found, generate plan object from database: ICadastralFeatureGenerator pFeatureGenerator = new CadastralFeatureGeneratorClass(); pGSPlanDB = pFeatureGenerator.CreatePlanFromRow(CadastralEditor, pPlanRow); //Hydrate the database plan as a new GSPlan in GeoSurvey Engine packet pGSPlan = new GSPlanClass(); AssignGSPlan(pGSPlanDB, pGSPlan, true); } return(pGSPlan); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } finally { } }
protected override void OnClick() { IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esriEditor.Editor"); if (pEd.EditState == esriEditState.esriStateNotEditing) { MessageBox.Show("Please start editing and try again."); return; } ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; ICadastralSelection pCadaSel = (ICadastralSelection)pCadEd; try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { pEd.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEParcelSelection, "Merge Parcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = "My New Plan"; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; pGSPlan.DirectionFormat = esriDirectionType.esriDTQuadrantBearing; pGSPlan.AngleUnits = esriDirectionUnits.esriDUDegreesMinutesSeconds; pGSPlan.AreaUnits = esriCadastralAreaUnits.esriCAUAcre; pGSPlan.Description = "My Test Plan for Merge"; pGSPlan.DistanceUnits = esriCadastralDistanceUnits.esriCDUFoot; } //3.b Add the plan to the job packet pCadaPlan.AddPlan(pGSPlan); ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IConstructParcelFunctions3 constrParcelFunctions = new ParcelFunctions() as IConstructParcelFunctions3; IEnumGSParcels selectedParcels = pCadaSel.SelectedParcels; //get selected parcels AFTER calling ::StartMapEdit to get the in-mem packet representation. IGSParcel gsParcel = constrParcelFunctions.MergeParcels(pGSPlan, pCadaPoints, selectedParcels, pCadaPacket); gsParcel.Type = 7; //7 = Tax parcel in the Local Government Information Model gsParcel.Lot = "My Merged Tax Parcel"; ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; //Make sure that any extended attributes on the new merged parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)gsParcel; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; pCadaParcel.AddParcel(gsParcel); //set the original parcels to historic selectedParcels.Reset(); IGSParcel selParcel = selectedParcels.Next(); while (selParcel != null) { selParcel.Historical = true; //set SystemEndDate pGSAttributes = (IGSAttributes)selParcel; if (pGSAttributes != null) { pGSAttributes.SetProperty("systemenddate", DateTime.Now); } selParcel = selectedParcels.Next(); } try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { pEd.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { pEd.StopOperation("Merge Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { pEd.AbortOperation(); MessageBox.Show(ex.Message); } }
private void AssignGSPlan(IGSPlan pGSSrcPlan, IGSPlan pGSDestPlan, bool setDatabaseID) { if (pGSSrcPlan == null || pGSDestPlan == null) { return; } int lAccuracy, dbId; esriDirectionUnits eAngleUnits; esriCadastralAreaUnits eAreaUnits; esriDirectionType eDirectionFormat; esriCadastralDistanceUnits eDistanceUnits; esriCadastralLineParameters eLinePara; bool isAtGround, isLocked, isTrueMid, isInternal; double dblGridFactor; string bsCompany, bsDesc, bsName, bsSurveyor; object vLegalDate = DateTime.Now; object vSurveyDate = DateTime.Now; lAccuracy = pGSSrcPlan.Accuracy; eAngleUnits = pGSSrcPlan.AngleUnits; eAreaUnits = pGSSrcPlan.AreaUnits; dblGridFactor = pGSSrcPlan.CombinedGridFactor; bsCompany = pGSSrcPlan.Company; bsDesc = pGSSrcPlan.Description; eDirectionFormat = pGSSrcPlan.DirectionFormat; isAtGround = pGSSrcPlan.DistanceAtGround; eDistanceUnits = pGSSrcPlan.DistanceUnits; vLegalDate = pGSSrcPlan.LegalDate; eLinePara = pGSSrcPlan.LineParameters; isLocked = pGSSrcPlan.Locked; bsName = pGSSrcPlan.Name; vSurveyDate = pGSSrcPlan.SurveyDate; bsSurveyor = pGSSrcPlan.Surveyor; isTrueMid = pGSSrcPlan.TrueMid; isInternal = pGSSrcPlan.InternalAngles; dbId = pGSSrcPlan.DatabaseId; pGSDestPlan.Accuracy = lAccuracy; pGSDestPlan.AngleUnits = eAngleUnits; pGSDestPlan.AreaUnits = eAreaUnits; pGSDestPlan.CombinedGridFactor = dblGridFactor; pGSDestPlan.Company = bsCompany; pGSDestPlan.Description = bsDesc; pGSDestPlan.DirectionFormat = eDirectionFormat; pGSDestPlan.DistanceAtGround = isAtGround; pGSDestPlan.DistanceUnits = eDistanceUnits; pGSDestPlan.LegalDate = vLegalDate; pGSDestPlan.LineParameters = eLinePara; pGSDestPlan.Locked = isLocked; pGSDestPlan.Name = bsName; pGSDestPlan.SurveyDate = vSurveyDate; pGSDestPlan.Surveyor = bsSurveyor; pGSDestPlan.TrueMid = isTrueMid; pGSDestPlan.InternalAngles = isInternal; if (setDatabaseID) { pGSDestPlan.DatabaseId = dbId; } AssignExtendedAttributes(pGSSrcPlan as IGSAttributes, pGSDestPlan as IGSAttributes); }
private void CreateParcelFromSegmentCollection(ISegmentCollection Segments, string PlanName) { int iCnt = Segments.SegmentCount; ISegment[] pSegmentArr = new ISegment[iCnt]; for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); } ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { m_editor.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = PlanName; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; } //3.b Add the plan to the job packet ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; pCadaPlan.AddPlan(pGSPlan); //4. Create Parcel ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; IGSParcel pNewGSParcel = new GSParcelClass(); //Make sure that any extended attributes on the parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //4a. Add the parcel to the packet. (do this before addlines) // - This will enable us to Acquire the parcel ID, // - Having the parcel attached to the packet allows InsertLine to function. pCadaParcel.AddParcel(pNewGSParcel); pNewGSParcel.Lot = "NewParcel"; pNewGSParcel.Type = 7; //4b. Set Plan (created above) IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName); pNewGSParcel.Plan = thePlan; //4c. Insert GSLines (from new) into GSParcel //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines. ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd; //Set up the initial start point, POB IPoint pPt1 = Segments.get_Segment(0).FromPoint; IZAware pZAw = (IZAware)pPt1; pZAw.ZAware = true; pPt1.Z = 0; //defaulting to 0 //Convert the point into metric units, and get a new (in-mem) point id IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1); pCadaPoints.AddPoint(pGSPointFrom); int iID1 = pGSPointFrom.Id; int iID1_Orig = iID1; int index = 0; IGSLine pGSLine = null; //++++++++++++ Add Courses ++++++++++++++ int iID2 = -1; bool bIsLoop = (Math.Abs(pPt1.X - Segments.get_Segment(iCnt - 1).ToPoint.X)) < 0.01 && (Math.Abs(pPt1.Y - Segments.get_Segment(iCnt - 1).ToPoint.Y)) < 0.01; IAngularConverter pAngConv = new AngularConverterClass(); for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); double dDir = 0; //radians north azimuth ILine pLineOrChord = new LineClass(); pLineOrChord.PutCoords(pSegmentArr[j].FromPoint, pSegmentArr[j].ToPoint); if (pAngConv.SetAngle(pLineOrChord.Angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians)) { dDir = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); } double dDist = pLineOrChord.Length; double dRadius = 0; int iAccuracy = -1; int iUserLineType = -1; int iCategory = -1; if (pSegmentArr[j] is ICircularArc) { ICircularArc pCircArc = pSegmentArr[j] as ICircularArc; dRadius = pCircArc.Radius; if (pCircArc.IsCounterClockwise) { dRadius = dRadius * -1; } } bool bComputeToPoint = (bIsLoop && (j < iCnt - 1)) || !bIsLoop; //From, Direction (NAz Radians), Distance (map's projection units), Radius pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID1, dDir, dDist, dRadius, iAccuracy, iUserLineType, iCategory, bComputeToPoint, out iID2); if (j < iCnt - 1 || !bIsLoop) { iID1 = iID2; } else if ((j == iCnt - 1) && bIsLoop) { pGSLine.ToPoint = iID1_Orig; //closing the traverse back to the POB } iID2 = -1; //Add the line to the new parcel if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } } //Add radial lines for circular curves pNewGSParcel.AddRadialLines(); // 4.e then set join=true on the parcel. pNewGSParcel.Joined = true; //let the packet know that a change has been made pCadPacketMan.SetPacketModified(true); //save the new parcel try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { m_editor.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { m_editor.StopOperation("New Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { m_editor.AbortOperation(); MessageBox.Show(ex.Message); } }
private bool RunAdjustment(ICadastralPacketManager pCadastralPacketManager, ICadastralAdjustment pCadAdj, ICadastralAdjustment3 pCadAdjEx, int Iteration, out double MaxShift, out string Summary) { esriCadastralDistanceUnits eDistUnits = esriCadastralDistanceUnits.esriCDUUSSurveyFoot; esriDirectionType eDirectType = esriDirectionType.esriDTNorthAzimuth; esriCadastralAreaUnits eAreaUnits = esriCadastralAreaUnits.esriCAUAcre; ICadastralPlan pCadPlan = (ICadastralPlan)pCadAdj; IEnumGSPlans pGSPlans = pCadPlan.GetPlans(enumGSPlansType.enumGSPlansWithParcels); pGSPlans.Reset(); IGSPlan pGSPlan = pGSPlans.Next(); while (pGSPlan != null) { eDistUnits = pGSPlan.DistanceUnits; eDirectType = pGSPlan.DirectionFormat; eAreaUnits = esriCadastralAreaUnits.esriCAUAcre; break; //just use the first one } double dMaxShift = -999; string sSummary = ""; MaxShift = dMaxShift; try { //get the units from the map plan sSummary = pCadAdj.PerformAdjustment(false, m_sBrowseFilePath, null, eDistUnits, eDirectType, eAreaUnits); double dMaxEast = -999; double dMaxNorth = -999; int iPt = -999; pCadAdjEx.GetMaxShiftData(ref iPt, ref dMaxEast, ref dMaxNorth); double dDistEast = -999; double dDistNorth = -999; IMetricUnitConverter pUnitConversion = (IMetricUnitConverter)pCadastralPacketManager; pUnitConversion.ConvertDistance(esriCadastralUnitConversionType.esriCUCFromMetric, dMaxEast, ref dDistEast); pUnitConversion.ConvertDistance(esriCadastralUnitConversionType.esriCUCFromMetric, dMaxNorth, ref dDistNorth); dMaxShift = Math.Sqrt((dDistEast * dDistEast) + (dDistNorth * dDistNorth)); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { MaxShift = dMaxShift; Summary = sSummary; } }
protected override void OnClick() { // **SAMPLE CODE NOTE** // the following code show the mechanics of creating a new parcel using the ICadastralMapEdit interface // there is no user interface to enter parcel record data, and the parcel line records are hard -coded // for the purposes of this sample code. The center of the map extent is used as the point of beginning // for the parcel. ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); if (pEd.EditState == esriEditState.esriStateNotEditing) { MessageBox.Show("Please start editing and try again."); return; } try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { pEd.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = "My New Plan"; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; } //3.b Add the plan to the job packet ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; pCadaPlan.AddPlan(pGSPlan); //4. Create Parcel ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; IGSParcel pNewGSParcel = new GSParcelClass(); //Make sure that any extended attributes on the parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //4a. Add the parcel to the packet. (do this before addlines) // - This will enable us to Acquire the parcel ID, // - Having the parcel attached to the packet allows InsertLine to function. pCadaParcel.AddParcel(pNewGSParcel); pNewGSParcel.Lot = "NewParcel"; pNewGSParcel.Type = 7; //4b. Set Plan (created above) IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName); pNewGSParcel.Plan = thePlan; //4c. Insert GSLines (from new) into GSParcel //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines. ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd; //Set up the initial start point, POB //This sample code starts from the middle of the map, and defines 4 lines of a parcel //The first course is a straight line, the other 3 courses are circular arcs IArea pArea = (IArea)ArcMap.Document.ActiveView.Extent; IPoint pPt1 = pArea.Centroid; IZAware pZAw = (IZAware)pPt1; pZAw.ZAware = true; pPt1.Z = 0; //defaulting to 0 //Convert the point into metric units, and get a new (in-mem) point id IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1); pCadaPoints.AddPoint(pGSPointFrom); int iID1 = pGSPointFrom.Id; int index = 0; //++++++++++++ Course 1 ++++++++++++++ int iID2 = -1; //From, Direction (NAz Radians), Distance (map's projection units), Radius IGSLine pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID1, 0, 100, 0, -1, -1, -1, true, out iID2); //Add the line to the new parcel if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 2 ++++++++++++++ int iID3 = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID2, (Math.PI / 2), 100, -80, -1, -1, -1, true, out iID3); if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 3 ++++++++++++++ int iID4 = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID3, Math.PI, 100, 80, -1, -1, -1, true, out iID4); if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //++++++++++++ Course 4 ++++++++++++++ //close back to point of beginning int i = -1; pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID4, (3 * Math.PI / 2), 100, 200, -1, -1, -1, false, out i); pGSLine.ToPoint = iID1; //closing the traverse back to the POB if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } //Add radial lines for circular curves pNewGSParcel.AddRadialLines(); // 4.e then set join=true on the parcel. pNewGSParcel.Joined = true; //let the packet know that a change has been made pCadPacketMan.SetPacketModified(true); //save the new parcel try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { pEd.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { pEd.StopOperation("New Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected override void OnClick() { ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); ICadastralFabric pCadFabric = pCadEd.CadastralFabric; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)pCadEd; IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; IParcelConstruction pTrav = pParcEditorMan.ParcelConstruction; //Test for the visibility of the parcel details window IDockableWindowManager pDocWinMgr = (IDockableWindowManager)ArcMap.Application; UID pUID = new UIDClass(); pUID.Value = "{28531B78-7C42-4785-805D-2A7EC8879EA1}";//ArcID.ParcelDetails IDockableWindow pParcelDet = pDocWinMgr.GetDockableWindow(pUID); if (!pParcelDet.IsVisible()) { MessageBox.Show("The Parcel Details window is not visible. \r\nThere is no data to save."); return; } //Make sure the lines grid is selected Utilities UTILS = new Utilities(); UTILS.SelectCadastralPropertyPage((ICadastralExtensionManager)pCadExtMan, "lines"); //test to make sure there is data there to be saved IParcelConstruction3 pConstr = (IParcelConstruction3)pTrav; IGSParcel pParcel = null; // try { pParcel = pTrav.Parcel; } catch (COMException err) { MessageBox.Show(err.Message + Environment.NewLine + "ERROR: Select a parcel or add lines to the grid. \r\nThere is no data to save. "); return; } //define the file that needs to be saved // Display .Net dialog for File saving. SaveFileDialog saveFileDialog = new SaveFileDialog(); // Set File Filter saveFileDialog.Filter = "Comma-delimited(*.csv)|*.csv|All Files|*.*"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; // Warn on overwrite saveFileDialog.OverwritePrompt = true; // Don't need to Show Help saveFileDialog.ShowHelp = false; // Set Dialog Title saveFileDialog.Title = "Save file"; // Display Open File Dialog if (saveFileDialog.ShowDialog() != DialogResult.OK) { saveFileDialog = null; return; } TextWriter tw = null; try { tw = new StreamWriter(saveFileDialog.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } try { IGSPlan pPlan = pTrav.Parcel.Plan; int iDF = (int)pPlan.DirectionFormat; switch (iDF) { case (int)esriDirectionType.esriDTNorthAzimuth: tw.WriteLine("DT,NA"); break; case (int)esriDirectionType.esriDTPolar: tw.WriteLine("DT,P"); break; case (int)esriDirectionType.esriDTQuadrantBearing: tw.WriteLine("DT,QB"); break; case (int)esriDirectionType.esriDTSouthAzimuth: tw.WriteLine("DT,SA"); break; default: tw.WriteLine("DT,NA"); break; } int iAU = (int)pPlan.AngleUnits; switch (iAU) { case (int)esriDirectionUnits.esriDUDecimalDegrees: tw.WriteLine("DU,DD"); break; case (int)esriDirectionUnits.esriDUDegreesMinutesSeconds: tw.WriteLine("DU,DMS"); break; case (int)esriDirectionUnits.esriDUGons: case (int)esriDirectionUnits.esriDUGradians: tw.WriteLine("DU,G"); break; case (int)esriDirectionUnits.esriDURadians: tw.WriteLine("DU,R"); break; default: tw.WriteLine("DU,R"); break; } ICadastralUnitConversion pUnitConv = new CadastralUnitConversionClass(); double dMetricConversion = pUnitConv.ConvertDouble(1, pPlan.DistanceUnits, esriCadastralDistanceUnits.esriCDUMeter); string sLU = Convert.ToString(dMetricConversion); tw.WriteLine("ToMetricFactor," + sLU); IEnumGSLines pGSLines = pTrav.GetLines(); pGSLines.Reset(); IGSLine pGSLine = null; IGSParcel pGSParcel = null; pGSLines.Next(ref pGSParcel, ref pGSLine); while (pGSLine != null) { int iFromPt = pGSLine.FromPoint; //from point int iToPt = pGSLine.ToPoint; //to point int iLineCat = (int)pGSLine.Category; //line category if (iLineCat == 4) { pGSLines.Next(ref pGSParcel, ref pGSLine); continue; //ignore radial lines } int iLineUserType = pGSLine.LineType; //line user type int iAccCat = pGSLine.Accuracy; //accuracy double dDistance = pGSLine.Distance; //distance double dChord = pGSLine.Distance; //chord double dRadius = pGSLine.Radius; //radius string sLineCat = Convert.ToString(iLineCat); string sLineUserType = Convert.ToString(iLineUserType); if (iLineUserType > 2140000000) { sLineUserType = ""; } string sAccCat = Convert.ToString(iAccCat); string sFromPt = Convert.ToString(iFromPt);//from point //following need conversion string sDirection = NorthAzRadians_2_DirectionString(pGSLine.Bearing, pPlan.DirectionFormat, pPlan.AngleUnits); //direction string sDistance = Convert.ToString(dDistance / dMetricConversion); //distance string sRadius = ""; string sChord = ""; if (dRadius != 123456789) { //circular curve sRadius = Convert.ToString(dRadius / dMetricConversion); //radius sChord = Convert.ToString(dDistance / dMetricConversion); //chord sDistance = ""; //distance is replaced with the chord distance } string sToPt = Convert.ToString(iToPt);//to point //write the line tw.WriteLine(sFromPt + "," + sDirection + "," + sDistance + "," + sRadius + "," + sChord + "," + sToPt + "," + sLineCat + "," + sLineUserType + "," + sAccCat); pGSLines.Next(ref pGSParcel, ref pGSLine); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tw.Close(); saveFileDialog = null; } }