Ejemplo n.º 1
0
        public frmBuffer(IMap _pMap)
        {
            InitializeComponent();
            //load all the feature layers in the map to the layers combo
            UID uid = new UIDClass();
            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
            pMap = _pMap;
            layers = pMap.get_Layers(uid, true);
            layers.Reset();
            ILayer layer = null;
            while ((layer = layers.Next()) != null)
            {
                cboLayers.Items.Add(layer.Name);
            }
            //select the first layer
            if (cboLayers.Items.Count > 0)
                cboLayers.SelectedIndex = 0;

            string tempDir = System.IO.Path.GetTempPath();
            txtOutputPath.Text = System.IO.Path.Combine(tempDir, ((string)cboLayers.SelectedItem + "_buffer.shp"));

            //set the default units of the buffer
            int units = Convert.ToInt32(pMap.MapUnits);
            cboUnits.SelectedIndex = units;
        }
Ejemplo n.º 2
0
 private void AttributeQueryFormcs_Load(object sender, EventArgs e)
 {
     if (PMap.LayerCount > 0)                                   //若地图中的图层不为空
     {
         comLayerName.Items.Clear();                            //清除图层名称列表框中的原有内容
         IEnumLayer pEnumlayer = PMap.Layers;                   //获取地图中的图层集合
         pEnumlayer.Reset();                                    //
         ILayer        pLayer        = pEnumlayer.Next();       //获得第一个图层
         IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; //获得矢量要素层
         while (pFeatureLayer != null)                          //
         {
             string name = pLayer.Name;                         //获得图层名称
             comLayerName.Items.Add(name);                      //将图层名称添加到列表中
             pLayer        = pEnumlayer.Next();                 //获得下一个图层
             pFeatureLayer = pLayer as IFeatureLayer;           //获得矢量要素层
         }
     }
 }
Ejemplo n.º 3
0
        public static Hashtable GetNALayers(IMap map)
        {
            Hashtable  hashtable = new Hashtable();
            IEnumLayer layer     = map.get_Layers(null, true);
            ILayer     layer2    = layer.Next();
            int        num       = 0;

            while (layer2 != null)
            {
                if (layer2 is INALayer)
                {
                    hashtable[num] = layer2;
                }
                num++;
                layer2 = layer.Next();
            }
            return(hashtable);
        }
Ejemplo n.º 4
0
        //打开所有图层
        private void ctMenuMapTurnOnAll_Click(object sender, EventArgs e)
        {
            IEnumLayer pEnumLayer = this.axMapControl1.Map.get_Layers(null, false);

            if (pEnumLayer == null)
            {
                return;
            }
            ILayer pLayer;

            pEnumLayer.Reset();
            for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
            {
                pLayer.Visible = true;
            }
            this.axMapControl1.Refresh();
            this.axTOCControl1.Update();
        }
Ejemplo n.º 5
0
 private void populateComboBox()
 {
     if (mp != null)
     {
         IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer);
         ILayer     lyr     = rstLyrs.Next();
         while (lyr != null)
         {
             string       lyrNm  = lyr.Name;
             IRasterLayer rstLyr = (IRasterLayer)lyr;
             IRaster      rst    = rsUtil.createRaster(((IRaster2)rstLyr.Raster).RasterDataset);
             if (((IRasterBandCollection)rst).Count > 1)
             {
                 for (int i = 0; i < ((IRasterBandCollection)rst).Count; i++)
                 {
                     IRaster rsN  = rsUtil.returnRaster(rsUtil.getBand(rst, i));
                     string  rsNm = lyrNm + "_Band_" + (i + 1).ToString();
                     if (!rstDic.ContainsKey(rsNm))
                     {
                         rstDic.Add(rsNm, rsN);
                         cmbInRaster1.Items.Add(rsNm);
                     }
                     else
                     {
                         rstDic[rsNm] = rsN;
                     }
                 }
             }
             else
             {
                 if (!rstDic.ContainsKey(lyrNm))
                 {
                     rstDic.Add(lyrNm, rst);
                     cmbInRaster1.Items.Add(lyrNm);
                 }
                 else
                 {
                     rstDic[lyrNm] = rst;
                 }
             }
             lyr = rstLyrs.Next();
         }
     }
 }
