コード例 #1
0
 /// <summary>
 /// 删除要素类
 /// </summary>
 /// <param name="featureWorkspace"></param>
 /// <param name="featureClassName"></param>
 public static void DelAeFeatureclass(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace, string featureClassName)
 {
     try
     {
         ESRI.ArcGIS.Geodatabase.IFeatureClass tmpfeatureclass = featureWorkspace.OpenFeatureClass(featureClassName);
         ESRI.ArcGIS.Geodatabase.IDataset      set             = tmpfeatureclass as ESRI.ArcGIS.Geodatabase.IDataset;
         set.CanDelete();
         set.Delete();
     }
     catch
     { }
 }
コード例 #2
0
 /// <summary>
 /// 将workspace 转换为 IWorkspaceName
 /// </summary>
 /// <param name="pWs"></param>
 /// <returns></returns>
 private static ESRI.ArcGIS.Geodatabase.IWorkspaceName GetWorkspaceName(ESRI.ArcGIS.Geodatabase.IWorkspace pWs)
 {
     try
     {
         ESRI.ArcGIS.Geodatabase.IDataset pDs = pWs as ESRI.ArcGIS.Geodatabase.IDataset;
         return((ESRI.ArcGIS.Geodatabase.IWorkspaceName)pDs.FullName);;
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
コード例 #3
0
        /// <summary>
        /// Finds the Device to Port relationship class for a given port table
        /// </summary>
        /// <param name="deviceClass">port table</param>
        /// <returns>ESRI.ArcGIS.Geodatabase.IRelationshipClass</returns>
        public static ESRI.ArcGIS.Geodatabase.IRelationshipClass GetDeviceRelationship(ESRI.ArcGIS.Geodatabase.ITable portTable)
        {
            // TODO: Currently returns the first relationship class found whose name ends with "Ports". Should probably make the relationship classes part of the configuration

            ESRI.ArcGIS.Geodatabase.IRelationshipClass result = null;

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

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IEnumRelationshipClass relClasses = ((ESRI.ArcGIS.Geodatabase.IObjectClass)portTable).get_RelationshipClasses(ESRI.ArcGIS.Geodatabase.esriRelRole.esriRelRoleDestination);
                releaser.ManageLifetime(relClasses);

                relClasses.Reset();
                result = relClasses.Next();

                while (null != result)
                {
                    ESRI.ArcGIS.Geodatabase.IDataset relationshipDataset = result as ESRI.ArcGIS.Geodatabase.IDataset;

                    if (relationshipDataset.Name.EndsWith("Ports", StringComparison.CurrentCultureIgnoreCase))
                    {
                        break;
                    }

                    result = relClasses.Next();
                }
            }

            if (null == result)
            {
                throw new Exception("Relationship class from device to port was not found.");
            }

            return(result);
        }
コード例 #4
0
        protected override void editor_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            // Check for bad inputs
            ESRI.ArcGIS.Geodatabase.IFeature feature = obj as ESRI.ArcGIS.Geodatabase.IFeature;
            if (feature == null || feature.Class == null)
            {
                return;
            }

            // Work out type of feature
            ESRI.ArcGIS.Geodatabase.IDataset dataset = (ESRI.ArcGIS.Geodatabase.IDataset)feature.Class;
            string tableName = GdbUtils.ParseTableName(dataset);

            // -----------------------------
            // Fiber
            // -----------------------------
            if (0 == string.Compare(ConfigUtil.FiberCableFtClassName, tableName, true))
            {
                try
                {
                    //FiberCableConfiguration cf =
                    //    ConfigUtil.FiberCableConfigurationFromDisplayName(listView1.SelectedItems[0].Text);
                    if (_fiberConfig != null)
                    {
                        ConfigureCable(feature, _fiberConfig, true);
                    }
                }
                catch (Exception ex)
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Failed to configure cable.", ex.Message);

                    string message = "Failed to configure cable:" + System.Environment.NewLine +
                                     ex.Message;
                    MessageBox.Show(message, "Configure Fiber Cable", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 字段匹配
        /// </summary>
        /// <param name="sourceFeatClass"></param>
        /// <param name="targetFeatClass"></param>
        /// <param name="FieldPair"></param>
        /// <returns></returns>
        public static ESRI.ArcGIS.Geoprocessing.IGPFieldMapping GetGPFieldMapping(ESRI.ArcGIS.Geodatabase.IFeatureClass sourceFeatClass,
                                                                                  ESRI.ArcGIS.Geodatabase.IFeatureClass targetFeatClass, string FieldPair)
        {
            ESRI.ArcGIS.Geodatabase.IDataset       sourceDataset = sourceFeatClass as ESRI.ArcGIS.Geodatabase.IDataset;
            ESRI.ArcGIS.esriSystem.IName           pName         = sourceDataset.FullName;
            ESRI.ArcGIS.Geoprocessing.IGPUtilities gputilities   = new ESRI.ArcGIS.Geoprocessing.GPUtilitiesClass();
            ESRI.ArcGIS.Geodatabase.IDETable       inputTableA   = (ESRI.ArcGIS.Geodatabase.IDETable)gputilities.MakeDataElementFromNameObject(pName);

            ESRI.ArcGIS.esriSystem.IArray inputtables = new ESRI.ArcGIS.esriSystem.ArrayClass();
            inputtables.Add(inputTableA);

            ESRI.ArcGIS.Geoprocessing.IGPFieldMapping pGPFieldMapping = new ESRI.ArcGIS.Geoprocessing.GPFieldMappingClass();
            pGPFieldMapping.Initialize(inputtables, null);

            string[] sFieldPairs = FieldPair.Split(';');
            if (sFieldPairs == null)
            {
                return(null);
            }

            foreach (string sFieldPair in sFieldPairs)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(sFieldPair))
                    {
                        continue;
                    }
                    string[] sourceAndtarget = sFieldPair.Split(',');
                    if (sourceAndtarget == null || sourceAndtarget.Length <= 0)
                    {
                        continue;
                    }
                    string targetFieldName = sourceAndtarget[0];
                    string sourceFieldName = sourceAndtarget[1];
                    int    sourceindex     = sourceFeatClass.FindField(sourceFieldName);
                    int    targetindex     = targetFeatClass.FindField(targetFieldName);
                    if (sourceindex < 0 || targetindex < 0)
                    {
                        continue;
                    }

                    ESRI.ArcGIS.Geoprocessing.IGPFieldMap trackid = new ESRI.ArcGIS.Geoprocessing.GPFieldMapClass();
                    trackid.OutputField = targetFeatClass.Fields.get_Field(targetFeatClass.FindField(targetFieldName));
                    trackid.MergeRule   = ESRI.ArcGIS.Geoprocessing.esriGPFieldMapMergeRule.esriGPFieldMapMergeRuleLast;
                    int fieldmap_index = pGPFieldMapping.FindFieldMap(sourceFieldName);
                    ESRI.ArcGIS.Geoprocessing.IGPFieldMap stfid_fieldmap = pGPFieldMapping.GetFieldMap(fieldmap_index);
                    int field_index = stfid_fieldmap.FindInputField(inputTableA, sourceFieldName);
                    ESRI.ArcGIS.Geodatabase.IField inputField = stfid_fieldmap.GetField(field_index);
                    //if (inputField.Name == "STLLZ")
                    //{
                    //    ESRI.ArcGIS.Geodatabase.IField field = targetFeatClass.Fields.get_Field(targetFeatClass.FindField(targetFieldName));
                    //}
                    trackid.AddInputField(inputTableA, inputField, -1, -1);
                    pGPFieldMapping.AddFieldMap(trackid);
                }
                catch (Exception ex)
                {
                }
            }

            return(pGPFieldMapping);
        }
