private void OnSketchFinished()
        {
            ConfigUtil.type = "gas";
            IFeature pFeat = null;

            try
            {
                m_editor.StartOperation();

                pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true);

                bool splitOccured = GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false);

                try
                {
                    //Check to see if the source feature is the Junction FC, if so, and a edge was split, the junction will be created, do not create it as to not construct an orphaned junction
                    //https://github.com/Esri/local-government-desktop-addins/issues/239
                    bool            storeFeature = true;
                    INetworkFeature netFeature   = pFeat as INetworkFeature;
                    if (netFeature != null)
                    {
                        if (pFeat.Class.ObjectClassID == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.FeatureClassID &&
                            pFeat.Class.CLSID.Value.ToString() == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.CLSID.Value.ToString() &&
                            splitOccured == true)
                        {
                            storeFeature = false;
                        }
                    }
                    if (storeFeature == true)
                    {
                        pFeat.Store();
                    }
                    netFeature = null;
                    m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn"));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                    m_editor.AbortOperation();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.ToString());
                m_editor.AbortOperation();
            }
            finally
            {
                if (pFeat != null)
                {
                    (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null);
                }
                pFeat = null;
            }
        }
예제 #2
0
        private void ApplyDomainNull()
        {
            if (CheckRequirements())
            {
                try
                {
                    IFeatureLayer     featureLayer     = _utilities.FeatureLayer(cboFeatureLayer.Text);
                    IFeatureClass     featureClass     = featureLayer.FeatureClass;
                    IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
                    IEnumIDs          enumIDs          = featureSelection.SelectionSet.IDs;
                    int fieldIndex = _utilities.FindField(featureClass, cboField.Text);

                    enumIDs.Reset();

                    _editor.StartOperation();
                    int intOID = enumIDs.Next();

                    while (intOID != -1)
                    {
                        IFeature feature = featureClass.GetFeature(intOID);
                        if (feature != null)
                        {
                            feature.set_Value(fieldIndex, System.DBNull.Value);
                            feature.Store();
                        }
                        intOID = enumIDs.Next();
                    }

                    _activeView.Refresh();
                    _editor.StopOperation("Update Class Type");
                }
#pragma warning disable CS0168 // Variable is declared but never used
                catch (Exception ex)
#pragma warning restore CS0168 // Variable is declared but never used
                {
                    MessageBox.Show("Shapefiles Don't Accept Null");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Will take a given polygon and 'cookie cut' it into the chosen layer
        /// </summary>
        /// <param name="homesite_polygon"></param>
        private void StampPolygonIntoHomesiteLayer(IPolygon homesite_polygon)
        {
            try
            {
                IFeatureLayer featureLayer = _utilitiesArcMap.FeatureLayer(cbo_featureclass.Text);
                IFeatureClass featureClass = featureLayer.FeatureClass;

                _editor.StartOperation();

                ISpatialFilter spatialFilter = new SpatialFilter();
                spatialFilter.GeometryField = featureClass.ShapeFieldName;
                spatialFilter.Geometry      = homesite_polygon;
                spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
                IFeature       feature       = null;

                while ((feature = featureCursor.NextFeature()) != null)
                {
                    ITopologicalOperator topologicalOperator = feature.Shape as ITopologicalOperator;
                    IGeometry            geometry            = topologicalOperator.Difference(homesite_polygon);
                    IPolygon             polygon             = geometry as IPolygon;


                    IFeature newFeature = featureClass.CreateFeature();
                    newFeature.Shape = polygon as IPolygon;

                    // This caused a problem with memory allocation. It would not delete the orignal data.
                    ArrayList fields = _utilitiesArcMap.NumberFieldsWithDomain(featureLayer);

                    // Set the attribute back to the old ones.
                    foreach (string field in fields)
                    {
                        newFeature.set_Value(newFeature.Fields.FindField(field), feature.get_Value(feature.Fields.FindField(field)));
                    }


                    newFeature.Store();
                    feature.Delete();
                }

                IFeature homesite = featureClass.CreateFeature();
                homesite.Shape = homesite_polygon;
                homesite.Store();

                _editor.StopOperation("Homesite");
            } catch (Exception ex)
            {
                RS_Tools.Utilities.Utilities_MessageBox.ErrorBox(ex.Message, MB_TITLE);
            }
        }
예제 #4
0
        private void Delete(IFeatureLayer buildingsfeaturelayer)
        {
            //Get the editor
            _editor = GetEditorFromArcMap(_application as IMxApplication);
            if (_editor == null)
            {
                MessageBox.Show("Editor version of ArcMap required.", "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            if (_editor.EditState != esriEditState.esriStateEditing)
            {
                MessageBox.Show("Start an edit session first.", "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            IFeatureSelection featureselection = buildingsfeaturelayer as IFeatureSelection;

            if (featureselection.SelectionSet.Count == 0)
            {
                MessageBox.Show("Select at least one feature.", "Building Inspector", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            IFeatureClass featureclass = buildingsfeaturelayer.FeatureClass;
            IEnumIDs      enumIDs      = featureselection.SelectionSet.IDs;

            enumIDs.Reset();
            int intOID = enumIDs.Next();

            while (intOID != -1)
            {
                IFeature feature = featureclass.GetFeature(intOID);
                if (feature != null)
                {
                    _editor.StartOperation();
                    feature.Delete();
                    _editor.StopOperation("Status updated!" + feature.OID);
                    feature.Store();
                }
                intOID = enumIDs.Next();
            }

            _activeView.Refresh();
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            //calc distance between points
            double dbp = 0;

            if (rbNOP.Checked)
            {
                dbp = m_polyline.Length / (int.Parse(txtNOP.Text) + 1);
            }
            else
            {
                dbp = int.Parse(txtDist.Text);
            }

            m_editor.StartOperation();
            this.Cursor = Cursors.WaitCursor;

            //create points at distance between points up to total length
            for (double d = dbp; d < m_polyline.Length; d += dbp)
            {
                IConstructPoint contructionPoint = new PointClass();
                contructionPoint.ConstructAlong(m_polyline, esriSegmentExtension.esriNoExtension, d, false);
                CreatePoint(contructionPoint as IPoint);
            }

            //create points at start and end of sketch
            if (chkEnds.Checked)
            {
                CreatePoint(m_polyline.FromPoint);
                CreatePoint(m_polyline.ToPoint);
            }

            this.Cursor = Cursors.Default;
            m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtPtsAlongLine"));
            this.Close();
        }
        private void OnSketchFinished()
        {
            //send a space to hide the construction toolbar
            SendKeys.SendWait(" ");

            List <CreatePointWithReferenceDetails> configDetails = null;
            AddressReturnInfo retInfo = null;
            IPointCollection  pPnts   = null;
            List <IFeature>   pFeats  = null;
            IPoint            pPnt    = null;

            try
            {
                ((IMxDocument)ArcMap.Document).FocusMap.ClearSelection();

                Keys ModKey = Control.ModifierKeys;


                pPnts = m_edSketch.Geometry as IPointCollection;
                if (pPnts == null)
                {
                    return;
                }

                if (pPnts.PointCount < 2)
                {
                    return;
                }

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }

                int idxConfig = -1;
                // TODO: Add developer code here
                configDetails = ConfigUtil.GetCreatePointWithRefConfig();


                retInfo = AMGeometryTools.AddPointWithRef(ArcMap.Application, pPnts.get_Point(0), configDetails, ((IFeatureLayer)m_editor.CurrentTemplate.Layer), ref idxConfig);//,config,null,true,true);
                if (idxConfig == -1)
                {
                    return;
                }

                if (retInfo == null)
                {
                    return;
                }


                int targetAddFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressField);

                if (targetAddFieldIdx == -1)
                {
                    return;
                }

                int targetNameFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].StreetNameField);

                if (targetNameFieldIdx == -1)
                {
                    return;
                }

                int targetIDFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressPntKeyField);

                //if (targetIDFieldIdx == -1)
                //    return;

                //. .AddLaterals(m_application, ConfigUtil.GetAddLateralsConfig(), pFeat, false, true, false, false);

                //IFeature pFeat = null;
                pFeats = new List <IFeature>();

                for (int i = 1; i < pPnts.PointCount; i++)
                {
                    pFeats.Add(Globals.CreateFeature(pPnts.get_Point(i), m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true));
                    // pFeats.Add(pFeat);
                }

                foreach (IFeature pFeat in pFeats)
                {
                    if (retInfo.AddressDetails.StreetGeometry == null)
                    {
                        if (targetNameFieldIdx != -1)
                        {
                            pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.Messages);
                        }
                    }
                    else
                    {
                        bool rightSide = true;
                        pPnt = Globals.GetPointOnLine(pFeat.Shape as IPoint, retInfo.AddressDetails.StreetGeometry as IPolyline, 400, out rightSide);
                        if (rightSide)
                        {
                            pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.RightAddress);
                        }
                        else
                        {
                            pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.LeftAddress);
                        }
                        if (targetNameFieldIdx != -1)
                        {
                            pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.StreetName);
                        }

                        if (targetIDFieldIdx != -1)
                        {
                            pFeat.set_Value(targetIDFieldIdx, retInfo.AddressPointKey);
                        }
                        pFeat.Store();
                    }
                }
                pPnts = null;
                ((IMxDocument)ArcMap.Document).ActiveView.Refresh();
                try
                {
                    m_editor.StopOperation("Create Point with Reference");
                }
                catch
                {
                }
            }
            catch
            {
                configDetails = null;
                retInfo       = null;
                pPnts         = null;
                pFeats        = null;
                pPnt          = null;
                try
                {
                    m_editor.AbortOperation();
                }
                catch
                {
                }
            }
        }
        private void OnSketchFinished()
        {
            Keys ModKey = Control.ModifierKeys;

            // Send a shift-tab to hide the construction toolbar

            m_editor.StartOperation();
            IFeature        pFeat   = null;
            returnFeatArray pRetVal = null;

            if (ModKey == Keys.Shift)
            {
                pFeat   = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey);
                //   pFeat.Store();
            }
            else if (ModKey == (Keys.Control | Keys.Shift))
            {
                pFeat   = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey);
                // pFeat.Store();
            }
            else if (ModKey == Keys.Control)
            {
                pFeat   = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, true, true);
                pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey);
                //    pFeat.Store();
            }
            else
            {
                pFeat   = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, true, true);
                pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey);
            }
            pFeat.Store();
            foreach (IFeature featus in pRetVal.Features)
            {
                featus.Store();
            }

            if (pRetVal.Options == "DIGITIZED")
            {
                Globals.GetCommand("A4WaterUtilities_EstablishFlowDigitized", ArcMap.Application).Execute();
            }
            else if (pRetVal.Options == "ROLE")
            {
                Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
            }
            else if (pRetVal.Options == "Ancillary".ToUpper())
            {
                Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
            }
            else
            {
            }
            //            addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name);

            m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtAssetAndLat"));

            //IEnvelope pEnv = pFeat.Shape.Envelope;
            //pEnv.Expand(8, 8, true);

            (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null);
            //pEnv = null;
            pFeat   = null;
            pRetVal = null;
        }
        private void OnSketchFinished()
        {
            IFeature           pFeat       = null;
            ISegmentCollection pSegColl    = null;
            IEnumSegment       pESeg       = null;
            ISegment           testSegment = null;
            ISegmentCollection segColTest  = null;
            object             Missing     = null;

            try
            {
                // Send a shift-tab to hide the construction toolbar

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }
                bool twoPoint = false;
                (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection();
                List <IFeature> pLstFeat = null;
                if (Control.ModifierKeys == Keys.Control)
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat);
                }
                else
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat);
                }


                if (twoPoint)
                {
                    pSegColl = (ISegmentCollection)m_edSketch.Geometry;
                    pESeg    = pSegColl.EnumSegments;
                    pESeg.Reset();


                    int partIndex    = 0;
                    int segmentIndex = 0;

                    pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);

                    while (testSegment != null)
                    {
                        segColTest = new PolylineClass();

                        Missing = Type.Missing;
                        segColTest.AddSegment(testSegment, ref Missing, ref Missing);

                        pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                        pFeat.Store();
                        pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);
                    }
                }
                else
                {
                    pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                    pFeat.Store();
                }

                foreach (IFeature pFt in pLstFeat)
                {
                    pFt.Store();
                }
                pLstFeat = null;

                m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts"));
                (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
            }
            catch { }
            finally
            {
                pFeat       = null;
                pSegColl    = null;
                pESeg       = null;
                testSegment = null;
                segColTest  = null;
                Missing     = null;
            }
        }
        private void OnSketchFinished()
        {
            //m_editor.UndoOperation();
            IFeature  pFeat = null;
            IEnvelope pEnv  = null;

            try
            {
                m_editor.StartOperation();
                Globals.ClearSelected(ArcMap.Application, false, new List <esriGeometryType>()
                {
                    esriGeometryType.esriGeometryPoint
                });

                pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);

                //CreatePoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate);

                if (pFeat == null)
                {
                    return;
                }


                // addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name);

                //((IFeatureSelection)m_editor.CurrentTemplate.Layer).Clear();
                m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat);

                string resetFlow = AddLateralsFromPoint.AddLateralsFromMainPoint(ArcMap.Application, ConfigUtil.GetAddLateralsFromMainConfig(), pFeat, false, true, false);
                // m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat);


                m_editor.Display.Invalidate((ArcMap.Document as IMxDocument).ActiveView.Extent, true, (short)esriScreenCache.esriAllScreenCaches);

                pFeat.Store();

                (ArcMap.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, (ArcMap.Document as IMxDocument).ActiveView.Extent.Envelope);


                if (resetFlow.ToUpper() == "DIGITIZED")
                {
                    Globals.GetCommand("A4WaterUtilities_EstablishFlowDigitized", ArcMap.Application).Execute();
                }
                else if (resetFlow.ToUpper() == "ROLE")
                {
                    Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
                }
                else if (resetFlow.ToUpper() == "Ancillary".ToUpper())
                {
                    Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
                }
                else
                {
                }
                m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtAssetAndLat"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("ALT_1") + ex.Message);
                m_editor.AbortOperation();
            }
            finally
            {
                pFeat = null;
                pEnv  = 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);
            }
        }
        /// <summary>
        /// Creates given connections between cable and device
        /// </summary>
        /// <param name="cable">Cable</param>
        /// <param name="device">Device</param>
        /// <param name="units">Units to connect</param>
        /// <param name="isFromEnd">Is it the cable's from end?</param>
        /// <param name="portType">Input or Output?</param>
        /// <param name="isExistingOperation">Flag to control whether we need to wrap this in a new edit operation</param>
        /// <returns>Success</returns>
        public bool MakeConnections(FiberCableWrapper cable, DeviceWrapper device, Dictionary <int, int> units, bool isFromEnd, PortType portType, bool isExistingOperation)
        {
            bool success         = false;
            bool isOperationOpen = false;

            #region Validation
            if (null == cable)
            {
                throw new ArgumentNullException("cable");
            }

            if (null == device)
            {
                throw new ArgumentNullException("device");
            }

            if (null == units)
            {
                throw new ArgumentNullException("units");
            }

            if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState)
            {
                throw new InvalidOperationException("You must be editing to perform this operation");
            }
            #endregion

            if (!isExistingOperation)
            {
                _editor.StartOperation();
                isOperationOpen = true;
            }

            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureClass      deviceFtClass  = device.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass;
                ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass);
                if (null == deviceHasPorts)
                {
                    throw new Exception("Unable to get port relationship class.");
                }

                ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable;
                if (null == portTable)
                {
                    throw new Exception("Invalid destination on port relationship class.");
                }

                int    portIdIdx      = portTable.FindField(ConfigUtil.PortIdFieldName);
                int    fiberNumberIdx = portTable.FindField(ConfigUtil.ConnectedFiberFieldName);
                int    cableIdIdx     = portTable.FindField(ConfigUtil.ConnectedCableFieldName);
                int    isFromEndIdx   = portTable.FindField(ConfigUtil.ConnectedEndFieldName);
                string isFromEndValue = isFromEnd ? "T" : "F";

                Dictionary <int, int> portsAsKeys = units;
                if (PortType.Input == portType)
                {
                    portsAsKeys = new Dictionary <int, int>();
                    foreach (KeyValuePair <int, int> pair in units)
                    {
                        portsAsKeys[pair.Value] = pair.Key;
                    }
                }

                using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
                {
                    ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                    releaser.ManageLifetime(filter);

                    string format = "{0}='{1}' AND {2}='{3}'";
                    filter.WhereClause = string.Format(format,
                                                       deviceHasPorts.OriginForeignKey,
                                                       device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)),
                                                       ConfigUtil.PortTypeFieldName,
                                                       (PortType.Input == portType ? "1" : "2"));

                    // Non recylcing cursor since we are doing updates.
                    ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Update(filter, false);
                    releaser.ManageLifetime(portCursor);

                    ESRI.ArcGIS.Geodatabase.IRow portRow = portCursor.NextRow();
                    while (null != portRow)
                    {
                        object portIdObj = portRow.get_Value(portIdIdx);
                        if (DBNull.Value != portIdObj)
                        {
                            int portId = System.Convert.ToInt32(portIdObj);
                            if (portsAsKeys.ContainsKey(portId))
                            {
                                portRow.set_Value(cableIdIdx, cable.IPID);
                                portRow.set_Value(isFromEndIdx, isFromEndValue);
                                portRow.set_Value(fiberNumberIdx, portsAsKeys[portId]);
                                portRow.Store();
                            }
                        }

                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow);
                        portRow = portCursor.NextRow();
                    }

                    if (isOperationOpen)
                    {
                        _editor.StopOperation("Create Connections");
                        isOperationOpen = false;
                    }

                    success = true;
                }
            }
            catch (Exception ex)
            {
                if (isOperationOpen)
                {
                    _editor.AbortOperation();
                }

                success = false;

                throw new Exception("Save operation failed.");
            }

            return(success);
        }