Ejemplo n.º 6
0
        private Dictionary <int, List <IDataLayer2> > GetBrokenDataSources()
        {
            var   brokenDataSources = new Dictionary <int, List <IDataLayer2> >();
            IMaps maps = ArcMap.Document.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                IMap map = maps.Item[i];
                // ReSharper disable once RedundantArgumentDefaultValue
                IEnumLayer layerEnumerator = map.Layers[null];
                ILayer     layer;
                while ((layer = layerEnumerator.Next()) != null)
                {
                    if (layer is ILayer2 layer2)
                    {
                        IDataLayer2 dataLayer = null;
                        if (!layer2.Valid)
                        {
                            dataLayer = layer2 as IDataLayer2;
                        }
                        // An IMosaicLayer (raster mosaic dataset) will report valid when it is not; need to check the sub layers.
                        // Repairing the sub layers is insufficient.  The IMosaicLayer must be repaired (this will repair the sub layers as well)
                        // NOTE: It would be nice to remove the sub-layers (they will report invalid),
                        //       1) they do not need to be fixed if the parent layer is fixed (must do)
                        //       2) they will report as unfixable after the parent layer is fixed because the new, correct path isn't in the moves db
                        else if (layer is IMosaicLayer)
                        {
                            var groupLayer = layer as ICompositeLayer;
                            var groupCount = groupLayer?.Count ?? 0;
                            for (int j = 0; j < groupCount; j++)
                            {
                                // Checking the Valid property on a Mosaic sublayer as ILayer will crash; Casting to ILayer2 is works.  Why????
                                // The raster sub layer does not implement ILayer2.  That is ok, since the boundary and footprint will indicate validity
                                if (groupLayer?.Layer[j] is ILayer2 subLayer)
                                {
                                    if (!subLayer.Valid)
                                    {
                                        dataLayer = layer as IDataLayer2;
                                        break;
                                    }
                                }
                            }
                        }
                        if (dataLayer != null)
                        {
                            if (!brokenDataSources.ContainsKey(i))
                            {
                                brokenDataSources[i] = new List <IDataLayer2>();
                            }
                            brokenDataSources[i].Add(dataLayer);
                        }
                    }
                }
            }
            return(brokenDataSources);
        }
Ejemplo n.º 7
0
        //**打开所有图层**//
        private void TOC_TurnAllLayersOn()
        {
            //打开地图图层
            IEnumLayer pEnumLayer = this.m_pMapControl.Map.get_Layers(null, false);

            if (pEnumLayer == null)
            {
                return;
            }
            ILayer pLayer;

            pEnumLayer.Reset();
            for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
            {
                pLayer.Visible = true;
            }
            this.m_pMapControl.Refresh();
            this.m_pTOCControl.Update();
        }
Ejemplo n.º 8
0
        public static List <ILayer> GetLayers(IMap map)
        {
            if (map == null)
            {
                throw new ArgumentNullException("A valid map reference [map] is required.");
            }

            IEnumLayer    elayers = map.get_Layers(null, true);
            List <ILayer> layers  = new List <ILayer>();
            ILayer        layer   = elayers.Next();

            while (layer != null)
            {
                layers.Add(layer);
                layer = elayers.Next();
            }

            return(layers);
        }