コード例 #6
0
        void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove)
        {
            if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
            {
                return;
            }

            ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset;

            //  Remove only elements contained in a specific Schematic dataset
            if (esriData.Name != SampleDatasetName)
            {
                return;
            }
            //  Remove only elements contained in a specific type of diagram
            if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName)
            {
                return;
            }

            canRemove = false;
            // can't remove SubStation
            if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation")
            {
                return;
            }

            ISchematicDiagramClass schemDiagramClass;

            schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass;

            //  For this specific diagram type, we retrieve the datasource
            //  and the tables where the elements are stored
            ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource;

            string tableName = "";

            switch (inMemoryFeature.SchematicElementClass.SchematicElementType)
            {
            case esriSchematicElementType.esriSchematicNodeType:
                tableName = TableNameNodes;
                break;

            case esriSchematicElementType.esriSchematicLinkType:
                tableName = TableNameLinks;
                break;

            case esriSchematicElementType.esriSchematicDrawingType:
                return;

                break;
            }

            // Retrieve Feature Workspace
            ESRI.ArcGIS.Geodatabase.IWorkspace        esriWorkspace        = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace;

            // Get Attributes values
            ISchematicAttributeContainer schemAttribCont       = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass;
            ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent;

            if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) ||
                 !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null)))
            {
                int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID);
                int OID      = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer);
                //Get table and row
                ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName);
                ESRI.ArcGIS.Geodatabase.IRow   esriRow   = esriTable.GetRow(OID);

                //  When the row is identified in the table, it is deleted and
                //  the CanRemove returns True so that the associated
                //  schematic element is graphically removed from the active diagram
                if (!(esriRow == null))
                {
                    esriRow.Delete();
                    canRemove = true;
                }
            }
        }
