Beispiel #1
0
        /// <summary>
        /// 用指定填充颜色和边线颜色渲染图层
        /// </summary>
        /// <param name="geoLayer">图层</param>
        /// <param name="mainColor">主颜色,即面图层的填充颜色,线图层的线条颜色,点图层的符号内部颜色</param>
        /// <param name="outlineColor">面或点的边线颜色,若为null,则设置边线颜色为RGB:128, 138, 135</param>
        /// <param name="transparency">图层的透明度,0为不透明,100为全透明</param>
        /// <param name="widthOrSize">面/线图层的线宽,或点图层点的大小</param>
        public static void SetSimpleRenderer(this IGeoFeatureLayer geoLayer, IColor mainColor, IColor outlineColor = null, short transparency = 0, double widthOrSize = 1)
        {
            ISymbol symbol = null;

            switch (geoLayer.FeatureClass.ShapeType)
            {
            case esriGeometryType.esriGeometryPolygon:
                symbol = (ISymbol)SymbolCreate.GetSimpleFillSymbol(mainColor, outlineColor, widthOrSize);
                break;

            case esriGeometryType.esriGeometryPoint:
            case esriGeometryType.esriGeometryMultipoint:
                symbol = (ISymbol)SymbolCreate.GetSimpleMarkerSymbol(mainColor, outlineColor, widthOrSize);
                break;

            case esriGeometryType.esriGeometryLine:
            case esriGeometryType.esriGeometryPolyline:
                symbol = (ISymbol)SymbolCreate.GetSimpleLineSymbol(mainColor, widthOrSize);
                break;
            }
            geoLayer.Renderer = new SimpleRendererClass {
                Symbol = symbol
            };

            ILayerEffects layerEffects = (ILayerEffects)geoLayer;

            layerEffects.Transparency = transparency;
        }
Beispiel #2
0
        protected override void OnClick()
        {
            if (ArcMap.Document.FocusMap.LayerCount < 1)
            {
                MessageBox.Show("You MUST have at least one layer in the map to use this tool.", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ILayer        layer        = ArcMap.Document.FocusMap.Layer[0];
            ILayerEffects layerEffects = layer as ILayerEffects;

            if (!layerEffects.SupportsTransparency)
            {
                return;
            }

            IDisplayFilterManager filterManager = layer as IDisplayFilterManager;

            filterManager.DisplayFilter = (layerEffects.Transparency == 0)
                ? new TransparencyDisplayFilterClass {
                Transparency = 75
            }
                : null;

            ArcMap.Document.ActiveView.Refresh();
        }
        private void SetBrightness(ILayer layer, short brtness)
        {
            ILayerEffects layerEffects = (ILayerEffects)layer;

            layerEffects.Brightness = brtness;
            return;
        }
Beispiel #4
0
        private void inPutTrans_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                int iValue = Convert.ToInt32(inPutTrans.Value) > 100 ? 100 : Convert.ToInt32(inPutTrans.Value);
                iValueLast = iValue;//记录上次  20110802 xisheng

                if (iValue < 0)
                {
                    inPutTrans.Value = Convert.ToDecimal(1);
                    iValue           = 1;
                }
                trackBar.Value = iValue;
                ILayerEffects pLyrEffects = m_pCurrentLayer as ILayerEffects;
                pLyrEffects.Transparency = (short)this.inPutTrans.Value;
            }
            catch
            {
                // (ee.Message,"提示");
                inPutTrans.Value = Convert.ToDecimal(iValueLast);//20110802 xisheng
            }

            //屏蔽设置透明度而一直刷新 现为点击应用再刷新 xisheng 20111117
            // frmLayerProperties.m.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, m_pCurrentLayer, null);
        }
        private void SetContrast(ILayer layer, short ctr)
        {
            ILayerEffects layerEffects = (ILayerEffects)layer;

            layerEffects.Contrast = ctr;
            return;
        }
Beispiel #6
0
        private void frmLayerTransparency_Load(object sender, EventArgs e)
        {
            ILayerEffects plyrEffects = m_pLayer as ILayerEffects;

            nDefaultValue = plyrEffects.Transparency;
            this.txtLayerTransparency.Text  = nDefaultValue.ToString();
            trackBarLayerTransparency.Value = nDefaultValue;
        }