예제 #12
0
        /// <summary>
        /// Will write a value when given: Feature, field_index, valueobject
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="field_index"></param>
        /// <param name="valueobject"></param>
        public void WriteValue(IEditor3 editor, IFeature feature, int field_index, object valueobject)
        {
            string valueobjectstring = valueobject.ToString();

            if (field_index > -1)
            {
                IField field = feature.Fields.get_Field(field_index);
                editor.StartOperation();
                switch (field.Type)
                {
                case esriFieldType.esriFieldTypeDate:
                    DateTime datetime = Convert.ToDateTime(valueobjectstring);
                    string   year     = datetime.Year.ToString();
                    string   month    = datetime.Month.ToString();
                    string   day      = datetime.Day.ToString();
                    valueobjectstring = month + "/" + day + "/" + year;
                    feature.set_Value(field_index, valueobjectstring);
                    break;

                case esriFieldType.esriFieldTypeDouble:
                    double valueobjectdouble = Convert.ToDouble(valueobjectstring);
                    System.Math.Round(valueobjectdouble, 8);
                    feature.set_Value(field_index, valueobjectdouble);
                    break;

                case esriFieldType.esriFieldTypeGeometry:
                    break;

                case esriFieldType.esriFieldTypeGlobalID:
                    if (field.Length > valueobjectstring.Length)
                    {
                        feature.set_Value(field_index, valueobject);
                    }
                    break;

                case esriFieldType.esriFieldTypeGUID:
                    if (field.Length > valueobjectstring.Length)
                    {
                        feature.set_Value(field_index, valueobject);
                    }
                    break;

                case esriFieldType.esriFieldTypeInteger:
                    feature.set_Value(field_index, Convert.ToInt64(valueobject));
                    break;

                case esriFieldType.esriFieldTypeOID:
                    if (field.Length > valueobjectstring.Length)
                    {
                        feature.set_Value(field_index, Convert.ToInt64(valueobject));
                    }
                    break;

                case esriFieldType.esriFieldTypeRaster:
                    break;

                case esriFieldType.esriFieldTypeSingle:
                    if (field.Length > valueobjectstring.Length)
                    {
                        feature.set_Value(field_index, Convert.ToSingle(valueobject));
                    }
                    break;

                case esriFieldType.esriFieldTypeSmallInteger:
                    if (field.Length > valueobjectstring.Length)
                    {
                        feature.set_Value(field_index, Convert.ToInt16(valueobject));
                    }
                    break;

                case esriFieldType.esriFieldTypeString:
                    if (field.Length < valueobjectstring.Length)
                    {
                        valueobjectstring = valueobjectstring.Substring(0, field.Length - 1);
                    }
                    feature.set_Value(field_index, valueobject.ToString());
                    break;

                case esriFieldType.esriFieldTypeXML:
                    break;
                }
                editor.StopOperation("Status updated!" + feature.OID);
                feature.Store();
            }
        }
