コード例 #1
0
        // ArcGIS Snippet Title:
        // Loop Through Layers of Specific UID
        //
        // Long Description:
        // Stub code to loop through layers in a map where a specific UID is supplied.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.System
        // System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Stub code to loop through layers in a map where a specific UID is supplied.</summary>
        ///
        ///<param name="map">An IMap interface in which the layers reside.</param>
        ///<param name="layerCLSID">A System.String that is the layer GUID type. For example: "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" is the IGeoFeatureLayer.</param>
        ///
        ///<remarks>In order of the code to be useful the user needs to write their own code to use the layer in the TODO section.
        ///
        /// The different layer GUID's and Interface's are:
        /// "{AD88322D-533D-4E36-A5C9-1B109AF7A346}" = IACFeatureLayer
        /// "{74E45211-DFE6-11D3-9FF7-00C04F6BC6A5}" = IACLayer
        /// "{495C0E2C-D51D-4ED4-9FC1-FA04AB93568D}" = IACImageLayer
        /// "{65BD02AC-1CAD-462A-A524-3F17E9D85432}" = IACAcetateLayer
        /// "{4AEDC069-B599-424B-A374-49602ABAD308}" = IAnnotationLayer
        /// "{DBCA59AC-6771-4408-8F48-C7D53389440C}" = IAnnotationSublayer
        /// "{E299ADBC-A5C3-11D2-9B10-00C04FA33299}" = ICadLayer
        /// "{7F1AB670-5CA9-44D1-B42D-12AA868FC757}" = ICadastralFabricLayer
        /// "{BA119BC4-939A-11D2-A2F4-080009B6F22B}" = ICompositeLayer
        /// "{9646BB82-9512-11D2-A2F6-080009B6F22B}" = ICompositeGraphicsLayer
        /// "{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E}" = ICoverageAnnotationLayer
        /// "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" = IDataLayer
        /// "{0737082E-958E-11D4-80ED-00C04F601565}" = IDimensionLayer
        /// "{48E56B3F-EC3A-11D2-9F5C-00C04F6BC6A5}" = IFDOGraphicsLayer
        /// "{40A9E885-5533-11D0-98BE-00805F7CED21}" = IFeatureLayer
        /// "{605BC37A-15E9-40A0-90FB-DE4CC376838C}" = IGdbRasterCatalogLayer
        /// "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" = IGeoFeatureLayer
        /// "{34B2EF81-F4AC-11D1-A245-080009B6F22B}" = IGraphicsLayer
        /// "{EDAD6644-1810-11D1-86AE-0000F8751720}" = IGroupLayer
        /// "{D090AA89-C2F1-11D3-9FEF-00C04F6BC6A5}" = IIMSSubLayer
        /// "{DC8505FF-D521-11D3-9FF4-00C04F6BC6A5}" = IIMAMapLayer
        /// "{34C20002-4D3C-11D0-92D8-00805F7C28B0}" = ILayer
        /// "{E9B56157-7EB7-4DB3-9958-AFBF3B5E1470}" = IMapServerLayer
        /// "{B059B902-5C7A-4287-982E-EF0BC77C6AAB}" = IMapServerSublayer
        /// "{82870538-E09E-42C0-9228-CBCB244B91BA}" = INetworkLayer
        /// "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}" = IRasterLayer
        /// "{AF9930F0-F61E-11D3-8D6C-00C04F5B87B2}" = IRasterCatalogLayer
        /// "{FCEFF094-8E6A-4972-9BB4-429C71B07289}" = ITemporaryLayer
        /// "{5A0F220D-614F-4C72-AFF2-7EA0BE2C8513}" = ITerrainLayer
        /// "{FE308F36-BDCA-11D1-A523-0000F8774F0F}" = ITinLayer
        /// "{FB6337E3-610A-4BC2-9142-760D954C22EB}" = ITopologyLayer
        /// "{005F592A-327B-44A4-AEEB-409D2F866F47}" = IWMSLayer
        /// "{D43D9A73-FF6C-4A19-B36A-D7ECBE61962A}" = IWMSGroupLayer
        /// "{8C19B114-1168-41A3-9E14-FC30CA5A4E9D}" = IWMSMapLayer
        ///</remarks>
        public void LoopThroughLayersOfSpecificUID(ESRI.ArcGIS.Carto.IMap map, System.String layerCLSID)
        {
            if (map == null || layerCLSID == null)
            {
                return;
            }
            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = layerCLSID; // Example: "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" = IGeoFeatureLayer
            try
            {
                ESRI.ArcGIS.Carto.IEnumLayer enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)(uid)), true); // Explicit Cast
                enumLayer.Reset();
                ESRI.ArcGIS.Carto.ILayer layer = enumLayer.Next();
                cboLayers.Items.Clear();
                lstLayers.Clear();
                while (!(layer == null))
                {
                    IFeatureLayer featureLayer = (IFeatureLayer)layer;
                    if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        cboLayers.Items.Add(layer.Name);
                        lstLayers.Add(layer);
                    }
                    layer = enumLayer.Next();
                }
                if (cboLayers.Items.Count > 0)
                {
                    cboLayers.SelectedIndex = 0;
                }
            }
            catch (System.Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show("No layers of type: " + uid.Value.ToString);
            }
        }
コード例 #2
0
        /// <summary>
        /// Finds the first layer on the focus map whose source feature class
        /// has the given name AND where the workspace matches that of the
        /// currently selected telecom workspace.
        /// </summary>
        /// <param name="ftClassName">Name to look for</param>
        /// <returns>IFeatureLayer</returns>
        public ESRI.ArcGIS.Carto.IFeatureLayer FindFeatureLayer(string ftClassName)
        {
            ESRI.ArcGIS.Carto.IFeatureLayer result = null;

            if (1 > ftClassName.Length)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "FindFeatureLayer: ", "ftClassName not specified");
                throw new ArgumentException("ftClassName not specified");
            }

            // Check the cache first for the layer
            if (_featureLayerCache.ContainsKey(ftClassName))
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Found Feature Layer in cache", ftClassName);
                return(_featureLayerCache[ftClassName]);
            }

            ESRI.ArcGIS.esriSystem.UID geoFeatureLayerID = new ESRI.ArcGIS.esriSystem.UIDClass();
            geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";

            ESRI.ArcGIS.Carto.IEnumLayer enumLayer = this.FocusMap.get_Layers(geoFeatureLayerID, true);

            // Step through each geofeature layer in the map
            enumLayer.Reset();
            ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;

            string testName        = ftClassName.ToLower(); // No reason to do this every time in the loop
            int    testDotPosition = testName.LastIndexOf('.');

            testName = testName.Substring(testDotPosition + 1);

            while (ftLayer != null)
            {
                if (ftLayer.Valid)
                {
                    ESRI.ArcGIS.Geodatabase.IDataset dataset = ftLayer.FeatureClass as ESRI.ArcGIS.Geodatabase.IDataset;
                    if (null != dataset && dataset.Workspace == _wkspHelper.CurrentWorkspace)
                    {
                        string tableName = GdbUtils.ParseTableName(dataset);
                        if (tableName.ToLower() == testName)
                        {
                            result = ftLayer;
                            _featureLayerCache.Add(ftClassName, result);
                            break;
                        }
                    }
                }

                ftLayer = enumLayer.Next() as ESRI.ArcGIS.Carto.IFeatureLayer;
            }

            return(result);
        }