Beispiel #7
0
        //更改图层透明度
        private void TransparencyTrackBar_Scroll(object sender, EventArgs e)
        {
            ILayerEffects eff = (m_mapControl.Layer[0] as ILayer) as ILayerEffects;

            eff.Transparency       = (short)TransparencyTrackBar.Value;
            TransparencyLabel.Text = "顶层透明度:" + TransparencyTrackBar.Value.ToString() + "%";
            activeView.Refresh();
        }
Beispiel #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //nDefaultValue = Convert.ToInt16(this.txtLayerTransparency.Text);
            ILayerEffects plyrEffects = m_pLayer as ILayerEffects;

            plyrEffects.Transparency = Convert.ToInt16(this.txtLayerTransparency.Text);
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            //this.Close();
        }
Beispiel #9
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtLayerTransparency.Text  = nDefaultValue.ToString();
            trackBarLayerTransparency.Value = nDefaultValue;

            ILayerEffects plyrEffects = m_pLayer as ILayerEffects;

            plyrEffects.Transparency = nDefaultValue;
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Beispiel #10
0
        private void AddTempLayer()
        {
            tempFeatureLayer = new FeatureLayerClass();
            tempFeatureLayer.FeatureClass = clipFeatureClass;
            tempFeatureLayer.Name         = clipFeatureClass.AliasName;
            ILayerEffects layerEffects = tempFeatureLayer as ILayerEffects;

            layerEffects.Transparency = 65;
            m_map.AddLayer(tempFeatureLayer);
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
        }
Beispiel #11
0
        /// <summary>
        /// 设置图层透明度
        /// </summary>
        /// <param name="pFeaturelayer"></param>
        /// <param name="transparency"></param>
        public static void setLayerTransparency(IFeatureLayer pFeaturelayer, short transparency)
        {
            if (pFeaturelayer == null)
            {
                return;
            }
            ILayerEffects effects = pFeaturelayer as ILayerEffects;

            if (effects.SupportsTransparency)
            {
                effects.Transparency = transparency;
            }
        }