예제 #13
0
        private void OnSketchFinished()
        {
            ConfigUtil.type = "gas";
            //m_editor.UndoOperation();
            IFeature  pFeat = null;
            IEnvelope pEnv  = null;

            try
            {
                m_editor.StartOperation();
                Globals.ClearSelected(ArcMap.Application, false, new List <esriGeometryType>()
                {
                    esriGeometryType.esriGeometryPoint
                });

                pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);

                //CreatePoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate);

                if (pFeat == null)
                {
                    return;
                }


                // addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name);

                //((IFeatureSelection)m_editor.CurrentTemplate.Layer).Clear();
                m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat);

                List <MergeSplitGeoNetFeatures> m_Config = null;
                m_Config = ConfigUtil.GetMergeSplitConfig();

                string resetFlow = AddLateralsLinesCmds.AddLaterals(ArcMap.Application, ConfigUtil.GetAddLateralsConfig(), pFeat, false, true, false, false, m_Config[0]);
                // m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat);


                m_editor.Display.Invalidate((ArcMap.Document as IMxDocument).ActiveView.Extent, true, (short)esriScreenCache.esriAllScreenCaches);

                pFeat.Store();

                (ArcMap.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, (ArcMap.Document as IMxDocument).ActiveView.Extent.Envelope);


                if (resetFlow.ToUpper() == "DIGITIZED")
                {
                    Globals.GetCommand("A4GasUtilities_EstablishFlowDigitized", ArcMap.Application).Execute();
                }
                else if (resetFlow.ToUpper() == "ROLE")
                {
                    Globals.GetCommand("A4GasUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
                }
                else if (resetFlow.ToUpper() == "Ancillary".ToUpper())
                {
                    Globals.GetCommand("A4GasUtilities_EstablishFlowAncillary", ArcMap.Application).Execute();
                }
                else
                {
                }
                m_editor.StopOperation("Create asset and lateral");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in the Add Lateral Tools: " + ex.ToString());
                m_editor.AbortOperation();
            }
            finally
            {
                pFeat = null;
                pEnv  = null;
            }
        }
        private void OnSketchFinished()
        {
            ConfigUtil.type = "gas";
            IFeature           pFeat       = null;
            ISegmentCollection pSegColl    = null;
            IEnumSegment       pESeg       = null;
            ISegment           testSegment = null;
            ISegmentCollection segColTest  = null;
            object             Missing     = null;

            try
            {
                // Send a shift-tab to hide the construction toolbar

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }
                bool twoPoint = false;
                (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection();
                List <IFeature> pLstFeat   = null;
                string          storeOrder = "";
                if (Control.ModifierKeys == Keys.Control)
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat, out storeOrder);
                }
                else
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat, out storeOrder);
                }
                if (storeOrder == null)
                {
                    storeOrder = "Points";
                }
                if (storeOrder.ToUpper() == "points".ToUpper())
                {
                    foreach (IFeature pFt in pLstFeat)
                    {
                        try
                        {
                            pFt.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                    }
                }
                if (twoPoint)
                {
                    pSegColl = (ISegmentCollection)m_edSketch.Geometry;
                    pESeg    = pSegColl.EnumSegments;
                    pESeg.Reset();


                    int partIndex    = 0;
                    int segmentIndex = 0;

                    pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);

                    while (testSegment != null)
                    {
                        segColTest = new PolylineClass();

                        Missing = Type.Missing;
                        segColTest.AddSegment(testSegment, ref Missing, ref Missing);

                        pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                        try
                        {
                            pFeat.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                        pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);
                    }
                }
                else
                {
                    pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                    pFeat.Store();
                }

                if (storeOrder.ToUpper() != "points".ToUpper())
                {
                    foreach (IFeature pFt in pLstFeat)
                    {
                        try
                        {
                            pFt.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                    }
                }

                pLstFeat = null;

                m_editor.StopOperation("Create line with points");
            }

            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts") + "\n" + ex.ToString());
                m_editor.AbortOperation();
            }
            finally
            {
                pFeat       = null;
                pSegColl    = null;
                pESeg       = null;
                testSegment = null;
                segColTest  = null;
                Missing     = null;
            }
        }
        protected override void OnClick()
        {
            //
            //  TODO: Sample code showing how to access button host
            //
            ArcMap.Application.CurrentTool = null;

            IMap map = ArcMap.Document.ActivatedView.FocusMap;

            //Check to make sure the map contains a layer
            if (map.LayerCount < 1)
            {
                MessageBox.Show("Must have a layer in your map...");
                return;
            }

            //Get the selected layer
            ILayer selectedLayer = ArcMap.Document.SelectedLayer;

            //Checl that there is a selected layer in the table of contents
            if (selectedLayer == null)
            {
                MessageBox.Show("You must have a layer highlighted in the table of contents.");
                return;
            }
            //Check that the selected layer is a featuer layer
            if (!(selectedLayer is IFeatureLayer))
            {
                MessageBox.Show("The highlighted layer in the TOC must be a feature layer.");
                return;
            }

            IFeatureLayer featureLayer = selectedLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            //Check that the features shape is a line
            if (featureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
            {
                MessageBox.Show("The highlighted layer in the TOC must be a polyline.");
                return;
            }
            //Check that features are selected in the table of contents
            IFeatureSelection featureSelection = featureLayer as IFeatureSelection;

            if (featureSelection.SelectionSet.Count < 1)
            {
                MessageBox.Show("The highlighted layer in the TOC must have some features selected.");
                return;
            }

            ISelectionSet2 selectionSet = featureSelection.SelectionSet as ISelectionSet2;

            int streetFieldIndex = featureClass.FindField(sStreetFldName);

            //Check that the street name exists in the table.
            if (streetFieldIndex < 0)
            {
                MessageBox.Show(sStreetFldName + " was not found in highlighted layer.");
                return;
            }

            int crossA = featureClass.FindField(sCrossAFldName);

            //Check that the cross from field was found in the table
            if (crossA < 1)
            {
                MessageBox.Show(sCrossAFldName + " was not found in highlighted layer.");
                return;
            }
            //Check that the cross to field was found in the table
            int crossB = featureClass.FindField(sCrossBFldName);

            if (crossB < 1)
            {
                MessageBox.Show(sCrossBFldName + " was not found in highlighted layer.");
                return;
            }
            //Find the editor
            UID id = new UID();

            id.Value = "esriEditor.Editor";

            IApplication application     = ArcMap.Application;
            IEditor3     editorExtension = application.FindExtensionByCLSID(id) as IEditor3;

            //Make sure that an active edit session is happening
            if (!(editorExtension.EditState == esriEditState.esriStateEditing))
            {
                MessageBox.Show("Must be in an edit session");
                return;
            }
            //Update the status bar
            application.StatusBar.Message[0] = "Populating Cross Streets...";
            editorExtension.StartOperation();
            IQueryFilter queryFilter = new QueryFilter();

            queryFilter.AddField(sCrossAFldName);
            queryFilter.AddField(sCrossBFldName);
            ICursor featureCursor;

            selectionSet.Update(null, false, out featureCursor);
            IFeature feature = featureCursor.NextRow() as IFeature;
            string   total   = selectionSet.Count.ToString();
            int      count   = 0;

            //Iterate through the features until all of the selected ones have been tested
            do
            {
                count++;
                application.StatusBar.Message[0] = "Populating cross streets... " + count.ToString() + " of " + total;
                string    street   = feature.Value[streetFieldIndex] as string;
                IGeometry geometry = feature.Shape;
                ICurve    curve    = geometry as ICurve;
                IPoint    point    = curve.FromPoint;
                string    sCrossA  = FindStreets(point, featureClass, streetFieldIndex, street, sJoin);
                point = curve.ToPoint;
                string sCrossB = FindStreets(point, featureClass, streetFieldIndex, street, sJoin);

                feature.Value[crossA] = sCrossA;
                feature.Value[crossB] = sCrossB;
                IRow row = feature;

                featureCursor.UpdateRow(feature);

                feature = featureCursor.NextRow() as IFeature;
            } while (!(feature == null));
            editorExtension.StopOperation("Populate Cross Streets");
        }