Пример #1
0
        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 btnRun_Click(object sender, EventArgs e)
        {
            double dConvTol     = 0.003;
            int    iRepeatCount = 2;
            double dMaxShift    = 0;

            double dVal = 0;

            if (Double.TryParse(this.txtMainDistResReport.Text, out dVal))
            {
                //write to registry
                Utilities FabUTILS = new Utilities();
                string    sVersion = FabUTILS.GetDesktopVersionFromRegistry();
                FabUTILS.WriteToRegistry(RegistryHive.CurrentUser,
                                         "Software\\ESRI\\Desktop" + sVersion + "\\ArcMap\\Cadastral\\AddIn.ParcelEditHelper",
                                         "LSADistanceToleranceReport", this.txtMainDistResReport.Text, true);
                FabUTILS = null;
            }

            bool   bAdjResult = true;
            string sSummary   = "";

            #region Setup Adjustment & Verify that there's enough information

            ICadastralPacketManager pCadastralPacketManager = null;
            ICadastralAdjustment    pCadAdj     = null;
            ICadastralAdjustment3   pCadAdjEx   = null;
            ICadastralMapEdit       pCadMapEdit = null;

            LoadValuesFromRegistry();

            UID pUID = new UIDClass();
            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralEditor pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralFabric pCadFabric = pCadEd.CadastralFabric;

            pCadastralPacketManager = (ICadastralPacketManager)pCadEd;
            bool open = pCadastralPacketManager.PacketOpen;

            ISelectionSet     pBeforeSS        = null;
            IFeatureSelection pParcelSelection = null;

            if (!open)
            {
                ICadastralSelection pSelection = (ICadastralSelection)pCadEd;
                IEnumGSParcels      pParcels   = pSelection.SelectedParcels;
                IEnumCEParcels      pCEParcels = (IEnumCEParcels)pParcels;
                if (pCEParcels != null)
                {
                    long count = pCEParcels.Count;
                    if (count == 0)
                    {
                        MessageBox.Show("There are no parcels selected to adjust." + Environment.NewLine
                                        + "Please select parcels and try again.", "Fabric Adjustment");
                        return;
                    }
                }

                ICadastralFabricLayer pCFLayer = pCadEd.CadastralFabricLayer;
                if (pCFLayer != null)
                {
                    IFeatureLayer pParcelLayer = pCFLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRParcels);
                    pParcelSelection = (IFeatureSelection)pParcelLayer;
                    if (pParcelSelection != null)
                    {
                        pBeforeSS = pParcelSelection.SelectionSet;
                    }
                }
            }

            pCadMapEdit = (ICadastralMapEdit)pCadEd;
            pCadMapEdit.StartMapEdit(esriMapEditType.esriMEParcelSelection, "Fabric Adjustment", false);

            ICadastralPacket pCadastralPacket = pCadastralPacketManager.JobPacket;
            int cpCount = 0;

            ICadastralControlPoints pCPts = (ICadastralControlPoints)pCadastralPacket;
            if (pCPts != null)
            {
                IGeometry            pGeom    = null;
                IEnumGSControlPoints pEnumCPs = pCPts.GetControlPoints(pGeom);
                pEnumCPs.Reset();
                IGSControlPoint pCP;
                if (pEnumCPs != null)
                {
                    pCP = pEnumCPs.Next();
                    while ((pCP != null) && (cpCount < 2))
                    {
                        if (pCP.Active)
                        {
                            cpCount++;
                        }
                    }
                }
            }

            if (cpCount < 2)
            {
                MessageBox.Show("Please make sure that at least 2 control points are" +
                                Environment.NewLine + "attached to the selected parcels.", "Fabric Adjustment");
                return;
            }
            pCadAdj   = (ICadastralAdjustment)pCadastralPacket;
            pCadAdjEx = (ICadastralAdjustment3)pCadastralPacket;
            ApplyAdjustmentSettings(pCadAdj, pCadAdjEx);

            #endregion

            double dHighestMaxShift = 0;

            //// Change display text depending on count
            //string itemText = count > 1 ? "items" : "item";

            for (int i = 1; i <= iRepeatCount; i++)
            {
                if (!RunAdjustment(pCadastralPacketManager, pCadAdj, pCadAdjEx, i, out dMaxShift, out sSummary))
                {
                    bAdjResult = false;
                    break;
                }
                if (dHighestMaxShift > dMaxShift)
                {
                    dHighestMaxShift = dMaxShift;
                }

                pCadAdj.AcceptAdjustment();
                if (dMaxShift < dConvTol)
                {
                    break;
                }
            }

            if (bAdjResult)
            {
                lblAdjResult.Text = "Adjustment Complete";
            }
            else
            {
                lblAdjResult.Text = "Adjustment Failed";
            }

            lblAdjResult.Visible = true;

            dlgAdjustmentResults AdjResults = new dlgAdjustmentResults();
            AdjResults.txtReport.Text = sSummary;

            //Display the dialog
            DialogResult pDialogResult = AdjResults.ShowDialog();
            if (pDialogResult != DialogResult.OK)
            {
                AdjResults = null;
                pCadMapEdit.StopMapEdit(false);
            }
            else
            {
                pCadMapEdit.StopMapEdit(true);
            }

            pParcelSelection.SelectionSet = pBeforeSS;

            Utilities FabUTILS2 = new Utilities();
            FabUTILS2.RefreshFabricLayers(ArcMap.Document.FocusMap, pCadFabric);
            FabUTILS2 = null;
        }
        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);
            }
        }
Пример #4
0
        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);
            }
        }