Beispiel #12
0
        private void fnBlinking(string strLayerName, string strFieldName, int intFlickerRate, int intNClasses, short srtTransparency, double[] cb)
        {
            try
            {
                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                pFLayer = pLayer as IFeatureLayer;

                pTrackCancel = new CancelTrackerClass();
                pTrackCancel.CancelOnClick    = false;
                pTrackCancel.CancelOnKeyPress = true;

                ILayerEffects pLayerEffect = (ILayerEffects)pFLayer;
                pLayerEffect.Transparency = srtTransparency;

                while (pTrackCancel.Continue())
                {
                    IFeatureLayerDefinition2 pFDefinition = (IFeatureLayerDefinition2)pFLayer;

                    for (int i = 0; i < intNClasses; i++)
                    {
                        if (i == 0)
                        {
                            pFDefinition.DefinitionExpression = strFieldName + " >= " + cb[i].ToString();
                        }
                        else
                        {
                            pFDefinition.DefinitionExpression = strFieldName + " > " + cb[i].ToString();
                        }

                        pActiveView.Refresh();
                        System.Threading.Thread.Sleep(intFlickerRate);
                        if (pTrackCancel.Continue() == false)
                        {
                            pFDefinition.DefinitionExpression = strFieldName + " >= " + cb[0].ToString();
                            pActiveView.Refresh();
                            btnStart.Text             = "Start";
                            pLayerEffect.Transparency = 0;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Beispiel #13
0
        public void SaveChangeResult()
        {
            InterposeLayerVisible(m_layerVisible);
            InterposeLayerDescription();
            InterposeLayerScale();
            //if(frmLayerProperties.m_featureTrue) xisheng 20111117 屏蔽掉图层名修改
            m_pLayer.Name = txtLayerName.Text;

            //定义透明度
            ILayerEffects pLyrEffects = m_pCurrentLayer as ILayerEffects;

            pLyrEffects.Transparency = (short)this.inPutTrans.Value;
            //xisheng 20110729 透明度设置
            frmLayerProperties.m_shorttra = pLyrEffects.Transparency;
        }
 /// <summary>
 /// Sets the layer transparency.
 /// </summary>
 private void SetLayerTransparency()
 {
     try
     {
         ILayerEffects layerEffects = this.m_pLayer as ILayerEffects;
         string        s            = this.zoomTrackBarControl1.EditValue.ToString();
         layerEffects.Transparency = short.Parse(s);
         IViewRefresh viewRefresh = this.m_pMap as IViewRefresh;
         viewRefresh.RefreshItem(this.m_pLayer);
     }
     catch (Exception ex)
     {
         //this.m_logger.Log(LogLevel.Error, EventType.UserManagement, this.Text, ex);
         Log.WriteLog(typeof(frmLayerTransparency), ex);
     }
 }
        /// <summary>
        /// Gets the layer transparency.
        /// </summary>
        /// <returns>System.Int32.</returns>
        private int GetLayerTransparency()
        {
            int result;

            try
            {
                ILayerEffects layerEffects = this.m_pLayer as ILayerEffects;
                int           transparency = (int)layerEffects.Transparency;
                result = transparency;
            }
            catch
            {
                result = 0;
            }
            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// 设置图层透明度
        /// </summary>
        /// <param name="layerName">图层名称</param>
        /// <param name="transparency">透明度</param>
        public void SetTransparency(string layerName, short transparency)
        {
            if (!layerDic.ContainsKey(layerName))
            {
                return;
            }

            ILayer pLayer = layerDic[layerName];

            Dosomething((Action) delegate()
            {
                // 透明度
                ILayerEffects pLayerEffects = pLayer as ILayerEffects;
                pLayerEffects.Transparency  = transparency;
            }, true);
        }
Beispiel #17
0
 private void trbTransparent_Scroll(object sender, EventArgs e)
 {
     try
     {
         if (pFLayer == null)
         {
             return;
         }
         ILayerEffects pLayerEffect = (ILayerEffects)pFLayer;
         pLayerEffect.Transparency = Convert.ToInt16(trbTransparent.Value);
         pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
     }
     catch (Exception ex)
     {
         frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
         return;
     }
 }
 public bool get_AppliesToObject(object pObject)
 {
     if (pObject is ILayer)
     {
         ILayerEffects layerEffects = (ILayerEffects)pObject;
         if (layerEffects.SupportsBrightnessChange && layerEffects.SupportsContrastChange)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #19
0
        private IFeatureLayer AddTempFeatureLayer()
        {
            try
            {
                //IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                //string gdbName = "FGISTemp" + ".gdb";
                //string gdbFullPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), gdbName);
                //IWorkspace workspace;
                //IFeatureWorkspace featureWorkspace;

                //if (System.IO.Directory.Exists(gdbFullPath))
                //{
                //    featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(gdbFullPath, 0);
                //}
                //else
                //{
                //    IWorkspaceName workspaceName = workspaceFactory.Create(System.IO.Path.GetTempPath(), gdbName, null, 0);
                //    IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName;
                //    workspace = (IWorkspace)name.Open();
                //    featureWorkspace = workspace as IFeatureWorkspace;
                //}

                IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0);
                IFeatureClass     featureClass     = featureWorkspace.OpenFeatureClass(tempFeatureLayerName);
                IFeatureLayer     featureLayer     = new FeatureLayerClass();
                featureLayer.FeatureClass = featureClass;
                featureLayer.Name         = featureClass.AliasName;
                featureLayer.Visible      = true;
                ILayerEffects layerEffects = featureLayer as ILayerEffects;
                layerEffects.Transparency = 60;
                IActiveView activeView = m_hookHelper.ActiveView;
                activeView.FocusMap.AddLayer(featureLayer);
                activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
                txtMessages.Text += "已创建临时层:Temp_Layer\r\n";
                return(featureLayer);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #20
0
 private void frmBlinking_FormClosed(object sender, FormClosedEventArgs e)
 {
     try
     {
         if (pFLayer != null)
         {
             ILayerEffects pLayerEffect = (ILayerEffects)pFLayer;
             pLayerEffect.Transparency = 0;
         }
         else
         {
             return;
         }
     }
     catch (Exception ex)
     {
         frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
         return;
     }
 }
Beispiel #21
0
        public frmLayerProperties(ILayer pLayer, IMapControlDefault mapcontrol, bool FeatureTure, string Layerid)
        {
            m_pLayer = pLayer;
            LayerID  = Layerid;
            ILayerEffects pLyrEffects = m_pLayer as ILayerEffects;

            m_shorttra = pLyrEffects.Transparency;//设置初始值 xisheng 20110729
            //在这判断是否为影像和适量了
            if (pLayer is IRasterCatalogLayer || pLayer is IRasterLayer)
            {
                FeatureTure = false;
            }
            else
            {
                FeatureTure = true;
            }
            m_MapControl  = mapcontrol;
            m_featureTrue = FeatureTure;
            InitializeComponent();
            InitTabControl();//添加TabControl
        }
Beispiel #22
0
        public frmLayerProperties(ILayer pLayer, IActiveView pActiveView, bool FeatureTure)
        {
            m_pActiveView = pActiveView;
            m_pLayer      = pLayer;
            ILayerEffects pLyrEffects = m_pLayer as ILayerEffects;

            m_shorttra = pLyrEffects.Transparency;//设置初始值 xisheng 20110729
            //在这判断是否为影像和适量了
            if (pLayer is IRasterCatalogLayer || pLayer is IRasterLayer)
            {
                FeatureTure = false;
            }
            else
            {
                FeatureTure = true;
            }
            //m_Map = map;
            m_featureTrue = FeatureTure;
            InitializeComponent();
            InitTabControl();//添加TabControl
        }
Beispiel #23
0
 private void frmGlider_FormClosed(object sender, FormClosedEventArgs e)
 {
     try
     {
         if (pFLayer != null)
         {
             ILayerEffects pLayerEffect = (ILayerEffects)pFLayer;
             pLayerEffect.Transparency = 0;
             DrawOnlySelectedFeatures(dblMinValue - 1);
         }
         else
         {
             return;
         }
     }
     catch (Exception ex)
     {
         frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
         return;
     }
 }
Beispiel #24
0
        //更换数据库时,重新初始化地图控件
        private void initAxMapCtrl(IWorkspace indataWS)
        {
            axMapControlR.ClearLayers();
            IFeatureWorkspace pFW = indataWS as IFeatureWorkspace;
            IFeatureClass     pFC = null;

            if ((indataWS as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, "METADATA_MAP"))
            {
                pFC = pFW.OpenFeatureClass("METADATA_MAP");
                IFeatureLayer pFL = new FeatureLayerClass();
                pFL.FeatureClass = pFC;
                pFL.Name         = pFC.AliasName;
                IGeoFeatureLayer pGFL = pFL as IGeoFeatureLayer;
                DefineUniqueValueRenderer(pGFL, "数据生产时间");
                //IAnnotationExpressionEngine pAEE = new AnnotationVBScriptEngineClass();
                //pAEE.SetExpression();
                ILabelEngineLayerProperties pLELP = new LabelEngineLayerPropertiesClass();
                pLELP.Expression = "\"数据生产单位:\" & [数据生产单位] & chr(13) & \"数据生产时间:\" & [数据生产时间] & chr(13)";//"[producedate]";
                IAnnotateLayerPropertiesCollection pALPC = pGFL.AnnotationProperties;
                pALPC.Clear();
                pALPC.Add(pLELP as IAnnotateLayerProperties);
                pGFL.DisplayAnnotation = true;

                axMapControlR.Map.AddLayer(pFL);
            }

            if ((indataWS as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, "XZQH_XIAN"))
            {
                pFC = pFW.OpenFeatureClass("XZQH_XIAN");
                IFeatureLayer pFL = new FeatureLayerClass();
                pFL.FeatureClass = pFC;
                pFL.Name         = pFC.AliasName;
                ILayerEffects pLE = pFL as ILayerEffects;
                if (pLE.SupportsTransparency)
                {
                    pLE.Transparency = 60;//设置图层透明
                }
                axMapControlR.AddLayer(pFL);
            }
        }
Beispiel #25
0
 private IFeatureLayer AddTempFeatureLayer()
 {
     try
     {
         IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
         IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0);
         IFeatureClass     featureClass     = featureWorkspace.OpenFeatureClass(tempFeatureClassName);
         IFeatureLayer     featureLayer     = new FeatureLayerClass();
         featureLayer.FeatureClass = featureClass;
         featureLayer.Name         = featureClass.AliasName;
         featureLayer.Visible      = true;
         ILayerEffects layerEffects = featureLayer as ILayerEffects;
         layerEffects.Transparency = 60;
         IActiveView activeView = m_hookHelper.ActiveView;
         activeView.FocusMap.AddLayer(featureLayer);
         activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
         txtMessages.Text += "已创建临时层:Temp_Layer\r\n";
         return(featureLayer);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #26
0
        public static ILayer AddToMap(FileSystemDataset dataset, string sLayerName, IGroupLayer pGroupLayer, List <string> precedingLayers, FileInfo fiSymbologyLayerFile = null, bool bAddToMapIfPresent = false, short transparency = 0, string definition_query = "")
        {
            if (!dataset.Exists)
            {
                return(null);
            }

            // Only add if it doesn't exist already
            ILayer pResultLayer = GetLayerBySource(dataset.Path);

            if ((pResultLayer is ILayer && string.Compare(pResultLayer.Name, sLayerName, true) == 0) && !bAddToMapIfPresent)
            {
                return(pResultLayer);
            }

            // Confirm that the symbology layer file exists
            if (fiSymbologyLayerFile != null && !fiSymbologyLayerFile.Exists)
            {
                Exception ex = new Exception("A symbology layer file was provided, but the file does not exist");
                ex.Data["Data Source"] = dataset.Path.FullName;
                ex.Data["Layer file"]  = fiSymbologyLayerFile.FullName;
                throw ex;
            }

            IWorkspace pWorkspace = GetWorkspace(dataset);

            switch (dataset.WorkspaceType)
            {
            case FileSystemDataset.GISDataStorageTypes.RasterFile:
                IRasterDataset pRDS      = ((IRasterWorkspace)pWorkspace).OpenRasterDataset(Path.GetFileName(dataset.Path.FullName));
                IRasterLayer   pRLResult = new RasterLayer();
                pRLResult.CreateFromDataset(pRDS);
                pResultLayer = pRLResult;
                break;

            case FileSystemDataset.GISDataStorageTypes.CAD:
                string        sFile = Path.GetFileName(Path.GetDirectoryName(dataset.Path.FullName));
                string        sFC   = sFile + ":" + Path.GetFileName(dataset.Path.FullName);
                IFeatureClass pFC   = ((IFeatureWorkspace)pWorkspace).OpenFeatureClass(sFC);
                pResultLayer = new FeatureLayer();
                ((IFeatureLayer)pResultLayer).FeatureClass = pFC;
                break;

            case FileSystemDataset.GISDataStorageTypes.ShapeFile:
                IFeatureWorkspace pWS        = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(dataset);
                IFeatureClass     pShapeFile = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(dataset.Path.FullName));
                pResultLayer = new FeatureLayer();
                ((IFeatureLayer)pResultLayer).FeatureClass = pShapeFile;
                break;

            case FileSystemDataset.GISDataStorageTypes.TIN:
                ITin pTIN = ((ITinWorkspace)pWorkspace).OpenTin(System.IO.Path.GetFileName(dataset.Path.FullName));
                pResultLayer = new TinLayer();
                ((ITinLayer)pResultLayer).Dataset = pTIN;
                pResultLayer.Name = dataset.Name;
                break;

            case FileSystemDataset.GISDataStorageTypes.GeoPackage:
                IFeatureWorkspace pGPKGWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(dataset);
                IFeatureClass     pGPKGFC = pGPKGWS.OpenFeatureClass(System.IO.Path.GetFileName(dataset.Path.FullName));
                pResultLayer = new FeatureLayer();
                ((IFeatureLayer)pResultLayer).FeatureClass = pGPKGFC;
                break;

            default:
                Exception ex = new Exception("Unhandled GIS dataset type");
                ex.Data["FullPath Path"] = dataset.Path.FullName;
                ex.Data["Storage Type"]  = dataset.WorkspaceType.ToString();
                throw ex;
            }

            if (!string.IsNullOrEmpty(sLayerName))
            {
                pResultLayer.Name = sLayerName;
            }

            try
            {
                ApplySymbology(pResultLayer, fiSymbologyLayerFile);
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower().Contains("symbology"))
                {
                    System.Diagnostics.Debug.Print(ex.Message);
                    // DO Nothing
                }
                else
                {
                    throw;
                }
            }

            try
            {
                if (pResultLayer is IFeatureLayer && !string.IsNullOrEmpty(definition_query))
                {
                    ApplyDefinitionquery((IFeatureLayer)pResultLayer, definition_query);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower().Contains("symbology"))
                {
                    System.Diagnostics.Debug.Print(ex.Message);
                    // DO Nothing
                }
                else
                {
                    throw;
                }
            }

            if (transparency > 0)
            {
                ILayerEffects pLayerEffects = (ILayerEffects)pResultLayer;
                pLayerEffects.Transparency = transparency;
            }

            if (pGroupLayer == null)
            {
                ((IMapLayers)ArcMap.Document.FocusMap).InsertLayer(pResultLayer, false, 0);
            }
            else
            {
                int layerIndex = 0;
                foreach (string name in precedingLayers)
                {
                    // Try and find the preceding layer already in the hierarchy
                    ICompositeLayer pCompositeLayer = (ICompositeLayer)pGroupLayer;
                    for (int i = 0; i <= pCompositeLayer.Count - 1; i++)
                    {
                        if (string.Compare(pCompositeLayer.Layer[i].Name, name, true) == 0)
                        {
                            layerIndex++;
                        }
                    }
                }

                ((IMapLayers)ArcMap.Document.FocusMap).InsertLayerInGroup(pGroupLayer, pResultLayer, false, layerIndex);
            }

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
            ArcMap.Document.CurrentContentsView.Refresh(null);

            return(pResultLayer);
        }
Beispiel #27
0
        ///<summary>
        ///在程序运行时的内存中创建矢量要素层,并加到地图控件最顶端
        ///</summary>
        ///<param name="pMapCtrl">地图控件</param>
        ///<returns>IFeatureLayer 新加的要素层</returns>
        public IFeatureLayer AddFeatureLayerByMemoryWS(AxMapControl pMapCtrl, ISpatialReference pSReference)
        {
            try
            {
                if (pMapCtrl == null)
                {
                    return(null);
                }

                #region 创建新的内存工作空间
                IWorkspaceFactory pWSF    = new InMemoryWorkspaceFactoryClass();
                IWorkspaceName    pWSName = pWSF.Create("", "Temp", null, 0);

                IName      pName     = (IName)pWSName;
                IWorkspace pMemoryWS = (IWorkspace)pName.Open();
                #endregion

                IField        oField        = new FieldClass();
                IFields       oFields       = new FieldsClass();
                IFieldsEdit   oFieldsEdit   = null;
                IFieldEdit    oFieldEdit    = null;
                IFeatureClass oFeatureClass = null;
                IFeatureLayer oFeatureLayer = null;
                try
                {
                    oFieldsEdit             = oFields as IFieldsEdit;
                    oFieldEdit              = oField as IFieldEdit;
                    oFieldEdit.Name_2       = "OBJECTID";
                    oFieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
                    oFieldEdit.IsNullable_2 = false;
                    oFieldEdit.Required_2   = false;
                    oFieldsEdit.AddField(oField);

                    oField     = new FieldClass();
                    oFieldEdit = oField as IFieldEdit;
                    IGeometryDef     pGeoDef     = new GeometryDefClass();
                    IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
                    pGeoDefEdit.AvgNumPoints_2     = 5;
                    pGeoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
                    pGeoDefEdit.GridCount_2        = 1;
                    pGeoDefEdit.HasM_2             = false;
                    pGeoDefEdit.HasZ_2             = false;
                    pGeoDefEdit.SpatialReference_2 = pSReference;
                    oFieldEdit.Name_2        = "SHAPE";
                    oFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                    oFieldEdit.GeometryDef_2 = pGeoDef;
                    oFieldEdit.IsNullable_2  = true;
                    oFieldEdit.Required_2    = true;
                    oFieldsEdit.AddField(oField);

                    oField                  = new FieldClass();
                    oFieldEdit              = oField as IFieldEdit;
                    oFieldEdit.Name_2       = "Code";
                    oFieldEdit.Type_2       = esriFieldType.esriFieldTypeSmallInteger;
                    oFieldEdit.IsNullable_2 = true;
                    oFieldsEdit.AddField(oField);
                    //创建要素类
                    oFeatureClass              = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                    oFeatureLayer              = new FeatureLayerClass();
                    oFeatureLayer.Name         = "TransTemp";
                    oFeatureLayer.FeatureClass = oFeatureClass;
                    //创建唯一值符号化对象
                    IUniqueValueRenderer pURender = new UniqueValueRendererClass();
                    pURender.FieldCount = 1;
                    pURender.set_Field(0, "Code");
                    pURender.UseDefaultSymbol = false;
                    ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass();
                    pFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
                    //半透明颜色
                    IRgbColor pColor = new RgbColorClass();
                    pColor.Red     = 255;
                    pColor.Green   = 255;
                    pFillSym.Color = pColor;
                    pURender.AddValue("1", "", pFillSym as ISymbol);
                    pFillSym       = new SimpleFillSymbolClass();
                    pFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
                    //唯一值符号化内存图层
                    (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer;
                    ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects;
                    //透明度
                    pLyrEffect.Transparency = 80;
                }
                catch (Exception Err)
                {
                    MessageBox.Show(Err.Message);
                }
                finally
                {
                    try
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oField);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pName);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSF);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSName);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pMemoryWS);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass);
                    }
                    catch
                    {
                    }
                    GC.Collect();
                }
                return(oFeatureLayer);
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(null);
            }
        }
        private short GetContrast(ILayer layer)
        {
            ILayerEffects layerEffects = (ILayerEffects)layer;

            return(layerEffects.Contrast);
        }
        private short GetBrightness(ILayer layer)
        {
            ILayerEffects layerEffects = (ILayerEffects)layer;

            return(layerEffects.Brightness);
        }
Beispiel #30
0
        private void uctrGeneral_Load_1(object sender, EventArgs e)
        {
            //xisheng 20111117 屏蔽掉判断是不是影像,不明白之前为什么要这样处理*******************//
            //if (frmLayerProperties.m_featureTrue)
            //{
            txtLayerName.Text = m_pLayer.Name;
            //}
            //else
            //{
            //    txtLayerName.Text = "影像数据";
            //}
            //xisheng 20111117 屏蔽掉判断是不是影像,不明白之前为什么要这样处理end*************//

            //获得图层NodeKey xisheng 20111117****************************************************
            ILayerGeneralProperties pLayerGenPro = m_pLayer as ILayerGeneralProperties;

            txtDescription.Text = pLayerGenPro.LayerDescription;
            if (pLayerGenPro.LayerDescription != "")
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(pLayerGenPro.LayerDescription);
                XmlNode xmlNode = xmldoc.SelectSingleNode(@"//Layer");
                m_nodeKey = (xmlNode as XmlElement).GetAttribute("NodeKey");
                //获得图层NodeKey xisheng 20111117**********************************************end

                m_LayerDescription  = "图层名称:" + (xmlNode as XmlElement).GetAttribute("NodeText") + ";\r\n";
                m_LayerDescription += "要素集名称:" + (xmlNode as XmlElement).GetAttribute("FeatureDatasetName") + ";\r\n";
                switch ((xmlNode as XmlElement).GetAttribute("DataType"))
                {
                case "FC":
                    m_LayerDescription += "要素集类型:FeatureClass;\r\n";
                    break;

                case "FD":
                    m_LayerDescription += "要素集类型:FeatureDataset;\r\n";
                    break;

                case "RC":
                    m_LayerDescription += "要素集类型:RasterClasss;\r\n";
                    break;

                case "RD":
                    m_LayerDescription += "要素集类型:RasterDataset;\r\n";
                    break;
                }
                m_LayerDescription += "要素类名称:" + (xmlNode as XmlElement).GetAttribute("Code") + ";\r\n";
                m_LayerDescription += "要素类类型:" + (xmlNode as XmlElement).GetAttribute("FeatureType") + ";";
            }
            List <string> list = new List <string>();

            chkLayerVisible.Checked = m_layerVisible;
            if (m_pCurrentLayer.MaximumScale == 0 && m_pCurrentLayer.MinimumScale == 0)
            {
                rbtnAllScale.Checked = true;
                cboMaxScale.Enabled  = false;
                cboMinScale.Enabled  = false;

                //等于上次的比例尺 xisheng 20111117
                if (Plugin.Mod.m_Dic.ContainsKey(m_nodeKey))
                {
                    list             = Plugin.Mod.m_Dic[m_nodeKey];
                    cboMaxScale.Text = list[1];
                    cboMinScale.Text = list[0];
                }
                //等于上次的比例尺 xisheng 20111117 end
            }
            else
            {
                rbtnRangeScale.Checked = true;
                cboMaxScale.Enabled    = true;
                cboMinScale.Enabled    = true;

                //shduan add 20110720
                cboMaxScale.Text = m_pCurrentLayer.MaximumScale.ToString();
                cboMinScale.Text = m_pCurrentLayer.MinimumScale.ToString();
            }
            txtDescription.Text = m_LayerDescription;
            ILayerEffects pLyrEffects = m_pCurrentLayer as ILayerEffects;

            this.inPutTrans.Value = pLyrEffects.Transparency;
        }