コード例 #7
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add PolygonsDifference.OnMouseDown implementation
            if (Button != (int)Keys.LButton)
            {
                return;
            }
            ILayer layer = m_engineEditor.TargetLayer;

            if (layer == null)
            {
                return;
            }
            m_activeView = m_hookHelper.ActiveView;
            m_map        = m_hookHelper.FocusMap;
            ESRI.ArcGIS.Geometry.IPoint pPoint = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            ISelectionEnvironment       pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelWithin;

            m_map.SelectByShape(pPoint as ESRI.ArcGIS.Geometry.IGeometry, pSelectionEnvironment, false);
            //if (m_map.SelectionCount != 2)
            //{
            //    MessageBox.Show("选择的多边形个数应该为2!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent);
            ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature  = m_map.FeatureSelection as ESRI.ArcGIS.Geodatabase.IEnumFeature;
            ESRI.ArcGIS.Geodatabase.IFeature     firstFeature  = pEnumFeature.Next();
            ESRI.ArcGIS.Geodatabase.IFeature     secondFeature = pEnumFeature.Next();
            bool firstPolygonIsLarge = false;

            ESRI.ArcGIS.Geometry.IGeometry            pGeometry            = null;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp1              = firstFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp2              = secondFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.ITopologicalOperator pTopologicalOperator = null;
            if (pRelOp1.Contains(secondFeature.Shape))
            {
                pTopologicalOperator = firstFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(secondFeature.Shape);
                firstPolygonIsLarge  = true;
            }
            else if (pRelOp2.Contains(firstFeature.Shape))
            {
                pTopologicalOperator = secondFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(firstFeature.Shape);
                firstPolygonIsLarge  = false;
            }
            else
            {
                return;
            }
            bool         deleteInteriorPolygon = false;
            DialogResult pDialogResult         = MessageBox.Show("是否要删除内多边形?", "操作提示", MessageBoxButtons.YesNo);

            if (pDialogResult == DialogResult.Yes)
            {
                deleteInteriorPolygon = true;
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass  featureClass  = firstFeature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass;
            ESRI.ArcGIS.Geodatabase.IDataset       dataset       = featureClass as ESRI.ArcGIS.Geodatabase.IDataset;
            ESRI.ArcGIS.Geodatabase.IWorkspaceEdit workspaceEdit = dataset.Workspace as ESRI.ArcGIS.Geodatabase.IWorkspaceEdit;
            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }
            workspaceEdit.StartEditOperation();
            if (firstPolygonIsLarge)
            {
                firstFeature.Shape = pGeometry;
                firstFeature.Store();
                if (deleteInteriorPolygon)
                {
                    secondFeature.Delete();
                }
            }
            else
            {
                secondFeature.Shape = pGeometry;
                secondFeature.Store();
                if (deleteInteriorPolygon)
                {
                    firstFeature.Delete();
                }
            }
            workspaceEdit.StopEditOperation();
            m_map.ClearSelection();
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_Mapcontrol.CurrentTool = null;
        }