Ejemplo n.º 9
0
        /// <summary> The polygon feature layers in current map </summary>
        /// <returns> Function to retrieve a list of polygon feature layers in current map </returns>
        public ArrayList PolygonLayers()
        {
            ArrayList pList = new ArrayList();

            if (FocusMap == null)
            {
                return(pList);
            }
            if (FocusMap.LayerCount == 0)
            {
                return(pList);
            }

            try
            {
                UID pID = new UIDClass();
                pID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; //GeoFeatureLayer
                IEnumLayer pEnumLayer = FocusMap.get_Layers(pID, true);
                pEnumLayer.Reset();
                ILayer pLayer = pEnumLayer.Next();
                while (!(pLayer == null))
                {
                    IFeatureLayer2 pFLayer = (IFeatureLayer2)pLayer;
                    if (pFLayer.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        if (pFLayer.FeatureClass != null)
                        {
                            pList.Add(pLayer.Name);
                        }
                    }
                    pLayer = pEnumLayer.Next();
                }
                return(pList);
            }
            catch (Exception ex)
            {
                if (SupressMessaging == false)
                {
                    MessageBox.Show(ex.Message, "Polygon Layers", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(pList);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// gets a specific feature layer give a layer name
        /// </summary>
        /// <param name="lyrName">layer name</param>
        /// <returns>ILayer</returns>
        public ILayer getFeatureLayer(string lyrName)
        {
            IEnumLayer lyrs     = getActiveViewLayers(viewUtility.esriIFeatureLayer);
            ILayer     flyr     = null;
            string     lyrName2 = null;
            ILayer     i        = lyrs.Next();

            while (i != null)
            {
                lyrName2 = i.Name;
                if (lyrName2.ToLower() == lyrName.ToLower())
                {
                    flyr = i;
                    break;
                }
                i = lyrs.Next();
            }
            return(flyr);
        }
Ejemplo n.º 11
0
        private void CreateLayer(IName name)
        {
            ILayerFactoryHelper helper = new LayerFactoryHelperClass();

            try
            {
                IEnumLayer layer = helper.CreateLayersFromName(name);
                layer.Reset();
                for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next())
                {
                    this.axMapControl1.AddLayer(layer2, 0);
                    this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, layer2, null);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("无法打开指定文档!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Ejemplo n.º 12
0
 private void CbxLayersAddItems()
 {
     if (GetLayers() != null)
     {
         IEnumLayer layers = GetLayers();
         layers.Reset();
         ILayer layer = layers.Next();
         while (layer != null)
         {
             if (layer is IRasterLayer)
             {
                 rasterlayer = layer as IRasterLayer;
                 cbb_RasterLayersStretch.Items.Add(layer.Name);
                 cbb_RasterLayersScale.Items.Add(layer.Name);
             }
             layer = layers.Next();
         }
     }
 }
Ejemplo n.º 13
0
        public void Init()
        {
            UID uid = new UIDClass
            {
                Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
            };
            IEnumLayer layer = BufferHelper.m_BufferHelper.m_pFocusMap.get_Layers(uid, true);

            this.cboEditingPolygonLayer.Properties.Items.Clear();
            layer.Reset();
            for (ILayer layer2 = layer.Next(); layer2 is IFeatureLayer; layer2 = layer.Next())
            {
                if ((((layer2 as IFeatureLayer).FeatureClass != null) &&
                     ((layer2 as IFeatureLayer).FeatureClass.FeatureType == esriFeatureType.esriFTSimple)) &&
                    this.method_0(layer2 as IFeatureLayer))
                {
                    this.cboEditingPolygonLayer.Properties.Items.Add(new ObjectWrap(layer2));
                }
            }
            this.cboEditingPolygonLayer.Enabled = false;
            if (this.cboEditingPolygonLayer.Properties.Items.Count > 0)
            {
                this.rdoSaveToEditingLayer.Enabled        = true;
                this.cboEditingPolygonLayer.SelectedIndex = 0;
            }
            else
            {
                this.rdoSaveToEditingLayer.Enabled = false;
            }
            if (BufferHelper.m_BufferHelper.m_pFeatureLayer.FeatureClass.ShapeType ==
                esriGeometryType.esriGeometryPolygon)
            {
                this.rdoBufferType.Enabled = true;
            }
            else
            {
                this.rdoBufferType.Enabled = false;
            }
            this.txtOutName.Enabled             = this.rdoNewLayer.Checked;
            this.btnSelectInputFeatures.Enabled = this.rdoNewLayer.Checked;
            this.cboEditingPolygonLayer.Enabled = this.rdoSaveToEditingLayer.Checked;
        }
Ejemplo n.º 14
0
        private bool GetFabricSubLayers(IMap Map, esriCadastralFabricTable FabricSubClass, bool ExcludeNonTargetFabrics,
                                        ICadastralFabric TargetFabric, out IArray CFParcelFabSubLayers)
        {
            ICadastralFabricSubLayer pCFSubLyr     = null;
            IArray        CFParcelFabricSubLayers2 = new ArrayClass();
            IFeatureLayer pParcelFabricSubLayer    = null;
            UID           pId = new UIDClass();

            pId.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            IEnumLayer pEnumLayer = Map.get_Layers(pId, true);

            pEnumLayer.Reset();
            ILayer pLayer = pEnumLayer.Next();

            while (pLayer != null)
            {
                if (pLayer is ICadastralFabricSubLayer)
                {
                    pCFSubLyr = (ICadastralFabricSubLayer)pLayer;
                    if (pCFSubLyr.CadastralTableType == FabricSubClass)
                    {
                        pParcelFabricSubLayer = (IFeatureLayer)pCFSubLyr;
                        ICadastralFabric ThisLayersFabric     = pCFSubLyr.CadastralFabric;
                        bool             bIsTargetFabricLayer = ThisLayersFabric.Equals(TargetFabric);
                        if (!ExcludeNonTargetFabrics || (ExcludeNonTargetFabrics && bIsTargetFabricLayer))
                        {
                            CFParcelFabricSubLayers2.Add(pParcelFabricSubLayer);
                        }
                    }
                }
                pLayer = pEnumLayer.Next();
            }
            CFParcelFabSubLayers = CFParcelFabricSubLayers2;
            if (CFParcelFabricSubLayers2.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
        //Cutomer by jin
        private void AddLayersToComboBox()
        {
            //Add ed by jin
            cboLayer.Items.Clear();
            UID uidLayer = new UID();

            uidLayer.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            IMap map = axMapControl1.ActiveView.FocusMap;

            //UID is inconsistent
            //IEnumLayer allFLayers = map.get_Layers(uidLayer, true);
            IEnumLayer allFLayers = map.get_Layers(null, true);
            //
            ILayer aLayer = allFLayers.Next();

            while (aLayer != null)
            {
                if (aLayer is IRasterLayer)
                {
                    MessageBox.Show(aLayer.Name);
                    m_strOption = "NoLayer";
                    OptionEnabler();
                }
                else if (aLayer is IFeatureLayer)
                {
                    IFeatureLayer fLayer = aLayer as IFeatureLayer;
                    if (fLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        cboLayer.Items.Add(fLayer.Name);
                    }
                    else if (fLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                    {
                        cboLayer.Items.Add(fLayer.Name);
                    }
                    else if (fLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        cboLayer.Items.Add(fLayer.Name);
                    }
                }
                aLayer = allFLayers.Next();
            }
        }
Ejemplo n.º 16
0
        private List <IDataset> GetAllDataset(IMap pMap)
        {
            List <IDataset> list = new List <IDataset>();
            UID             uid  = new UIDClass
            {
                Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
            };
            IEnumLayer layer = pMap.get_Layers(uid, true);

            layer.Reset();
            for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next())
            {
                IFeatureLayer layer3 = layer2 as IFeatureLayer;
                if ((layer3 != null) && (layer3.FeatureClass != null))
                {
                    list.Add(layer3.FeatureClass as IDataset);
                }
            }
            return(list);
        }
Ejemplo n.º 17
0
        public static ILayer GetFeatureLayer(ref IBasicMap ibasicMap_0, ref string string_0)
        {
            ILayer result;

            if (ibasicMap_0.LayerCount > 0)
            {
                IEnumLayer enumLayer = ibasicMap_0.get_Layers(null, true);
                enumLayer.Reset();
                for (ILayer layer = enumLayer.Next(); layer != null; layer = enumLayer.Next())
                {
                    if (layer.Name == string_0 && layer is IFeatureLayer && layer.Valid)
                    {
                        result = layer;
                        return(result);
                    }
                }
            }
            result = null;
            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 刷新图层列表
        /// </summary>
        /// <returns></returns>
        private List <string> RefreshLayers()
        {
            List <string> list   = new List <string>();
            IEnumLayer    layers = Utils.getFeatureLayers(mMap);

            if (layers == null || layers.Next() == null)
            {
                return(list);
            }
            ILayer layer = null;

            layers.Reset();  //将游标归位
            //遍历获取到的矢量图层,并添加到下拉列表中
            while ((layer = layers.Next()) != null)
            {
                // ToolStripMenuItem menuItem = new ToolStripMenuItem(layer.Name);
                list.Add(layer.Name);
            }
            return(list);
        }
Ejemplo n.º 19
0
 private void populateComboBox()
 {
     if (mp != null)
     {
         IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIFeatureLayer);
         ILayer     lyr     = rstLyrs.Next();
         while (lyr != null)
         {
             string        lyrNm  = lyr.Name;
             IFeatureLayer ftrLyr = (IFeatureLayer)lyr;
             IFeatureClass ftrCls = ftrLyr.FeatureClass;
             if (!ftrDic.ContainsKey(lyrNm))
             {
                 ftrDic.Add(lyrNm, (ITable)ftrCls);
                 cmbSampleFeatureClass.Items.Add(lyrNm);
             }
             lyr = rstLyrs.Next();
         }
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// This function will search the map for a service location and then return it
        /// </summary>
        /// <param name="map">the map</param>
        /// <returns>the service location layer</returns>
        public static ILayer ReturnServiceLocationLayerByUtility(IMap map)
        {
            IEnumLayer enumLayer = map.get_Layers(null, true);
            ILayer     layer     = enumLayer.Next();

            while (layer != null)
            {
                if (IsValidGisLayer(layer) && layer is IGeoFeatureLayer)
                {
                    string sName = ((IDataset)layer).BrowseName;

                    if (sName == "Service")
                    {
                        return(layer);
                    }
                }
                layer = enumLayer.Next();
            }
            return(null);
        }
Ejemplo n.º 21
0
        //public void RemoveLayersfromTOC(string directory)
        //{
        //    //IMxDocument mxMap = (IMxDocument)application.Document;
        //    //IMap pMap = mxMap.FocusMap;
        //    //IMapLayers pMapLayers = pMap;

        //    for (int i = 0; i <= ArcMap.Document.FocusMap.LayerCount - 1; i++)
        //    {
        //        ILayer player = ArcMap.Document.FocusMap.Layer[i];
        //        if (player is IGroupLayer)
        //        {
        //            RemoveLayersfromGroupLayer((IGroupLayer)player, directory);
        //        }
        //        else
        //        {
        //            IDataset pDS = player;
        //            try
        //            {
        //                if (LCase(directory) == LCase(pDS.Workspace.PathName))
        //                {
        //                    pMap.DeleteLayer(player);
        //                }
        //            }
        //            }

        //        if (player != null)
        //        {
        //            System.Runtime.InteropServices.Marshal.ReleaseComObject(player);
        //            player = null;
        //        }
        //    }

        //    mxMap.UpdateContents();
        //    mxMap.ActiveView.Refresh();
        //    ESRI.ArcGIS.ArcMapUI.IContentsView pContentsView = mxMap.CurrentContentsView;
        //    pContentsView.Refresh(null);
        //    if (mxMap != null)
        //    {
        //        System.Runtime.InteropServices.Marshal.ReleaseComObject(mxMap);
        //        mxMap = null;
        //    }

        //    if (pContentsView != null)
        //    {
        //        System.Runtime.InteropServices.Marshal.ReleaseComObject(pContentsView);
        //        pContentsView = null;
        //    }
        //}

        //public void RemoveLayersfromGroupLayer(IGroupLayer pGroupLayer, string directory)
        //{
        //    ILayer pLayer;
        //    List<ILayer> LayersToDelete = new List<ILayer>();
        //    ICompositeLayer pCompositeLayer = (ICompositeLayer)pGroupLayer;
        //    for (int i = 1; i <= pCompositeLayer.Count; i++)
        //    {
        //        pLayer = pCompositeLayer.Layer[i - 1];
        //        if (pLayer is IGroupLayer)
        //        {
        //            RemoveLayersfromGroupLayer(pLayer, directory);
        //        }
        //        else
        //        {
        //            try
        //            {
        //                IDataset pDS = (IDataset)pLayer;
        //                string LayerDirectoryname = pDS.Workspace.PathName.ToLower();
        //                if (LayerDirectoryname.EndsWith(IO.Path.DirectorySeparatorChar))
        //                {
        //                    LayerDirectoryname = LayerDirectoryname.Substring(0, LayerDirectoryname.Length - 1);
        //                }

        //                if (LCase(directory) == LayerDirectoryname)
        //                {
        //                    LayersToDelete.Add(pLayer);
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                Debug.WriteLine(ex.Message);
        //            }
        //        }
        //    }

        //    foreach (ILayer pDeleteLayer in LayersToDelete)
        //    {
        //        pGroupLayer.Delete(pDeleteLayer);
        //        if (pDeleteLayer != null)
        //        {
        //            System.Runtime.InteropServices.Marshal.ReleaseComObject(pDeleteLayer);
        //            pDeleteLayer = null;
        //        }
        //    }

        //    if (pGroupLayer != null)
        //    {
        //        System.Runtime.InteropServices.Marshal.ReleaseComObject(pGroupLayer);
        //        pGroupLayer = null;
        //    }
        //}

        public static void RemoveGroupLayer(string sGroupLayerName, Boolean searchRecursive)
        {
            IMap pMap = ArcMap.Document.FocusMap;
            UID  pUID = new UID();

            pUID.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}";

            IEnumLayer pEnum = ArcMap.Document.FocusMap.Layers[pUID, searchRecursive];
            ILayer     pL    = pEnum.Next();

            while (pL is ILayer)
            {
                if (string.Compare(sGroupLayerName, pL.Name, true) == 0)
                {
                    pMap.DeleteLayer(pL);
                }

                pL = pEnum.Next();
            }
        }
Ejemplo n.º 22
0
        private void CbxLayersAddItems()
        {
            if (GetLayers() == null)
            {
                return;
            }
            IEnumLayer layers = GetLayers();

            layers.Reset();
            ILayer layer = layers.Next();

            while (layer != null)
            {
                if (layer is IFeatureLayer)
                {
                    cbxLayers2Symbolize.Items.Add(layer.Name);
                }
                layer = layers.Next();
            }
        }
Ejemplo n.º 23
0
 private void populateComboBox()
 {
     if (mp != null)
     {
         IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer);
         ILayer     lyr     = rstLyrs.Next();
         while (lyr != null)
         {
             string       lyrNm  = lyr.Name;
             IRasterLayer rstLyr = (IRasterLayer)lyr;
             IRaster      rst    = rstLyr.Raster;
             if (!rstDic.ContainsKey(lyrNm))
             {
                 rstDic.Add(lyrNm, rst);
                 cmbRasterBands.Items.Add(lyrNm);
             }
             lyr = rstLyrs.Next();
         }
     }
 }
Ejemplo n.º 24
0
        //Custom
        private IGeoFeatureLayer GetLayerByName(string LayerName)
        {
            UID uid = new UID();

            uid.Value = "{E156D7E5-22AF-11D3-9f99-00C04F6BC78E}";
            IEnumLayer allFLayers = axMapControl1.ActiveView.FocusMap.get_Layers(uid, true);
            //loop until LayerName is found
            ILayer layer;

            layer = allFLayers.Next();
            while (layer != null)
            {
                if (layer.Name.Equals(LayerName))
                {
                    return(layer as IGeoFeatureLayer);
                }
                layer = allFLayers.Next();
            }
            return(null);
        }
        private void CboAddItems(ComboBox cbo)
        {
            IEnumLayer layers = GetLayers();

            if (layers == null)
            {
                return;
            }
            layers.Reset();
            ILayer layer = layers.Next();

            while (layer != null)
            {
                if (layer is IFeatureLayer)
                {
                    cbo.Items.Add(layer.Name);
                }
                layer = layers.Next();
            }
        }
Ejemplo n.º 26
0
        public static bool HasZDLayer(IMap imap_0)
        {
            bool       flag   = false;
            IEnumLayer layers = imap_0.Layers[null, true];

            layers.Reset();
            for (ILayer i = layers.Next(); i != null; i = layers.Next())
            {
                if (i is IFeatureLayer)
                {
                    bool flag1 = ZDRegister.IsZDFeatureClass((i as IFeatureLayer).FeatureClass);
                    flag = flag1;
                    if (flag1)
                    {
                        break;
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 27
0
        public void DiscoverWorkspacesMethod()
        {
            IMxDocument pMxdoc  = ArcMap.Application.Document as IMxDocument;
            IEnumLayer  eLayers = pMxdoc.FocusMap.Layers;

            eLayers.Reset();
            ILayer pLayer = eLayers.Next();

            while (pLayer != null)
            {
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                    IDataset      ds      = pFLayer.FeatureClass as IDataset;
                    AddWorkspace(ds.Workspace);
                }

                pLayer = eLayers.Next();
            }
        }
Ejemplo n.º 28
0
        protected override void OnUpdate()
        {
            m_pMxDoc = (IMxDocument)ArcMap.Application.Document;
            m_pMap   = m_pMxDoc.FocusMap;

            //** If a brand new data frame, reading Layers property will generate an error
            if (m_pMap.LayerCount > 0)
            {
                m_pLayers = m_pMap.Layers;
                m_pLayers.Reset();
                m_pLoopLayer       = m_pLayers.Next();
                m_pOrthoIndexLayer = null;

                //** Loop through all layers
                while (!(m_pLoopLayer == null))
                {
                    if (m_pLoopLayer.Name == "orth_idx")
                    {
                        //** Ortho index found.  Set the ortho var, enable the tool and exit the loop
                        m_pOrthoIndexLayer = (IFeatureLayer)m_pLoopLayer;
                        Enabled            = true;
                        break;
                    }
                    else
                    {
                        //** STATES not found yet.  Move to next layer
                        m_pLoopLayer = m_pLayers.Next();
                    }
                }
            }
            else
            {
                m_pOrthoIndexLayer = null;
            }

            if (m_pOrthoIndexLayer == null)
            {
                //** Ortho Index layer must not be in data frame, disable the tool
                Enabled = false;
            }
        }
Ejemplo n.º 29
0
        protected override void OnUpdate()
        {
            pMxDoc = (IMxDocument)ArcMap.Application.Document;
            pMap   = pMxDoc.FocusMap;

            //** If a brand new data frame, reading Layers property will generate an error
            if (pMap.LayerCount > 0)
            {
                pLayers = pMap.Layers;
                pLayers.Reset();
                pLoopLayer    = pLayers.Next();
                pRoadIdxLayer = null;

                //** Loop through all layers
                while (!(pLoopLayer == null))
                {
                    if (pLoopLayer.Name == "road_idx")
                    {
                        //** Road_idx found.  Set the id var, enable the tool and exit the loop
                        pRoadIdxLayer = (IFeatureLayer)pLoopLayer;
                        Enabled       = true;
                        break;
                    }
                    else
                    {
                        //** roads not found yet.  Move to next layer
                        pLoopLayer = pLayers.Next();
                    }
                }
            }
            else
            {
                pRoadIdxLayer = null;
            }

            if (pRoadIdxLayer == null)
            {
                //** roads must not be in data frame, disable the tool
                Enabled = false;
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 通过名字获得索引图层.
        /// </summary>
        /// <param name="layerName">Name of the layer.</param>
        /// <returns></returns>
        public static IFeatureLayer GetIndexLayerByName(string layerName, IMap pMap)
        {
            UID pUID = new UIDClass();

            pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
            IEnumLayer pEnumLayer = pMap.get_Layers(pUID, true);

            pEnumLayer.Reset();
            ILayer pLayer = pEnumLayer.Next();

            while (pLayer != null)
            {
                if (pLayer.Name == layerName)
                {
                    return((IFeatureLayer)pLayer);
                }

                pLayer = pEnumLayer.Next();
            }
            return(null);
        }
Ejemplo n.º 31
0
        private void CacheTOC()
        {
            IMap aMap = ArcMap.Document.FocusMap as IMap;
            //UID anUID = new UID();
            //anUID.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}";
            // get all the 'top level' items
            IEnumLayer someLayers = aMap.Layers[null, false];
            ILayer     aLayer     = null;
            int        depth      = 0;

            while ((aLayer = someLayers.Next()) != null)
            {
                rootLayers.Add(aLayer);
            }
            someLayers = aMap.Layers[null, true];
            while ((aLayer = someLayers.Next()) != null)
            {
                Tree.Add(depth, aLayer);
                depth += 1;
            }
        }
Ejemplo n.º 32
0
        public Buffer(IMap _pMap)
        {
            InitializeComponent();

            //����Glass����
            this.EnableGlass = false;
            //����ʾ�����С����ť
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            //
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
            //ȥ��ͼ��
            this.ShowIcon = false;

            //load all the feature layers in the map to the layers combo
            UID uid = new UIDClass();
            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
            pMap = _pMap;
            layers = pMap.get_Layers(uid, true);
            layers.Reset();
            ILayer layer = null;
            while ((layer = layers.Next()) != null)
            {
                cboLayers.Items.Add(layer.Name);
            }
            //select the first layer
            if (cboLayers.Items.Count > 0)
                cboLayers.SelectedIndex = 0;

            string tempDir = System.IO.Path.GetTempPath();
            txtOutputPath.Text = System.IO.Path.Combine(tempDir, ((string)cboLayers.SelectedItem + "_buffer.shp"));

            //set the default units of the buffer
            int units = Convert.ToInt32(pMap.MapUnits);
            cboUnits.SelectedIndex = units;
        }
Ejemplo n.º 33
0
        private Dictionary<IFeatureLayer, string> GetTransMapLayers(IEnumLayer layers, IWorkspace transWorkspace)
        {
            Dictionary<IFeatureLayer, string> theReturn = new Dictionary<IFeatureLayer,string>();

            layers.Reset();
            ILayer theLayer = layers.Next();
            while (theLayer != null)
            {
                if (theLayer is IFeatureLayer)
                {
                    IDataset theDataset = ((IFeatureLayer)theLayer).FeatureClass as IDataset;
                    if (theDataset != null && theDataset.Workspace == transWorkspace)
                    {
                        theReturn.Add((IFeatureLayer)theLayer, theDataset.Name);
                    }
                }
                theLayer = layers.Next();
            }

            return theReturn;
        }
Ejemplo n.º 34
0
 /// <summary>
 /// 窗体初始化
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SelectByAttrFrm_Load(object sender, EventArgs e)
 {
     this.pMap = this.tempMainFrm.mainMapControl.Map;
     if (this.pMap.LayerCount == 0) return;
     this.pEnumLayer = this.pMap.get_Layers(null, true);
     if (pEnumLayer == null)
     {
         return;
     }
     pEnumLayer.Reset();
     for (this.pLayer = pEnumLayer.Next(); this.pLayer != null; this.pLayer = pEnumLayer.Next())
     {
         if (this.pLayer is IFeatureLayer)
         {
             this.comboBoxLayers.Items.Add(this.pLayer.Name);
         }
     }
     if (this.comboBoxLayers.Items.Count == 0)
     {
         MessageBox.Show("没有可供选择的图层!");
         this.Close();
         return;
     }
     this.comboBoxLayers.SelectedIndex = 0;
     this.comboBoxMethod.SelectedIndex = 0;
 }
Ejemplo n.º 35
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;

            }
            #region //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null)  //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {

                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null) return;
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

                    //Create a MapSurroundFrame from the MapFrame
                    mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

                    if (mapSurroundFrame == null) return;
                    if (mapSurroundFrame.MapSurround == null) return;

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;

                }

                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
               #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame .MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            else
                textBox1.Text = "Legend";

            this.textBoxWidth.Text = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack !=null )
            this.btnBackGroundColor.BackColor =ColorTranslator.FromOle ( pSymbolBack.FillSymbol.Color.RGB ) ;
            if (pSymbolBorder != null)
            this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
             if (pSymbolShadow != null)
            this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
        }
		private string CreateSchLayers(IEnumLayer pLayers)
		{
			if (pLayers == null) return "";
			ILayer pLayer = pLayers.Next();
			IFeatureLayer featureLayer;
			IFeatureClass featureClass;
			string pStrLayerNames = "";
			IDataset pDataset;
			System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
			System.Windows.Forms.Cursor.Show();

			m_pSDS.DesignMode = true;
			m_pSDI = (ESRI.ArcGIS.Schematic.ISchematicDatasetImport)m_pSDS;

			Dictionary<string, IFeatureClass> myDictionary = new Dictionary<string, IFeatureClass>();
			IGeometricNetwork gn = null;
			do
			{
				featureLayer = (IFeatureLayer)pLayer;
				featureClass = featureLayer.FeatureClass;
				pDataset = (IDataset)featureClass;

				if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTSimpleEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
				{

					//The FeatureType property of feature classes that implement this interface will be esriFTSimpleJunction, esriDTSimpleEdge, esriFTComplexJunction, or esriFTComplexEdge.
					INetworkClass networkClass = (INetworkClass)featureLayer.FeatureClass;

					if (networkClass.GeometricNetwork != null)
					{
						//we have a network class
						if ((gn == null) || (gn != networkClass.GeometricNetwork))
						{
							//need to process all the classes
							Dictionary<string, IFeatureClass> localDictionary = new Dictionary<string, IFeatureClass>();
							gn = networkClass.GeometricNetwork;
							IEnumFeatureClass fcComplexEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge);
							IEnumFeatureClass fcComplexNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction);
							IEnumFeatureClass fcSimpleEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge);
							IEnumFeatureClass fcSimpleNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction);
							localDictionary = ProcessFCs(fcComplexEdge, fcComplexNode, fcSimpleEdge, fcSimpleNode);
							if (myDictionary.Count == 0)  //just copy it
							{
								myDictionary = localDictionary;
							}
							else //merge
							{
								Dictionary<string, IFeatureClass>.KeyCollection keyColl = localDictionary.Keys;

								foreach (string s in keyColl)
								{
									IFeatureClass fc;
									bool bln = localDictionary.TryGetValue(s, out fc);
									myDictionary.Add(s, fc);
								}
							}
						}
						//Build up the string that will go to the select items to reduce form
						pStrLayerNames += pDataset.Name.ToString();
						pStrLayerNames += ";";

						//Build up the string for just the node feature classes
						if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
						{
							strNodeLayers += pDataset.Name.ToString();
							strNodeLayers += ";";
						}

						//create the fields collections to be used by the frmAdvanced form
						IFields pFields = featureClass.Fields;
						if (pFields.FieldCount > 0)
						{
							for (int i = 0; i < pFields.FieldCount; i++)
							{
								//don't mess with objectid or shape or GlobalID
								if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != featureClass.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != featureClass.ShapeFieldName.ToString()))
								{
									m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
								}
							}
						}

						//remove the layer from the list of dictionary classes
						if (myDictionary.ContainsKey(featureClass.AliasName))
						{
							myDictionary.Remove(featureClass.AliasName);
						}

						m_pSDI.ImportFeatureLayer(featureLayer, m_pSDT, true, true, true);
					}
				}
				pLayer = pLayers.Next();
			} while (pLayer != null);

			//handle any feature classes that were not in the map
			if (myDictionary.Count > 0)
			{
				Dictionary<string, IFeatureClass>.KeyCollection keyColl = myDictionary.Keys;
				foreach (string s in keyColl)
				{
					IFeatureClass fc;
					bool bln = myDictionary.TryGetValue(s, out fc);
					IObjectClass o = (IObjectClass)fc;
					pDataset = (IDataset)fc;

					pStrLayerNames += pDataset.Name.ToString();
					pStrLayerNames += ";";

					//Build up the string for just the node feature classes
					if (fc.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction)
					{
						strNodeLayers += pDataset.Name.ToString();
						strNodeLayers += ";";
					}

					//create the fields collections to be used by the frmAdvanced form
					IFields pFields = fc.Fields;
					if (pFields.FieldCount > 0)
					{
						for (int i = 0; i < pFields.FieldCount; i++)
						{
							//don't mess with objectid or shape or GlobalID
							if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != fc.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != fc.ShapeFieldName.ToString()))
							{
								m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString());
							}
						}
					}
					if ((fc.FeatureType == esriFeatureType.esriFTComplexJunction) || (fc.FeatureType == esriFeatureType.esriFTSimpleJunction))
					{
						//node
						m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicNodeType);
					}
					else
					{
						//link
						m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicLinkType);
					}
				}
			}

			m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true);
			m_pSDS.DesignMode = false;
			return pStrLayerNames;
		}
Ejemplo n.º 37
0
        private IFeatureLayer GetFeatureLayer(string layerName)
        {
            //get the layers from the maps
            UID uid = new UIDClass();
            uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";
            layers = pMap.get_Layers(uid, true);
            layers.Reset();

            ILayer layer = null;
            while ((layer = layers.Next()) != null)
            {
                if (layer.Name == layerName)
                    return layer as IFeatureLayer;
            }

            return null;
        }